The purpose of the week is to fabricate the "hello" network example boards and program them
In link with my project i decided to add two board that can detect proximity or vibration .you can find those library github repository :
/* ATtiny45 as an I2C Slave * * ATtiny Pin 1 = (RESET) N/U ATtiny Pin 2 = (D3) N/U * ATtiny Pin 3 = (D4) to LED1 ATtiny Pin 4 = GND * ATtiny Pin 5 = I2C SDA ATtiny Pin 6 = N/U * ATtiny Pin 7 = I2C SCK ATtiny Pin 8 = VCC (2.7-5.5V) * More on TinyWireS usage - see TinyWireS.h */ #include "TinyWireS.h" // wrapper class for I2C slave routines #define I2C_SLAVE_ADDR 0x10 // i2c slave address (16) ( 0x11 and 0x12 for the 2 others ) #define LED1_PIN 4 // ATtiny Pin 3 void setup(){ pinMode(LED1_PIN,OUTPUT); // lep pin Blink(LED1_PIN,1); // show it's alive TinyWireS.begin(I2C_SLAVE_ADDR); // init I2C Slave mode } void loop(){ byte byteRcvd = 0; if (TinyWireS.available()){ // got I2C input! byteRcvd = TinyWireS.receive(); // get the byte from master Blink(LED1_PIN,byteRcvd); // master must wait for this to finish before calling Wire.requestFrom // send it back to master TinyWireS.send(byteRcvd); } } void Blink(byte led, byte times){ // poor man's display for (byte i=0; i< times; i++){ digitalWrite(led,HIGH); delay (200); digitalWrite(led,LOW); delay (100); } }
/* ATtiny45 as an I2C Master * I2C master * SETUP: * ATtiny Pin 1 = (RESET) N/U ATtiny Pin 2 = N/U * ATtiny Pin 3 = (D4) N/U ATtiny Pin 4 = GND * ATtiny Pin 5 = SDA ATtiny Pin 6 = N/U * ATtiny Pin 7 = SCK ATtiny Pin 8 = VCC (2.7-5.5V) * NOTE! - It's very important to use pullups on the SDA & SCL lines! * TinyWireM USAGE see TinyWireM.h */ #include// I2C Master lib for ATTinys which use USI #include #define NODE1_ADDR 0x10 // 7 bit I2C address node1 #define NODE2_ADDR 0x11 // 7 bit I2C address node2 #define NODE3_ADDR 0x12 // 7 bit I2C address node3 #define RX 3 #define TX 4 int datareceived = 0; SoftwareSerial Myserial(RX,TX); void setup(){ Myserial.begin(9600); TinyWireM.begin(); // initialize I2C lib delay (1000); } void loop(){ delay(5000); Myserial.print("demande de blink node1"); BlinkNode(NODE1_ADDR,0x1); datareceived = TinyWireM.receive(); Myserial.println(datareceived); delay (1000); BlinkNode(NODE2_ADDR,0x2); delay (1000); BlinkNode(NODE3_ADDR,0x3); delay (1000); } void BlinkNode(byte NodeNum,byte times) { TinyWireM.beginTransmission(NodeNum); TinyWireM.send(times); // Ask node to blink n time TinyWireM.endTransmission(); // Send to the slave }
// Wire Master Writer // Refer to the "Wire Slave Receiver" #include#define NODE1_ADDR 0x10 // 7 bit I2C address node1 #define NODE2_ADDR 0x11 // 7 bit I2C address node2 #define NODE3_ADDR 0x12 // 7 bit I2C address node3 int datareceived = 0; void setup() { Serial.begin(9600); Wire.begin(); // join i2c bus (address optional for master) } void loop() { Serial.print("demande de 3 blinks a node1: "); BlinkNode(NODE1_ADDR,3); delay(3000); Serial.print("demande de 5 blinks a node2: "); BlinkNode(NODE2_ADDR,5); delay(3000); Serial.print("demande de 7 blinks a node3: "); BlinkNode(NODE3_ADDR,7); delay(3000); } void BlinkNode(byte NodeNum,byte times) { Wire.beginTransmission(NodeNum); // transmit to device nodenum Wire.write(times); delay(1000); //Wire.requestFrom(NodeNum,2); //while (Wire.available()) // slave may send less than requested // { //datareceived = Wire.read(); //Serial.print("reponse:"); //Serial.println(datareceived); // } Wire.endTransmission(); }
you can find the design files on my github repository :