In this example we connect a TCS34725 Color Sensor to an Adafruit Feather M0 running Circuitpython
First lets look at some information about the sensor from the manufacturer
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
Product parameters
Supply Voltage [V] 2.7 – 3.6
Interface VDD
Color Sensor Channels RGBC
IR Blocking Filter Yes
Programmable
Temperature Range [°C] -40 to 85
This is the sensor I bought
Parts Required
Name | Link |
Adafruit Feather M0 Express | Adafruit (PID 3403) Feather M0 Express – Designed for CircuitPython – ATSAMD21 Cortex M0 |
TCS34725 | TCS34725 Color Sensor RGB color sensor development board module |
Connecting cables | Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire |
Schematic/Connection
Code Example
I used Mu for development
The following is based on a library , I copied the TCS34725 library to the lib folder on my Feather M0 Express – https://circuitpython.org/libraries
The following properties are supported
color_rgb_bytes – A 3-tuple of the red, green, blue color values. These are returned as bytes from 0 to 255 (0 is low intensity, 255 is maximum intensity).
color_temperature – The color temperature in Kelvin detected by the sensor.
lux – The light intensity in lux detected by the sensor.
[codesyntax lang=”python”]
# Simple demo of the TCS34725 color sensor. # Will detect the color from the sensor and print it out every second. import time import board import busio import adafruit_tcs34725 # Initialize I2C bus and sensor. i2c = busio.I2C(board.SCL, board.SDA) sensor = adafruit_tcs34725.TCS34725(i2c) # Main loop reading color and printing it every second. while True: # Read the color temperature and lux of the sensor too. temp = sensor.color_temperature lux = sensor.lux print('Color: ({0}, {1}, {2})'.format(*sensor.color_rgb_bytes)) print("Temperature: {0}K Lux: {1}".format(temp, lux)) # Delay for a second and repeat. time.sleep(1.0)
[/codesyntax]
Output
Here is what I saw in Mu REPL window, I was trying to point the sensor at different colored objects
Temperature: 1391.0K Lux: 0.0
Color: (92, 92, 92)
Temperature: 5201.0K Lux: 44.6917
Color: (255, 255, 255)
Temperature: 1391.0K Lux: 0.0
Color: (71, 25, 25)
Links
1 comment
[…] Connecting a TCS34725 Color Sensor to an Adafruit Feather M0 running CircuitPython – Learn MicroPython. […]