Go Down

Topic: Sending 16bit to Raspberry (Read 66 times) previous topic - next topic


May 16, 2016, 08:37 pm Last Edit: May 16, 2016, 08:44 pm by tsaG

Im trying to send a uint16_t Value to a raspberry Pi over I2C using Python.

Im sending it like this:

Code: [Select]
void I2cBigWrite(uint16_t bigVal) {
  digitalWrite(P1LED, HIGH); // set the LED on
  bigVal = 1000;
  Wire.write (lowByte (bigVal));
  Wire.write (highByte (bigVal));
  digitalWrite(P1LED, LOW); // set the LED on

and receiving it like this:

Code: [Select]
def readTacho1(self):     
            freq = i2cbus.read_word_data(dev_address, 0xE)
            print freq

Pretty simple.

But what I receive is 33768. The arduino is sending the lowByte first, then the highByte.

If I split the reading into two bytes:

Code: [Select]
def readTacho1(self):
            freq1 = i2cbus.read_byte_data(dev_address, 0xE)
            freq2 = i2cbus.read_byte(dev_address)
            print "First Byte: " + str(freq1)
            print "Second Byte: " + str(freq2)

I get:
First Byte: 232
Second Byte: 232

It looks like it is only receiving the (first) lowByte.

Do I miss something? :o


Do I miss something?
The fact that if you want to send multiple bytes, you should put them in an array, and send the whole array in one call?


It sounds to me like the first one was a simple endianess problem.  In that case just send the bytes in the reverse order.  Send the high byte first and then the low. 
Ad hoc, ad loc, and quid pro quo.  So little time - so much to know!  ~Jeremy Hillary Boob Ph.D

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