Simple test
Ensure your device works with this simple test.
examples/tcs34725_simpletest.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4# Simple demo of the TCS34725 color sensor.
5# Will detect the color from the sensor and print it out every second.
6import time
7
8import board
9
10import adafruit_tcs34725
11
12# Create sensor object, communicating over the board's default I2C bus
13i2c = board.I2C() # uses board.SCL and board.SDA
14# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
15sensor = adafruit_tcs34725.TCS34725(i2c)
16
17# Change sensor integration time to values between 2.4 and 614.4 milliseconds
18# sensor.integration_time = 150
19
20# Change sensor gain to 1, 4, 16, or 60
21# sensor.gain = 4
22
23# Main loop reading color and printing it every second.
24while True:
25 # Raw data from the sensor in a 4-tuple of red, green, blue, clear light component values
26 # print(sensor.color_raw)
27
28 color = sensor.color
29 color_rgb = sensor.color_rgb_bytes
30 print(f"RGB color as 8 bits per channel int: #{color:02X} or as 3-tuple: {color_rgb}")
31
32 # Read the color temperature and lux of the sensor too.
33 temp = sensor.color_temperature
34 lux = sensor.lux
35 print(f"Temperature: {temp}K Lux: {lux}\n")
36 # Delay for a second and repeat.
37 time.sleep(1.0)
DisplayIO Simpletest
This is a simple test for boards with built-in display.
examples/tcs34725_simpletest.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4# Simple demo of the TCS34725 color sensor.
5# Will detect the color from the sensor and print it out every second.
6import time
7
8import board
9
10import adafruit_tcs34725
11
12# Create sensor object, communicating over the board's default I2C bus
13i2c = board.I2C() # uses board.SCL and board.SDA
14# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
15sensor = adafruit_tcs34725.TCS34725(i2c)
16
17# Change sensor integration time to values between 2.4 and 614.4 milliseconds
18# sensor.integration_time = 150
19
20# Change sensor gain to 1, 4, 16, or 60
21# sensor.gain = 4
22
23# Main loop reading color and printing it every second.
24while True:
25 # Raw data from the sensor in a 4-tuple of red, green, blue, clear light component values
26 # print(sensor.color_raw)
27
28 color = sensor.color
29 color_rgb = sensor.color_rgb_bytes
30 print(f"RGB color as 8 bits per channel int: #{color:02X} or as 3-tuple: {color_rgb}")
31
32 # Read the color temperature and lux of the sensor too.
33 temp = sensor.color_temperature
34 lux = sensor.lux
35 print(f"Temperature: {temp}K Lux: {lux}\n")
36 # Delay for a second and repeat.
37 time.sleep(1.0)