Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gon0 opened this issue May 30, 2019 · 0 comments
Open

Comments

@gon0
Copy link

gon0 commented May 30, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant