Go Down

Topic: i2c and integer (Read 813 times) 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

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131