// Wire Master Reader // by Nicholas Zambetti // Demonstrates use of the Wire library // Reads data from an I2C/TWI slave device // Refer to the "Wire Slave Sender" example for use with this // Created 29 March 2006 // This example code is in the public domain. #include byte sensorValue = 0; void setup() { Wire.begin(); // join i2c bus (address optional for master) Serial.begin(115200); // start serial for output } void loop() { /*Wire.requestFrom(10, 6); // request 6 bytes from slave device #10 Serial.print("Node@10 answers: "); while (Wire.available()) { // slave may send less than requested char c = Wire.read(); // receive a byte as character Serial.print(c); // print the character } delay(500); Serial.print("\t"); Serial.print("\t"); */ Wire.requestFrom(9, 1); // request 1 byte from secondary device #9 (My ATtiny44 board) Serial.print("Node@09 answers: "); while (Wire.available()) { // slave may send less than requested sensorValue = Wire.read(); // receive a byte as character Serial.print(sensorValue); // print the character } delay(50); Wire.beginTransmission(10); // transmit to device #10 (Aaron's LED board) Wire.write(sensorValue); // sends one byte Wire.endTransmission(); // stop transmitting Serial.println(); delay(50); }