adafruit / Adafruit_CircuitPython_LTR390

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

Not initing on ESP32-S2 #6

Closed caternuson closed 2 years ago

caternuson commented 3 years ago

Some discussion and possible solution here: https://forums.adafruit.com/viewtopic.php?f=60&t=178596

Can demonstrate issue by simply trying to setup an LTR:

Adafruit CircuitPython 6.2.0 on 2021-04-05; FeatherS2 with ESP32S2
>>> import board
>>> import adafruit_ltr390
>>> i2c = board.I2C()
>>> ltr = adafruit_ltr390.LTR390(i2c)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "adafruit_ltr390.py", line 254, in __init__
  File "adafruit_ltr390.py", line 260, in initialize
  File "adafruit_ltr390.py", line 283, in _reset
  File "adafruit_register/i2c_bit.py", line 43, in __get__
  File "adafruit_register/i2c_bit.py", line 43, in __get__
OSError: [Errno 5] Input/output error
>>>  

Sanity check with QT Py M0:

Adafruit CircuitPython 6.2.0 on 2021-04-05; Adafruit QT Py M0 Haxpress with samd21e18
>>> import board
>>> import adafruit_ltr390
>>> i2c = board.I2C()
>>> ltr = adafruit_ltr390.LTR390(i2c)
>>> 
jposada202020 commented 3 years ago

@caternuson I verify the code vs the post in the forum, maybe when they post the solution they meant

self._reset_bit = False

If not the code looks exactly the same, so not sure what they did.

Thanks

jposada202020 commented 3 years ago

I did some tests, this are my findings.

Findings

  1. The library works fine with an RP2040 using CircuitPython 6.2.
  2. In the RP2040 you could even remove the Try... Except statement and reset the sensor
  3. The library does no work with the FeatherS2 as it is. The reset bit either is not sent to the sensor, or the ACK is not received, as mentioned in the comment in the code
  4. The sensor works without resetting in both the RP2040 and the FeatherS2

My biggest concern removing the try... except.. is why we are not catching the exception, the REPL shows asOSerror `but the exceptions just do not work, and library fails here https://github.com/adafruit/Adafruit_CircuitPython_LTR390/blob/99cc48248d8a1de6d09dc593039e578eb3c97a57/adafruit_ltr390.py#L309

caternuson commented 2 years ago

Fixed by #13

Adafruit CircuitPython 7.1.0-beta.1 on 2021-11-30; Adafruit Feather ESP32S2 with ESP32S2
>>> import board
>>> import adafruit_ltr390
>>> ltr = adafruit_ltr390.LTR390(board.I2C())
>>> ltr.light
509
>>> ltr.light
2
>>> 
ladyada commented 2 years ago

bless