D
Dave Saville
I am using perl on a Rasberry pi to read an i2c device using the hipi
library.
@temp = $dev->bus_read( MPU6050_TEMP_OUT_H, 2 );
Returns two bytes as an array of two values. High byte, low byte.
For example I may get:
$temp[0] = 244; # 0xFD
$temp[1] = 224; # 0xE0
Which is -2848. I (eventually) came up with this
$temp = unpack 's', pack 'CC', reverse @temp;
Is there a better method? Also why does
$temp = unpack 'n', pack 'CC', @temp;
Not give the same value?
TIA
library.
@temp = $dev->bus_read( MPU6050_TEMP_OUT_H, 2 );
Returns two bytes as an array of two values. High byte, low byte.
For example I may get:
$temp[0] = 244; # 0xFD
$temp[1] = 224; # 0xE0
Which is -2848. I (eventually) came up with this
$temp = unpack 's', pack 'CC', reverse @temp;
Is there a better method? Also why does
$temp = unpack 'n', pack 'CC', @temp;
Not give the same value?
TIA