pinpong example tcs34725

Reading Values from I2C TCS34725 Color Sensor

Here is the Python code to read values from an I2C TCS34725 color sensor:

# -*- coding: UTF-8 -*-
# Experiment effect: Read the values of the I2C TCS34725 color sensor
# Wiring: Connect an Arduino main control board to a Windows or Linux computer, and connect the TCS34725 color sensor to the I2C port SCL and SDA

import time
from pinpong.board import Board
from pinpong.libs.dfrobot_tcs34725 import TCS34725 # Import the tcs34725 library from libs

Board("uno").begin()               # Initialization, choose the board type (uno, leonardo, xugu) and port number. If the port number is not entered, automatic recognition will be performed
#Board("uno","COM36").begin()      # Initialization with specified port on Windows
#Board("uno","/dev/ttyACM0").begin() # Initialization with specified port on Linux
#Board("uno","/dev/cu.usbmodem14101").begin()   # Initialization with specified port on Mac

tcs = TCS34725() # Sensor initialization

print("Color View Test!");
while True:
  if tcs.begin(): # Look for the sensor, return True if found
    print("Found sensor")
    break # If found, break the loop
    print("No TCS34725 found ... check your connections")

while True:
  r,g,b,c = tcs.get_rgbc() # Get the RGBC data

  # Data conversion
  r /= c
  g /= c
  b /= c
  r *= 256
  g *= 256
  b *= 256;