I'm using a Synapse wireless module which has a ATMEL ATmega128 on it. I've connected a ADXL345 3 axis accelerometer to it and I'm communicating with it via I2C. The Synapse module uses a subset of python as the scripting language.
When I read the XYZ data I get back an array of 6 bytes. EC FF EF FF 14 01
The output data is twos complement with DATAx0 as the least significant byte and DATAx1 as the most significant byte. So in the example above, EC FF is the output for the x axis.
I'm struggling with how to convert this into G force. The datasheet says in full resolution mode (which I'm in) the output resolution increases with the g range set by the range bits to maintain a 4 mg/LSB scale factor.
I've tried the following:
x0 = ord(data[0])
x1 = ord(data[1])
raw = x0+(256*x1)
but the value of raw doesn't make any sense. How do I convert these two bytes into a signed integer?
Additional Information When I make the call to read the adxl345:
data = readAdxls(6)
it returns the string of bytes read back from the external I2C device.
Xlsb = data[0] # EC - 236
Xmsb = data[1] # FF - 255
Ylsb = data[2] # EF - 239
Ymsb = data[3] # FF - 255
Zlsb = data[4] # 14 - 20
Zmsb = data[5] # 01 - 1
So Xlsb is the least significant byte and Xmsb is the most significant byte. These are integers
I guess I just don't understand the twos complement and how to combine these 2 integers/bytes into a signed integer.
structmodule? - MaxNoe