Skip to content

lis3dh_ad example broken #54

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
jerryneedell opened this issue Aug 28, 2019 · 4 comments · Fixed by #55
Closed

lis3dh_ad example broken #54

jerryneedell opened this issue Aug 28, 2019 · 4 comments · Fixed by #55
Assignees

Comments

@jerryneedell
Copy link
Contributor

There are a few problem with the lis3dh_adc example.
I get the same results on a CPX and CPB

The I2C initialization needs to be updated:
I changed it to use the same init as in the other examples:



# Hardware I2C setup. Use the CircuitPlayground built-in accelerometer if available;
# otherwise check I2C pins.
if hasattr(board, 'ACCELEROMETER_SCL'):
    i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA)
    int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
    lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19, int1=int1)
else:
    i2c = busio.I2C(board.SCL, board.SDA)
    int1 = digitalio.DigitalInOut(board.D6)  # Set to correct pin for interrupt!
    lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)


and it seems happy, but then I get


Press any key to enter the REPL. Use CTRL-D to reload.
Adafruit CircuitPython 5.0.0-alpha.0-287-g7cbae3d20 on 2019-08-28; Adafruit CircuitPlayground Express with samd21g18
>>> 
>>> import lis3dh_adc
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "lis3dh_adc.py", line 39, in <module>
  File "adafruit_lis3dh.py", line 206, in read_adc_raw
RuntimeError: buffer size must match format
>>> 

the error appears to be here
https://github.com/adafruit/Adafruit_CircuitPython_LIS3DH/blob/master/adafruit_lis3dh.py#L206

@ladyada
Copy link
Member

ladyada commented Aug 28, 2019

yeah we are much pickier now about the unpack format matching the size of the buffer. wanna try fixing? you just need to slice the array to the right size

@jerryneedell
Copy link
Contributor Author

sure -- I'll give it a try

@jerryneedell jerryneedell self-assigned this Aug 28, 2019
@jerryneedell
Copy link
Contributor Author

OK -- I have it working now -- just cleaning up the example - will have PR later tonight or more likely tomorrow. All the boards with on-board LIS3DHs have the ADC inputs tied to Vdd the example is not very interesting ;-) -- I'll add some notes to the example that it is really only useful on the breakout.

@ladyada
Copy link
Member

ladyada commented Aug 28, 2019

yeah - best not to have them floating if unused, the ADCs are kinda not great :)

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

Successfully merging a pull request may close this issue.

2 participants