In this article we connect a TCS3472 Color Sensor to a Raspberry Pi Pico running Circuitpython
Sensor Information
The TCS3472 device provides a digital return of red, green, blue (RGB), and clear light sensing values. An IR blocking filter, integrated on-chip and localized to the color sensing photodiodes, minimizes the IR spectral component of the incoming light and allows color measurements to be made accurately.
The high sensitivity, wide dynamic range, and IR blocking filter make the TCS3472 an ideal color sensor solution for use under varying lighting conditions and through attenuating materials. This data is transferred via an I2C to the host.
Features
Integrated IR blocking filter
3.8M:1 dynamic range
Four independent analog-to-digital converters
A reference channel for color analysis (clear channel photodiode)
Benefits
Minimizes IR and UV spectral component effects to produce accurate color measurement
Enables accurate color and ambient light sensing under varying lighting conditions
Minimizes motion/transient errors
Clear channel provides a reference which allows for isolation of color content
Not Recommended for New Designs! ams AG is discontinuing production of this device.
There are still many of these that are available that can bought online and are still useful for hobbyists
Parts Required
Name | Link |
Pico | Raspberry Pi Pico Development Board |
tcs34725 | TCS34725 Color Sensor RGB Color Sensor |
Connecting cables | Aliexpress product link |
Schematic/Connection
I used the Adafruit tcs34725 sensor
Black for GND
Red for V+
Blue for SDA
Yellow for SCL
So color coded for ease of use, this layout shows a connection to the module
Code Example
I used Thonny for development
The following is based on a library , I copied the adafruit_tcs34725.mpy library for this device to the lib folder on my Feather M0 Express – https://circuitpython.org/libraries
This is the basic example which comes with the library
[codesyntax lang=”python”]
import time import board import adafruit_tcs34725 import busio # Create sensor object, communicating over the board's default I2C bus i2c = busio.I2C(scl=board.GP1, sda=board.GP0) # uses board.SCL and board.SDA sensor = adafruit_tcs34725.TCS34725(i2c) # Change sensor integration time to values between 2.4 and 614.4 milliseconds # sensor.integration_time = 150 # Change sensor gain to 1, 4, 16, or 60 # sensor.gain = 4 # Main loop reading color and printing it every second. while True: # Raw data from the sensor in a 4-tuple of red, green, blue, clear light component values # print(sensor.color_raw) color = sensor.color color_rgb = sensor.color_rgb_bytes print( "RGB color as 8 bits per channel int: #{0:02X} or as 3-tuple: {1}".format( color, color_rgb ) ) # Read the color temperature and lux of the sensor too. temp = sensor.color_temperature lux = sensor.lux print("Temperature: {0}K Lux: {1}\n".format(temp, lux)) # Delay for a second and repeat. time.sleep(1.0)
[/codesyntax]
Output
Here is what I saw in Thonny REPL window
RGB color as 8 bits per channel int: #00 or as 3-tuple: (0, 0, 0)
Temperature: 1391.0K Lux: 0.0
RGB color as 8 bits per channel int: #3F0B05 or as 3-tuple: (53, 13, 2)
Temperature: 2430.09K Lux: 360.633
RGB color as 8 bits per channel int: #520900 or as 3-tuple: (82, 9, 0)
Temperature: 1935.29K Lux: 453.117
RGB color as 8 bits per channel int: #00 or as 3-tuple: (0, 0, 0)
Temperature: 1391.0K Lux: 0.0
RGB color as 8 bits per channel int: #00 or as 3-tuple: (0, 0, 0)
Temperature: 1391.0K Lux: 0.0
Links