RGB Values over 255 when using the TCS34725 RGB sensor

I'm getting RGB values above 255 and I'm not sure how to interpret these values. Is there something wrong in my code?

#include <Wire.h>
#include "Adafruit_TCS34725.h"
 
/* Example code for the Adafruit TCS34725 breakout library */
 
/* Connect SCL to analog 5
Connect SDA to analog 4
Connect VDD to 3.3V DC
Connect GROUND to common ground */
 
/* Initialise with default values (int time = 2.4ms, gain = 1x) */
// Adafruit_TCS34725 tcs = Adafruit_TCS34725();
 
/* Initialise with specific int time and gain values */
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_614MS, TCS34725_GAIN_1X);
 
void setup(void) {
Serial.begin(9600);
 
if (tcs.begin()) {
Serial.println("Found sensor");
} else {
Serial.println("No TCS34725 found ... check your connections");
while (1);
}
 
// Now we're ready to get readings!
}
 
void loop(void) {
uint16_t r, g, b, c, colorTemp, lux;
 
tcs.getRawData(&r, &g, &b, &c);
colorTemp = tcs.calculateColorTemperature(r, g, b);
lux = tcs.calculateLux(r, g, b);
 
Serial.print("Color Temp: "); Serial.print(colorTemp, DEC); Serial.print(" K - ");
Serial.print("Lux: "); Serial.print(lux, DEC); Serial.print(" - ");
Serial.print("R: "); Serial.print(r, DEC); Serial.print(" ");
Serial.print("G: "); Serial.print(g, DEC); Serial.print(" ");
Serial.print("B: "); Serial.print(b, DEC); Serial.print(" ");
Serial.print("C: "); Serial.print(c, DEC); Serial.print(" ");
Serial.println(" ");
}

Example output: 12:24:42.459 -> Color Temp: 8643 K - Lux: 795 - R: 961 G: 1240 B: 1161 C: 2866
How do i fix this? Thanks in advance!

Read the documentation, and find the RGB maximum values (the range of values). Then scale the values to 0-255 by multiplying by 256 and dividing by the maximum values.

It's simple scaling.

You didn't say why you wanted to scale it, you will lose precision that way.

Those numbers are fine -

This “ uint16_t” tells you they are 16bit numbers , scaled 0 to 65535 , not 0-255.

“ Colour temperature is measured in Kelvins (K), and typically ranges from 2000K-6500K. The lower the number, the warmer the light. A typical warm white light bulb for use in living rooms and bedrooms would have a colour temperature between 2700K-3200K. Cool white bulbs are anywhere upwards of 4000K. At the far end of the scale, ‘daylight’ bulbs have a colour temperature of 6500K and are supposed to replicate the tone of light that the sun emits during the day. These would look very blue in a typical living room.”

Agreed. The sensor is operating correctly. The data sheet explains the sensor operation very clearly.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.