Skip to content

MSA301 library appears to be incompatible with M0 Basic #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
marc-wells opened this issue Dec 31, 2020 · 3 comments
Closed

MSA301 library appears to be incompatible with M0 Basic #12

marc-wells opened this issue Dec 31, 2020 · 3 comments

Comments

@marc-wells
Copy link

I recently got a Feather M0 Basic controller and the MSA301 accelerometer for a new project. When I tried to load the basic test program, I get an unexpected error message. The M0 Basic info is: Adafruit CircuitPython 6.0.0 on 2020-11-16; Adafruit Feather M0 Basic with samd21g18

The Circuit Python program (as copied from the documentation) is:
import time
import board
import busio
import adafruit_msa301
i2c = busio.I2C(board.SCL, board.SDA)
msa = adafruit_msa301.MSA301(i2c)
while True:
print("%f %f %f" % msa.acceleration)
time.sleep(0.5)

When loaded to the M0 Basic, the error message is:
Traceback (most recent call last):
File "code.py", line 4, in
File "adafruit_msa301.py", line 207, in
File "adafruit_msa301.py", line 233, in MSA301
File "adafruit_register/i2c_bits.py", line 61, in init
OverflowError: small int overflow

I checked on the Discord Adafruit Circuit Python channel and both jerryn and Jeff E. were extremely helpful in chasing down this issue. From their comments, specifically from Jeff E., the issue could be:

"Line 233: _xyz_raw = ROBits(48, _MSA301_REG_OUT_X_L, 0, 6)
"This specifies that the "xyz raw" register has 48 bits, which it will try to treat as a single integer value. This doesn't work in M0 builds, because they don't support "long integers", they only support integers 30 bits long (31 bits? anyway, fewer than 48 and even fewer than the customary 32).
"... I think there's a reasonable possibility it can be modified to get rid of this particular use of a 48 bit quantity. Instead of using RWBits for this particular data, you would use a 6-byte readinto() followed by a struct.unpack. It's all a conjecture from me though"

Thanks for your kind consideration,
Marc Wells

@ladyada
Copy link
Member

ladyada commented Dec 31, 2020

oh yknow this should be a UnaryStruct instead... since its 3 x 16-bit values. is this adaptation something you could try doing and submitting a fix?

@marc-wells
Copy link
Author

marc-wells commented Dec 31, 2020 via email

@ladyada
Copy link
Member

ladyada commented Jan 2, 2021

hihi i submitted a fix :) when this issue is closed, look for the latest release for the mpy file
happy new year!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants