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
Bridgeduino:
1 | #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
1 | #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.