adafruit / Adafruit_CircuitPython_LIS331

A library for the ST LIS331 family of high-g 3-axis accelerometers
MIT License
2 stars 1 forks source link

Odd readings with H3LIS331 #2

Open caternuson opened 3 years ago

caternuson commented 3 years ago

Re this thread: https://forums.adafruit.com/viewtopic.php?f=60&t=176800

Recreated using Pi Zero W:

pi@raspberrypi:~ $ python3
Python 3.7.3 (default, Jul 25 2020, 13:03:44) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import board
>>> import adafruit_lis331
>>> lis = adafruit_lis331.H3LIS331(board.I2C())
>>> lis.acceleration
(-19.15361328125, -47.884033203125, 3.83072265625)
>>> lis.acceleration
(-28.730419921874997, -11.49216796875, 34.47650390625)
>>> lis.acceleration
(-32.561142578125, -7.6614453125, 26.81505859375)
>>> lis.acceleration
(-24.899697265625, -26.81505859375, 30.64578125)
>>> 
caternuson commented 3 years ago

Not sure if related, but the power on defaults for the control registers does not match datasheet:

image

Quick manual reading of control registers after initial power up (the | 0x80 is how you specify multi-byte read):

Adafruit CircuitPython 6.1.0 on 2021-01-21; Adafruit ItsyBitsy M4 Express with samd51g19
>>> import board
>>> i2c = board.I2C()
>>> i2c.try_lock()
True
>>> buffer = bytearray(5)
>>> i2c.writeto_then_readfrom(0x18, bytes([0x20 | 0x80]), buffer)
>>> print("0b{:08b}".format(buffer[0]))
0b00111111
>>> print("0b{:08b}".format(buffer[1]))
0b00000000
>>> print("0b{:08b}".format(buffer[2]))
0b00000000
>>> print("0b{:08b}".format(buffer[3]))
0b00110000
>>> print("0b{:08b}".format(buffer[4]))
0b00000000
>>> 

The CTRL_REG1 and CTRL_REG4 don't agree.

Just to make sure it's not a quirk of multi-byte reads, can get same thing reading individually, ex:

>>> i2c.writeto_then_readfrom(0x18, bytes([0x23]), buffer, in_end=1)
>>> print("0b{:08b}".format(buffer[0]))
0b00110000
>>> 

Not seeing any errata or updated datasheet on ST's site: https://www.st.com/en/mems-and-sensors/h3lis331dl.html#documentation

jozuz commented 2 years ago

Hello caternuson,

I am having the same issues on Rpi and arduino, did you find out what caused the problem?

Best regards jozuz

caternuson commented 2 years ago

Adding forum link for ref: https://forums.adafruit.com/viewtopic.php?f=60&t=192698