calculateLux returns 65535 for specific low-light values of R, G and B
gon0 opened this issue · 0 comments
gon0 commented
I am running multiple TCS34725 sensors for some months now for environmental monitoring. I realized that the function "calculateLux" returns 65535 in some low-light-conditions:
The issue can be reproduced by calling:
Adafruit_TCS34725 tcs_Test = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);
uint16_t Lux_result1 = 0;
uint16_t rot = 1;
uint16_t gruen = 1;
uint16_t blau = 2;
Lux_result1 = tcs_Test.calculateLux(rot, gruen, blau);
Serial.print("Lux_result1: ");
Serial.println(Lux_result1);
uint16_t Lux_result2 = 0;
rot = 1;
gruen = 0;
blau = 2;
Lux_result2 = tcs_Test.calculateLux(rot, gruen, blau);
Serial.print("Lux_result2: ");
Serial.println(Lux_result2);
The console returns:
Lux_result1: 0
Lux_result2: 65535
Library-Included version of "calculateLux" function:
uint16_t Adafruit_TCS34725::calculateLux(uint16_t r, uint16_t g, uint16_t b) {
float illuminance;
/* This only uses RGB ... how can we integrate clear or calculate lux */
/* based exclusively on clear since this might be more reliable? */
illuminance = (-0.32466F * r) + (1.57837F * g) + (-0.73191F * b);
return (uint16_t)illuminance;
}
Proposed modification of "calculateLux" function:
uint16_t Adafruit_TCS34725::calculateLux(uint16_t r, uint16_t g, uint16_t b) {
float illuminance;
/* This only uses RGB ... how can we integrate clear or calculate lux */
/* based exclusively on clear since this might be more reliable? */
illuminance = (-0.32466F * r) + (1.57837F * g) + (-0.73191F * b);
if (illuminance < 0) { // This line is added
illuminance = 0; // This line is added
} // This line is added
return (uint16_t)illuminance;
}
Maybe there are better ways to make this function more robust. For me, the mentioned modification seems to work.