FREE SHIPPING ON ALL ORDERS OVER £20

60 DAY HASSLE-FREE RETURNS

Gamit ang TCS34725 kasama ang Raspberry Pi

Using the TCS34725 with the Raspberry Pi

Ang TCS34725 ay isang color sensor module na kayang tumukoy ng red, green, blue (RGB), at clear light values. Malawak itong ginagamit sa mga application gaya ng ambient light sensing, color detection, at maging sa mga color-based sorting system. Ipinapaliwanag ng gabay na ito kung paano ikonekta at gamitin ang TCS34725 sa Raspberry Pi.


Mga Kakailanganin

  1. Raspberry Pi (anumang model na may GPIO support, hal. Pi 3, Pi 4)
  2. TCS34725 Color Sensor Module
  3. Breadboard at Jumper Wires
  4. Python na naka-install sa iyong Raspberry Pi

Hakbang 1: Pag-wire ng TCS34725 sa Raspberry Pi

Ang TCS34725 ay gumagamit ng I2C protocol para sa komunikasyon.

Mga Koneksyon

TCS34725 Pin Raspberry Pi Pin
VIN 3.3V (Pin 1)
GND Ground (Pin 6)
SDA SDA (Pin 3, GPIO2)
SCL SCL (Pin 5, GPIO3)

Hakbang 2: I-enable ang I2C Interface

  1. Buksan ang Raspberry Pi configuration tool:
    sudo raspi-config
    
  2. Mag-navigate sa Interface Options > I2C at i-enable ito.
  3. I-reboot ang Raspberry Pi:
    sudo reboot
    

Hakbang 3: I-install ang mga Kinakailangang Library

  1. I-update ang iyong Raspberry Pi:
    sudo apt update && sudo apt upgrade -y
    
  2. I-install ang mga kinakailangang tool at Python library:
    sudo apt install -y i2c-tools python3-pip
    pip3 install adafruit-circuitpython-tcs34725
    
  3. I-verify kung nade-detect ang TCS34725 sa I2C bus:
    sudo i2cdetect -y 1
    
    Dapat lumabas ang sensor sa address na 0x29.

Hakbang 4: Python Code para Magbasa ng Data mula sa TCS34725

Narito ang isang Python script para magbasa ng RGB at clear light values mula sa TCS34725.

Halimbawa ng Python Code

import time
import board
import adafruit_tcs34725

# I-initialize ang I2C at TCS34725 sensor
i2c = board.I2C()
sensor = adafruit_tcs34725.TCS34725(i2c)

# Itakda ang gain at integration time para sa sensor
sensor.gain = adafruit_tcs34725.GAIN_4X
sensor.integration_time = 100  # Sa milliseconds

try:
    while True:
        # Basahin ang color values
        r, g, b, c = sensor.color_raw
        temperature = sensor.color_temperature  # Opsyonal: Tantiyahin ang color temperature
        lux = sensor.lux  # Opsyonal: Kalkulahin ang liwanag sa lux

        print(f"Raw RGB: R={r}, G={g}, B={b}, Clear={c}")
        if temperature is not None:
            print(f"Color Temperature: {temperature:.2f} K")
        print(f"Lux: {lux:.2f} lx")
        print("--------------------------")
        time.sleep(1)
except KeyboardInterrupt:
    print("Exiting...")

Hakbang 5: Mga Application ng TCS34725

  1. Ambient Light Sensing: I-adjust ang liwanag ng screen o ilaw base sa antas ng ambient light.
  2. Color Detection: Gamitin ang sensor para sa color sorting o pagkilala sa robotics.
  3. Photography: Sukatin ang color temperature para sa white balance correction.
  4. IoT Projects: I-integrate ang color at light data sa mga smart home system.

Troubleshooting

  1. Hindi Nade-detect ang Sensor:

    • I-verify ang mga koneksyon ng SDA at SCL.
    • Siguraduhing naka-enable ang I2C interface sa Raspberry Pi.
  2. Hindi Tumpak na Readings:

    • Iwasan ang direktang sikat ng araw o mga reflective surface habang nagsusukat.
    • I-adjust ang gain at integration time sa script para mapabuti ang accuracy.
  3. Mga I2C Error:

    • Suriin kung may mga conflict na device sa I2C bus o maluwag na wiring.

Konklusyon

Ang TCS34725 ay isang versatile na color sensor na madaling i-integrate sa Raspberry Pi. Sa pagsunod sa gabay na ito, magagamit mo ito para sukatin ang RGB, clear light, color temperature, at antas ng liwanag, kaya mainam ito para sa iba't ibang application gaya ng robotics, IoT, at photography. Mag-eksperimento sa mga setting nito para umangkop sa mga partikular na pangangailangan ng iyong proyekto!

Notice an Issue? Have a Suggestion?
If you encounter a problem or have an idea for a new feature, let us know! Report a problem or request a feature here.

1 Komento

Spent the day trying to find something that would get this sensor working on one of my old beater Raspberry Pi 3 B boards. Your post did the trick.
Thank you.
Michael A. Dupont

Junk Drawer Labs, LLC,

Mag -iwan ng komento