- Tue Jan 03, 2017 10:54 pm
#192757
I'm writing a bit of driver code in java using pi4j to poll the LSM9DS1 orientation data for use with my raspberry pi 3. As far as I'm aware, there is no existing open source code base to perform this task on the LSM9DS1 in Java. This is pretty far afield from my area, and a lot of the terminology and acronyms in the device datasheet are greek to me, so I apologize if this is a silly question.
According to the datasheet section 7.31-7.33, the accelerometer registers are arranged in pairs representing two's complement 16-bit values for the X, Y, Z axes. According to section 2.1, the accelerometer unit is measured in g's. When reading the accelerometer registers (on a flat surface), one would expect to get approximately: x=0, y=0, z=1
Instead my outputs are are as follows:
Acc (x): -119
Acc (y): -1433
Acc (z): 15862
If I hold the device sideways, then the registers read out:
Acc (x): 15121
Acc (y): 695
Acc (z): 4174
It seems as though the device is working correctly but I'm misunderstanding something about the byte conversion to two's complement?
Here's a sample of the actual binary outputs from the registers from a different polling:
Acc z High (OUT_Z_H_XL): 00111110
Acc z Low (OUT_Z_L_XL): 00010000
Assembled, they are: 0011111000010000 => 15,888 in decimal
Can anybody offer insight on what the problem might be?
According to the datasheet section 7.31-7.33, the accelerometer registers are arranged in pairs representing two's complement 16-bit values for the X, Y, Z axes. According to section 2.1, the accelerometer unit is measured in g's. When reading the accelerometer registers (on a flat surface), one would expect to get approximately: x=0, y=0, z=1
Instead my outputs are are as follows:
Acc (x): -119
Acc (y): -1433
Acc (z): 15862
If I hold the device sideways, then the registers read out:
Acc (x): 15121
Acc (y): 695
Acc (z): 4174
It seems as though the device is working correctly but I'm misunderstanding something about the byte conversion to two's complement?
Here's a sample of the actual binary outputs from the registers from a different polling:
Acc z High (OUT_Z_H_XL): 00111110
Acc z Low (OUT_Z_L_XL): 00010000
Assembled, they are: 0011111000010000 => 15,888 in decimal
Can anybody offer insight on what the problem might be?