Read Data From Adxl355 Using Python Spi Interface On Raspberry Pi
Solution 1:
In order to debug such a problem you need start by checking the hardware communication level because SPI protocol is sensitive to long wires [>1m] and you need to know if everything if as it should at this level. Use a logic analyzer like saleae.
Also be aware that ADXL sensors are known for having problems.
I've lost a couple of nights, years ago, with this two problems.
Solution 2:
I have worked with these sensors, they can be a real pain!
Have a look over here. Someone already went through the trouble of creating a library in python for using this sensor combined with the SPI bus on the RPi. Basically this is exactly what you need. You can copy your gpio.output(pin, gpio.LOW)
and gpio.output(pin, gpio.HIGH)
statements into the read_data function of that library or just connect it to pin 24 on the pi instead (like the library doc suggests) and see if that works.
Also from the adxl355.py file I can see that you are interpreting your data differently:
# Join data
x_data = (x_data[0] >> 4) + (x_data[1] << 4) + (x_data[2] << 12)
y_data = (y_data[0] >> 4) + (y_data[1] << 4) + (y_data[2] << 12)
z_data = (z_data[0] >> 4) + (z_data[1] << 4) + (z_data[2] << 12)
# Apply two complement
if x_data & 0x80000 == 0x80000:
x_data = ~x_data + 1
if y_data & 0x80000 == 0x80000:
y_data = ~y_data + 1
if z_data & 0x80000 == 0x80000:
z_data = ~z_data + 1
Maybe you're just interpreting your data wrong, try the above and see if that fix it. Otherwise I would suggest switching to use that library. Even if it's temporary it can help you figure out what is wrong with your code.
Post a Comment for "Read Data From Adxl355 Using Python Spi Interface On Raspberry Pi"