adafruit / Adafruit_TCS34725

Arduino library driver for Adafruit's TCS34725 RGB Color Sensor Breakout

Home Page:http://www.adafruit.com/products/1334

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

calculateLux returns 65535 for specific low-light values of R, G and B

gon0 opened this issue · comments

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:
TCS_values_in_Grafana

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.