adafruit/Adafruit_TCS34725

Issues with accuracy and speed

mkudlacek opened this issue · 1 comments

Hello,
I think there is a problem with how the getRawData() works and thus affecting the accuracy of the measurement.

The getRawData() first pulls data from the sensor and then waits for some time based on integration time. So far, it seems ok, but imagine this scenario

  • The sensor is in a dark box. Integration time is set to 154ms to get reasonable resolution and speed. The object of which we want to measure the color is also in the box
  • We enable LED illumination by asserting pin to LOW
  • We call the getRawData() immediatelly

Because of the short time between illuminating the object and taking the measurment, the actual data we will get will be before the illumination, thus R: 0 G: 0 B: 0 C:0. Next getRawData() call will return the correct values.

I propose to switch the delay and reading. First wait for the integration time, then read the values.

Moreover, the waiting is hardcoded, so the getRawData() is a blocking function. For example, I'm reading values from multiple sensors connected to I2C multiplexer. I illuminate the object, then read values from each sensor. The time to do this is NUMBER_OF_SENSORS x INTEGRATION_TIME. It would be more suitable to:

  1. illuminate
  2. wait the integration time
  3. read immediatelly current values from each sensor

I can implement this, but please give me some response first.

sure please try it out and submit a pull request :)