Hi,
I am using this light sensor with Digital_Light_TSL2561 library.
After reading the sensor with this line: TSL2561.readVisibleLux(), The code gets stuck when the sensor is being disconnected(physically).
Is there a way to prevent this from happening with code? I would like to know when it is connected or disconnected.
Thanks.
One solution is that you can check the Wire(I2C) communication established or not before reading the value from the sensor.
like this
#include <Wire.h>
#include <Digital_Light_TSL2561.h>
void setup() {
Wire.begin();
Serial.begin(9600);
TSL2561.init();
}
void loop() {
if (Wire.available()) {
Serial.println("Sensor is Present");
Serial.print("The Light value is: ");
Serial.println(TSL2561.readVisibleLux());
delay(1000);
}
else {
Serial.println("Sensor error! please check sensor");
}
}
Hi,
Thanks for the reply.
It works if it is the only i2c device available, what if I 2 devices and one is still connected? Is there a way to distinguish between addresses?
Yes, Using the address you can check the availability .