Michael On Everything Else

TSL2561 UP/DOWN Status

I’ve found that detecting the up or down status of the TSL2561 sensor using if(!tsl.begin()) is unreliable. The code often doesn’t clearly indicate down status, even when the sensor is completely removed from the circuit.

To effectively detect up or down status, I use a chunk of code from Nick Gammon’s I2C Scanner.

The scanner sketch initiates a brief connection with the TSL2561 and returns the error code from the communication. Depending on that error code, we can determine up or down status:

In the code below, “41” is the address of my sensor (I have connected the “Addr” pin to ground to change it).

Wire.beginTransmission(41);

I2Cerror = Wire.endTransmission();

if ( I2Cerror == 0 ) //Error "0" indicates a successful contact

{ //DO SOME STUFF}