adafruit / Adafruit_TSL2591_Library

This is an Arduino library for the TSL2591 digital luminosity (light) sensors.
58 stars 48 forks source link

Implement sensor reset via TSL2591_SRESET #33

Closed buzz-tee closed 10 months ago

buzz-tee commented 5 years ago

When my sensor gets disconnected from I2C and is reconnected shortly after then the reading is no longer valid. In this case (getStatus() would return 0xFF) calling the reset() function comes in handy.

The reset method writes TSL2591_SRESET to the control register (see https://cdn-shop.adafruit.com/datasheets/TSL25911_Datasheet_EN_v1.pdf, p.13).

I tested the change on an ESP32 using I2C: after disconnecting and reconnecting the readings return to normal as soon as my code calls the new reset() method.

I did not test SPI.

I'm aware that there might be better ways than resetting the sensor, but the function itself is not evil as far as I can tell.

caternuson commented 10 months ago

In general, I2C is not meant to be hot plugable. So sensors should not get disconnected while powered and running. This may have worked, but is not a proper usage of I2C.

However, exposing software reset might be something worth considering. If that becomes important, can open a new issue to discuss.