adafruit / Adafruit_CircuitPython_LTR390

CircuitPython library for the LTR390 ambient light and UV sensor
MIT License
7 stars 2 forks source link

LTR390 Fails to Init with RP2040 #11

Closed jknappatdirigible closed 2 years ago

jknappatdirigible commented 2 years ago

I am trying to integrate the LTR390 with a Feather RP2040 but the device is failing to initialize. I am running Circuitpython 7.0.0 (adafruit-circuitpython-adafruit_feather_rp2040-en_US-7.0.0.uf2) and using the libraries from the latest Circuitpython bundle (adafruit-circuitpython-bundle-7.x-mpy-20211127).

The code I am running is as follows:

import board
import adafruit_ltr390

i2c = board.I2C()

ltr = adafruit_ltr390.LTR390(i2c)
print("UV:", ltr.uvs, "\t\tAmbient Light:", ltr.light)
print("UVI:", ltr.uvi, "\t\tLux:", ltr.lux)

And the error I'm receiving is:

code.py output:
Traceback (most recent call last):
  File "code.py", line 6, in <module>
  File "adafruit_ltr390.py", line 286, in __init__
  File "adafruit_ltr390.py", line 292, in initialize
  File "adafruit_ltr390.py", line 315, in _reset
  File "adafruit_register/i2c_bit.py", line 43, in __get__
OSError: [Errno 116] ETIMEDOUT

Code done running.

I have also attached a photo of my setup. You may notice that there are other sensors and boards connected to the Feather RP2040, but I have tried connecting the LTR390 directly to the RP2040 via STEMMA QT Cable. This didn't produce any positive change, however. Other things I have tried include:

I have managed to get the code to execute successfully with a Feather M0 RFM95 LoRa Radio, so the problem appears to be specific to the RP2040.

Hope you can make more sense of this than I have so far. Please let me know if I can provide any additional info.

IMG_1356

ladyada commented 2 years ago

@caternuson this is due to the LTR390 not acking the reset bit, @hathach just fixed this in arduino - most sensors don't just give up the ghost in the middle of a transaction :/ dupe of https://github.com/adafruit/Adafruit_CircuitPython_LTR390/issues/6

hathach commented 2 years ago

from my testing with arduino after soft reset()

other mcus may/may not recover, though I think the "best-to-all" solution is just re-init I2C within the soft-reset, just to be safe. This can be done easily with arduino by calling end() then begin() https://github.com/adafruit/Adafruit_LTR390/pull/3/files#diff-2e600839f345eb79c6af9a2d512e9b212072006ae371f58f2817b6e60538a7f3R92

caternuson commented 2 years ago

@hathach thanks for the input. i was thinking same here:

though I think the "best-to-all" solution is just re-init I2C within the soft-reset

I'll setup and test that on various MCU's and see how it plays.

caternuson commented 2 years ago

Please try the 1.1.3 release: https://github.com/adafruit/Adafruit_CircuitPython_LTR390/releases/tag/1.1.3

jknappatdirigible commented 2 years ago

This worked for me. Thank you for the quick fix, @caternuson