


Wire.onReceive(receiveEvent) // what to do when receiving data Wire.onRequest(requestEvent) // fucntion to run when asking for data Volatile int Val // variable used by the master to sent data to the slave here I am just sending the number 2Ĭhar t //empty array where to put the numbers going to the master Serial.println(t) //shows the data in the array t T = Wire.read() // every character that arrives it put in order in the empty array "t" Int i=0 //counter for each bite as it arrives Wire.requestFrom(8, 3) // request 3 bytes from slave device #8 Serial.begin(9600) // start serial for output Wire.begin() // join i2c bus (address optional for master)

Volatile int Val // varaible used by the master to sent data to the slave Int table= //empty array where to put the numbers comming from the slave Here is the code for the master #include Ĭonst int SLAVE_ADDRESS = 8 //Slave arduino ID In my code a master receives three types of data from the slave, and it send data of a fourth variable to the slave. How can one transmit different types of numbers?. Right now the communication via I2C using the wire library only allows transmission of numbers between 0 and 255. My limitation is now how to transmit different types of data like for instance, long, float, etc. I have found a few good tutorials on how to send and receive data via I2C in connected arduinos.
