The datasheet is here.
The lines of the example here:
00016
00017 accelerometer.setDataFormatControl(0x0B);
Say that you'll be using +/- 16g resolution, and you'll get 4milli-g's per least significant bit.
From page 3 of the datasheet:
±16 g Range Full resolution 13-bit
Since we're reading a 13-bit unsigned (MSB isn't a sign bit) number, our value will be between 0 and 2^13.
I assume that the 0g value will be half the range = 2^13 / 2 = 2^12 = 4096.
So to zero-offset our value we simply subtract 4096.
g_data = value - 4096
To get it to scale correctly we need to divide it by 4096/16 (we get a max of +16g)
g_data = (value - 4096) / 256
I hope that works - let me know if it doesn't match up with the data you're getting (I haven't actually used an ADXL345 before)
I just got my ADXL345 accelerometer working using the cookbook code.
I notice that the output is in ADC counts (bits). I need to convert this to g's. Just looking for suggestions for the conversion.
I plan to take the ADC count reading at rest. I would set this equal to 1G. Then simply divide the number of the count into 1G to provide the resolution. The math is simple. The syntax might be too.
What do you all think?