gpvidal / adxl355-arduino

Read ADXL355 PMDZ accelerometer on Arduino
MIT License
9 stars 8 forks source link

sign extension bug and multi byte read bug #2

Open petedl opened 3 years ago

petedl commented 3 years ago

I'm new to github, so not sure if i have done this correctly.

there was a bug with the sign extension from 20 bit to 32 bits of the X,Y,Z data.

There was also a bug in the readMultipleData function. The X data was being read correctly, but the following data was wrong. I fixed this by putting a chip select toggle inside the read loop.

I created a fork, make the fixes, committed it and commit to master. Not sure if this made a request to include it in your version

rbp9802 commented 3 years ago

Thank you for your fix @petedl it worked well on my Raspberry Pi Pico. I was wondering if you have any code for python as i'm planning to use this accelerometer on a Raspberry Pi 4.

petedl commented 3 years ago

Sorry, no python.

Unfortunately there seems to be a remaining bug that I did not track down before I moved onto other work. The X,Y,Z look roughly right on first inspection, but if you look closely, something strange happens. The MSB values follow how one would expect (slowly increasing or decreasing when you rotate the chip). However, some of the lower bits go in the wrong direction, thus give a sawtooth graph when you would expect a ramp.

If i had more time, i would wire up the "data ready" pin and only read a new value when the data ready pin is set. This is my guess at what is wrong. The code not inspecting the "data ready" pin is an obvious diversion from the data sheet, but there is no good reason that this would create the bug i saw.

Please let me know if you track down the problem.

rbp9802 commented 3 years ago

Thank you for your reply!

Actually i found python codes.

I rotated the chip and get a "ramp" in every direction (i couldn't make any steadier rotation), it seems that i'm not having that bug otherwise i didn't understand it.

ADXL355_test