I am trying to read acceleration values from a ADXL345 via I2C. I've successfully configured the accelerometer with a resolution of 16G.
Test 1: 180° rotation along the y axis in 16G resolution. The acceleration along the Z axis is shown below:
Using a 16g configuration, the resolution is too low. I changed it to 2g in order to get a more accurate value of gravity and performed the same test.
Test 2: 180° rotation along the y axis in 2G resolution. The acceleration along the Z axis is shown below:
As you can see, the is a roll over effect probably caused by the number of bits used in the register to save the value. With 16g mode the module uses a 13 bit register, with 2/4/8g mode it uses a 10bit register.
Which approach do you suggest to reconstruct the acceleration value?
In this question @davidcary mentioned the roll over effect.
I am reading two bytes, it is the same code I used for the 16g mode
def read_word(self,adr): high = self.bus.read_byte_data(self.address, adr) low = self.bus.read_byte_data(self.address, adr+1) val = (high << 8) + low return val def read_word_2c(self,adr): val = self.read_word(adr) if (val >= 0x8000): return -((65535 - val) + 1) else: return val [...] accel_zout = adx.read_word_2c(0x36)
Here is a screenshot of the registers containing the Zaxis values
Here is another problem, I will open another question for this but it is worth pointing out the following problem. Please focus on the Z axis only
Test: tilt from 0° to 180° and back to 0° twice, then from 0° to -180° and back to 0° twice.
Figure 1: Raw data
As you can see, the shift is not costant. The average shift is around 58.000 but sometimes it is smaller than this. If we apply the same correction to all shify occurence we will end up with this:
Figure 2: Unwrapped data
If the threshold after which the correction should be applied is not correctly defined, the resulting data won't be accurate. In Figure 2 the acceleration along the Z axis after the test is different from the initial zero value which means disaster...