Electronic – Accelerometer readings, what is wrong

accelerometer

I made a board with the Analog Devices ADXL345. I then attached it to my robot and did obstacle avoidance with data logging for about 10s. The robot made 4 turns. Here is a graph of z-axis readings. I set the ADXL345 to +/- 2g. It is 10bit. This data doesn't look right. Is this what I would see from vibration, or is this what I should see?

enter image description here

Best Answer

That's a very bimodal distribution - not something you should see from vibration. My guess is you are either not reading the right data from the chip or you are interpreting it incorrectly. This part uses two byte values for the outputs - it looks like you may have the MSB and LSB swapped.

Edit: I'm actually going to say that you almost certainly have the MSB and LSB swapped. The sensitivity on the 2g scale is 256 LSB/g. This means that you should be seeing a raw reading of + or - 256 or so, assuming the chip is mounted with the axis vertical. The LSB will be mostly 'noise' while the MSB will be mostly zero. If the bytes are swapped, then the sign bit becomes what should have been bit 7 and it will flip more or less randomly. If the original value is 255, byte swapping results in -256. If the original value is 256, byte swapping results in value of 1. If the original value is 127, byte swapping results in 32,512. If you are dividing by the sensitivity, you should see a highly bimodal distribution with lot of points with small negative values and a lot of points with large positive values.