//for the master unit
//Wire lib is for using the I2C bus
#include <Wire.h>
//define slave address
#define SLAVE_ADDR 9
//define Slave answer size
#define ANSWERSIZE 5
//The above expects that the slave gives us 5 bytes
void setup(){
//initialize the I2C communication for the master
Wire.begin();
Serial.begin(9600);
}
void loop(){
delay(500);
Serial.println("Write Data to slave");
//write charecters to the slave
Wire.beginTransmission(SLAVE_ADDR);
Wire.write(0);
Serial.println("recieve data");
//Read response for the slave
//Read 5 charecters back
Wire.requestFrom(SLAVE_ADDR,ANSWERSIZE);
//the string that is read from slave
String response = "";
while (Wire.available()){
char b = Wire.read();
response += b;
}
//print to serial monitor
Serial.print(response);
}