Home Circuitpython Adafruit Feather M0 and TCS34725 Color Sensor circuitpython example

Adafruit Feather M0 and TCS34725 Color Sensor circuitpython example

by shedboy71

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

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

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

feather and TCS34725 layout

feather and TCS34725 layout

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

Datasheet

 

You may also like

1 comment

Leave a Comment