Go Down

Topic: i2c and integer (Read 1 time) previous topic - next topic


at first excuse me for my english,

i have a question i use wire library to trasmit between 2 arduinos and i don't know if i can trasmit an integer value. if i can, how i can do it?

thank you


I would imagine you can send anything, but only a byte at a time.
So you would get the number and use mod & div to split the number up.


Feb 04, 2009, 05:41 pm Last Edit: Feb 04, 2009, 05:44 pm by mem Reason: 1
here is an example:

 Wire.send((byte)(integerValue >>8));     // sends the most significant byte    
 Wire.send((byte)(integerValue & 0xff));    // sends the least significant byte

the receiving side has to reconstruct the integer
 val = Wire.receiver() << 8; // get the msb
 val += Wire.receive(); // get the lsb


Go Up