/* ATtiny85 as an I2C Slave BroHogan 1/12/11 * Example of ATtiny I2C slave receiving and sending data to an Arduino master. * Gets data from master, adds 10 to it and sends it back. * SETUP: * 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 on DS1621 & GPIO ATtiny Pin 6 = (D1) to LED2 * ATtiny Pin 7 = I2C SCK on DS1621 & GPIO ATtiny Pin 8 = VCC (2.7-5.5V) * NOTE! - It's very important to use pullups on the SDA & SCL lines! * Current Rx & Tx buffers set at 32 bytes - see usiTwiSlave.h * Credit and thanks to Don Blake for his usiTwiSlave code. * More on TinyWireS usage - see TinyWireS.h */ #include "TinyWireS.h" // wrapper class for I2C slave routines #define I2C_SLAVE_ADDR 0x26 // i2c slave address (38) #define LED1_PIN 7 // ATtiny Pin 3 #define LED2_PIN 8 // ATtiny Pin 6 void setup(){ pinMode(LED1_PIN,OUTPUT); // for general DEBUG use pinMode(LED2_PIN,OUTPUT); // for verification digitalWrite(7, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(7, LOW); // turn the LED off by making the voltage LOW TinyWireS.begin(I2C_SLAVE_ADDR); // init I2C Slave mode delay(1000); // wait for a second } void loop(){ byte byteRcvd = 0; if (TinyWireS.available()){ // got I2C input! byteRcvd = TinyWireS.receive(); // get the byte from master // byteRcvd += 10; // add 10 to what's received // TinyWireS.send(byteRcvd); // send it back to master digitalWrite(7, HIGH); //alive delay(2000); digitalWrite(7, LOW); delay(2000); if(byteRcvd!=0){ digitalWrite(8, HIGH); //blue led= receive delay(2000); //digitalWrite(8, LOW); //delay(2000); } } }