Week15_Bridge_node_I2C

E3C2AF9B1853FFC930F82E8A24BB76F0

I2c

The Bridge is master and the node is slave,both connect with two wire SDA(data line) and SCL(clock line)

There is a reference files about ATtiny I2C

Install the I2C library

E3C2AF9B1853FFC930F82E8A24BB76F0

Bridgeduino:


traces
interto

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <TinyWireM.h> // I2C Master lib for ATTinys which use USI
#define Node_Addr 0x48
byte x = 0x01;
int c = 0;
boolean state;
#include "SoftwareSerial.h"
const int Rx = 4; // this is physical pin 7
const int Tx = 3; // this is physical pin 6
SoftwareSerial mySerial(Rx, Tx);
void setup() {
// put your setup code here, to run once:
TinyWireM.begin(); // initialize I2C lib
pinMode(Rx, INPUT);
pinMode(Tx, OUTPUT);
mySerial.begin(4800); // send serial data at 9600 bits/sec
}
void loop() {
if(mySerial.available()){
c = mySerial.read();
delay(100);
if(c==97){
TinyWireM.beginTransmission(Node_Addr);
x = 0x01;
TinyWireM.send(x); // if one-shot, start conversions now
TinyWireM.endTransmission(); // Send 1 byte to the slave
delay(1000); // if one-shot, must wait ~750 ms for conversion
}else if(c==98){
TinyWireM.beginTransmission(Node_Addr);
x = 0x00;
TinyWireM.send(x); // if one-shot, start conversions now
TinyWireM.endTransmission(); // Send 1 byte to the slave
delay(1000); // if one-shot, must wait ~750 ms for conversion
}
}
}

NodeDuino

traces
interto

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "TinyWireS.h" // wrapper class for I2C slave routines
#define Node_ADDR 0x48 // 7 bit I2C Address for Node
#define LED 4 // ATtiny Pin 3
byte byteRcvd = 0x00;
void setup() {
// put your setup code here, to run once:
pinMode(LED,OUTPUT);
TinyWireS.begin(Node_ADDR);
}
void loop() {
// put your main code here, to run repeatedly:
if (TinyWireS.available()){ // got I2C input!
byteRcvd = TinyWireS.receive(); // get the byte from master
if(byteRcvd == 0x01){
digitalWrite(LED,HIGH);
}else{
digitalWrite(LED,LOW);
}
}
delay (10);
}

File Download

Bridge eagle
Node eagle
Bridgeduino.zip
NodeDuino.zip


This work is licensed under a Creative Commons Attribution 4.0 International License.