Difference between revisions of "TCS34725 Color Sensor"
m (Text replacement - "https://www.waveshare.com/w/upload/" to "https://files.waveshare.com/upload/") |
|||
(15 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | <div class=" | + | <div class="wiki-pages jet-green-color"> |
− | |||
{{Infobox item|colorscheme=green | {{Infobox item|colorscheme=green | ||
− | |img=[[File:TCS34725-Color-Sensor-intro.jpg|300px| link=https://www.waveshare.com/tcs34725-color-sensor.htm]] | + | |img=[[File:TCS34725-Color-Sensor-intro.jpg|300px|{{Amazon_nolink|default={{#ifeq: {{#urlget:amazon|0}}|{{#urlget:Amazon|0}}| default|}}|url=link=https://www.waveshare.com/tcs34725-color-sensor.htm}}]] |
|caption=TCS34725 Color Sensor, I2C interfaces | |caption=TCS34725 Color Sensor, I2C interfaces | ||
|category=[[:Category:Sensor|Sensor]], [[:Category:Modules|Moduiles]], [[:Category:Light|Light]] | |category=[[:Category:Sensor|Sensor]], [[:Category:Modules|Moduiles]], [[:Category:Light|Light]] | ||
|brand=Waveshare | |brand=Waveshare | ||
− | |{{#urlget:amazon|default}}=display | + | |{{#ifeq: {{#urlget:amazon|0}}|{{#urlget:Amazon|0}}| default|}}=display |
|website_cn=[http://www.waveshare.net/shop/TCS34725 Color Sensor.htm 官方中文站点] | |website_cn=[http://www.waveshare.net/shop/TCS34725 Color Sensor.htm 官方中文站点] | ||
|website_en=[https://www.waveshare.com/tcs34725-color-sensor.htm Waveshare Website] | |website_en=[https://www.waveshare.com/tcs34725-color-sensor.htm Waveshare Website] | ||
Line 12: | Line 11: | ||
}} | }} | ||
{{TCS34725 Color Sensor Spec}} | {{TCS34725 Color Sensor Spec}} | ||
− | |||
− | |||
{{TCS34725 Color Sensor RPi Guide}} | {{TCS34725 Color Sensor RPi Guide}} | ||
− | |||
− | |||
{{TCS34725 Color Sensor STM32 Guide}} | {{TCS34725 Color Sensor STM32 Guide}} | ||
− | |||
− | |||
{{TCS34725 Color Sensor Arduino Guide}} | {{TCS34725 Color Sensor Arduino Guide}} | ||
− | + | =Resources= | |
− | + | *[https://files.waveshare.com/upload/b/bb/TCS34725_Color_Sensor_user_manual_en.pdf TCS45725 color sensor user manual] | |
− | + | *[https://files.waveshare.com/upload/a/a1/TCS34725_Color_Sensor_code.7z Demo code] | |
− | + | *[https://files.waveshare.com/upload/5/5c/TCS34725_Color_Sensor_SchDoc.pdf Schematic] | |
− | *[https:// | ||
− | *[ | ||
− | *[ | ||
== Datasheet == | == Datasheet == | ||
+ | *[https://files.waveshare.com/upload/e/e4/TCS3472_Datasheet.pdf TCS3472] | ||
− | + | =FAQ= | |
− | + | {{FAQ|The demo outputs all data as 0 or fails to initialize? As shown in the figure:<br/> | |
− | + | [[File: TSL25911 Light Sensor-12.png]] | |
− | {{FAQ| | + | |Please check if the pin connection is correct. |
− | |Please check if you connect the correct pins | + | ||}} |
+ | {{FAQ| Why does the data all be 0? | ||
+ | |Please check if you connect the correct pins. | ||
}} | }} | ||
− | {{FAQ| All the RGB data output is 253 as the picture. <br /> | + | {{FAQ|Raspberry Pi demo failed to initialize? |
+ | |This prompt appears for the BCM2835 and wiringPi demo:<br/> | ||
+ | [[File:TCS34725 Color Sensor02.png]]<br/> | ||
+ | Python demo:<br/> | ||
+ | [[File:TCS34725 Color Sensor03.png]]<br/> | ||
+ | If the above problem occurs, it is a device data I2C data transmission error. Most of them are hardware connection errors, please check whether the hardware connection is correct, check whether there is any problem with the hardware connection, and run i2cdetect -y 1 If the IIC address is displayed, it means that the hardware connection is no problem.<br/> | ||
+ | [[File:TCS34725 Color Sensor04.png]]<br/> | ||
+ | If the hardware connection is correct, it may be caused by incorrect use of Raspberry Pi control (see below for details), just restart the Raspberry Pi.<br/> | ||
+ | ||}} | ||
+ | {{FAQ|Incorrect use of Raspberry Pi controls may cause? | ||
+ | |If running the wiringPi demo is normal, then running Python or BCM2835 may cause the screen to fail to refresh normally, because the bcm2835 library is a library function of the Raspberry Pi CPU chip, and the bottom layer is to directly operate the registers, while the bottom layer of the wiringPi library and python are read and written by reading and writing. The device file of the Linux system operates the device, which may cause the GPIO port to be abnormal. Restarting the Raspberry Pi can solve the problem perfectly. | ||
+ | ||}} | ||
+ | {{FAQ|STM32 and Arduino routine serial port output have no data or data output is garbled? | ||
+ | |Confirm whether the baud rate is set to 115200. For the STM32 routine, please confirm that the computer is correctly connected to the development board USART2 (PA2, PA3), PA2 is TXD, and the correct COM port is selected. Control Panel -> Hardware -> Device Manager.<br/> | ||
+ | [[File:TCS34725 Color Sensor05.png]] | ||
+ | ||}} | ||
+ | {{FAQ|STM32 and Arduino demo serial port output RGB data are all 0 or initialization failed? As shown<br/> | ||
+ | [[File:TCS34725 Color Sensor06.png]][[File:TCS34725 Color Sensor07.png]] | ||
+ | |Please check the hardware connection first, and press the RESET button if there is no problem. | ||
+ | ||}} | ||
+ | {{FAQ| All the RGB data output is 253 as in the picture. <br /> | ||
:[[File:TCS34725-Color-Sensor- (27).png|400px]] | :[[File:TCS34725-Color-Sensor- (27).png|400px]] | ||
|In this case, the light intensity exceeds the inspection range, and reducing the gain can solve the problem (modify in the initial, or rewrite the gain setting TCS34725_Set_Gain(TCS34725_GAIN_16X) after the initialization). | |In this case, the light intensity exceeds the inspection range, and reducing the gain can solve the problem (modify in the initial, or rewrite the gain setting TCS34725_Set_Gain(TCS34725_GAIN_16X) after the initialization). | ||
Line 47: | Line 60: | ||
|The interrupt is compared with the data in the Clear channel. The data in the Clear channel is related to the integration time. After actual measurement, the gain is 60 times. <br /> | |The interrupt is compared with the data in the Clear channel. The data in the Clear channel is related to the integration time. After actual measurement, the gain is 60 times. <br /> | ||
[[File:TCS34725 Integrate time.jpg|400px]] <br /> | [[File:TCS34725 Integrate time.jpg|400px]] <br /> | ||
− | Therefore, you should modify the threshold value if sample rate is fast. And please increase brightness of LED when you set integrate time to 2.4ms.<br /> | + | Therefore, you should modify the threshold value if the sample rate is fast. And please increase the brightness of the LED when you set integrate time to 2.4ms.<br /> |
}} | }} | ||
− | + | =Support= | |
− | + | {{Servicebox1}} | |
− | |||
− | {{ | ||
</div> | </div> | ||
</div> | </div> |
Latest revision as of 07:30, 1 September 2023
| ||
Overview
This is a color sensor module based on TCS34725, which will output RGB data and light intensity through the I2C interface. Its advantages include high sensitivity, wide dynamic range, accurate measuring, etc.
Features
- Onboard TCS34725FN, embedded ADC, high sensitivity, wide dynamic range.
- I2C communication uses a few pins.
- Integrates IR blocking filter, minimizes the IR spectral component of the incoming light.
- Outputs RGB data without white balance.
- Outputs light intensity, feel the light like human eyes.
- Supports light intensity interrupt output and programmable upper and lower thresholds.
- Supports fill-light by onboard LED, and adjustable brightness by PWM.
- Onboard voltage level translator, compatible with 3.3V/5V operating voltage.
Specifications
- Sensor: TCS34725FN
- Communication interface: I2C
- Operating voltage: 3.3V/5V
- Dimension: 27mm × 20mm
- Resolution: 4-ch RGBC, 16-bit per channel
- Recommended measuring distance: 2mm
Pinouts
Pin | Function |
VCC | 3.3V/5V |
GND | Power ground |
SDA | I2C data input |
SCL | I2C clock pin |
INT | Interrupt output (open drain output) |
LED | Light emitting diode |
Controller
TCS34725 is used for color sensing. TCS34725 is an I2C bus-based color light-to-digital converter with an IR filter, providing a digital return of red, green, blue (RGB), and clear light sensing values. The high sensitivity, wide dynamic range, and IR blocking filter make the TCS34725 an ideal color sensor solution for use under varying lighting conditions and through attenuating materials.
Communication Protocol
I2C bus has two lines, one is a data line (SDA) and another is a lock line (SDL). There are three kinds of signals when communicating, Start signal, Stop signal, and Answer signal.
Start signal: When SCL is High, SDA change from High to Low, and it starts to transmit data.
Stop signal: When SCL is High, SDA change from Low to High, and it stops transmitting.
Answer signal: Every time IC sends back a certain Low plus to the sender after it receives 8 bits of data.
I2C Write
When working, Raspberry Pi (hereafter named Master) will first send a Start signal, then send a byte to TCS34725(hereafter named Slaver), whose first 7 bits are the address of Slaver and 1-bit write bit. The slave responds with an Answer signal every time it receives any data. The master sends the command register address to Slaver, then the data of the command register. Stop signals are sent to slaves to stop communicating.
I2C Read
When working, Master will first send a Start signal, then send a byte to Slaver, whose first 7 bits are the address of Slaver and 1-bit write bit. The slave responds with an Answer signal every time it receives any data. The master sends the command register address to the Slave. After that, Mater will send a Start signal again, and then send a byte (7-bit address and 1-bit read bit) to Slaver. Slaver response and send data of the register to Master, master answer as well. Stop signals will be sent to stop communicating.
I2C Address
The I2C device address of TCS34725 is 0x29.
Note: 0x29 is 7bit in fact, therefore, when you set the I2C address, you should left-shift one bit, and turn it to 0x52.
Enable I2C Interface
Open a terminal and run the following commands:
sudo raspi-config Choose Interfacing Options -> I2C -> Yes.
Reboot Raspberry Pi:
sudo reboot
Install Library
If you use the bookworm system, you can only use lgpio library, bcm2835 and wiringPi can't be installed and used.
BCM2835
#Open the Raspberry Pi terminal and run the following command wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.71.tar.gz tar zxvf bcm2835-1.71.tar.gz cd bcm2835-1.71/ sudo ./configure && sudo make && sudo make check && sudo make install # For more, you can refer to the official website at: http://www.airspayce.com/mikem/bcm2835/
WiringPi
#Open the Raspberry Pi terminal and run the following command cd sudo apt-get install wiringpi #For Raspberry Pi systems after May 2019 (earlier than that can be executed without), an upgrade may be required: wget https://project-downloads.drogon.net/wiringpi-latest.deb sudo dpkg -i wiringpi-latest.deb gpio -v # Run gpio -v and version 2.52 will appear, if it doesn't it means there was an installation error # Bullseye branch system using the following command: git clone https://github.com/WiringPi/WiringPi cd WiringPi . /build gpio -v # Run gpio -v and version 2.70 will appear, if it doesn't it means there was an installation error
lgpio
#Open the Raspberry Pi terminal and run the following command wget https://github.com/joan2937/lg/archive/master.zip unzip master.zip cd lg-master sudo make install # You can refer to the official website for more: https://github.com/gpiozero/lg
Python
#python2 sudo apt-get update sudo apt-get install python-pip sudo apt-get install python-pil sudo apt-get install python-numpy sudo pip install RPi.GPIO sudo pip install spidev
Download Examples
Open a terminal of the Raspberry Pi:
sudo apt-get install p7zip-full -y sudo wget https://files.waveshare.com/upload/a/a1/TCS34725_Color_Sensor_code.7z 7z x TCS34725_Color_Sensor_code.7z -O./TCS34725_Color_Sensor_code cd TCS34725_Color_Sensor_code/RaspberryPi/
Hardware Connection
TCS34725 | Raspberry Pi | Description |
Board order | ||
VCC | 5V | Power input |
GND | GND | Power ground |
SDA | 3 | I2C data input |
SCL | 5 | I2C clock pin |
INT | 11 | Interrupt output (open drain output) |
LED | 12 | Light emitting diode |
Run Examples
C Examples
BCM2835
cd bcm2835 sudo make clean sudo make sudo ./main
WiringPi
cd wiringPi sudo make clean sudo make sudo ./main
Python Example
cd python sudo python main.py
Expected Result
The RGB data are printed in the terminal:
R, G, and B values are printed in RGB888 format (DEC), C is a light value without processing, and RGB565 and RGB888 are HEX data printed in a certain format. LUX is light value processed. CT is color temperature. (https://en.wikipedia.org/wiki/Color_temperature) If you want to measure CT, please turn off the LED. INT is interrupted, 1: light value is over the threshold.
You can turn the RGB value to color with tools:
The STM32 examples are based on the STM32F103RBT6 and the STM32H743. The connection provided below is based on the STM32F103RB. If you need to use other STM32 boards, you may need to change the hardware connection and port the code yourself.
STM32
Hardware Connection
Sensor | STM32 | Description |
---|---|---|
VCC | 3.3V | Power input |
GMD | GND | Power ground |
SDA | PB9 | I2C data input |
SCL | PB8 | I2C clock pin |
INT | PB4 | Interrupt output (open drain output) |
LED | PB10 | Light emitting diode |
Examples
The examples are developed based on the HAL libraries. Download the Demo codes archive to your PC. Unzip and find the STM32 project from TCS34725_Color_Sensor_code\STM32\XNUCLEO-F103RB\MDK-ARM.
- Open the TCS34725_Color_Sensoc.uvprojx file by Keil.
- Build and the project.
- Program the project to your STM32 board.
- Connect the UART1 of your STM32 board to the PC and check the serial data with SSCOM software.
The Arduino example is written for the Arduino UNO. If you want to connect it to other Arduino boards, you may need to change the connection.
Arduino
Hardware Connection
Sensor | Arduino | Description |
---|---|---|
VCC | 5V | Power input |
GMD | GND | Power ground |
SDA | SDA | I2C data input |
SCL | SCL | I2C clock input |
INT | D5 | Interrupt output (open drain output) |
LED | D6 | Light emitting diode |
Examples
- Download the demo codes to your PC and unzip them.
- Install the Arduino IDE on your PC.
- Go into TCS34725_Color_Sensor_code/Arduino/Color_Sensor.
- Run the Color_Sensor.ino file.
- Select the correct Board and the Port.
- Build the project and upload it to the board.
- Open the serial monitor of the Arduino IDE or the SSCOM software and check the serial data.
Resources
Datasheet
FAQ
{{{5}}}
{{{5}}}
Python demo:
If the above problem occurs, it is a device data I2C data transmission error. Most of them are hardware connection errors, please check whether the hardware connection is correct, check whether there is any problem with the hardware connection, and run i2cdetect -y 1 If the IIC address is displayed, it means that the hardware connection is no problem.
If the hardware connection is correct, it may be caused by incorrect use of Raspberry Pi control (see below for details), just restart the Raspberry Pi.
{{{5}}}
{{{5}}}
Question:STM32 and Arduino demo serial port output RGB data are all 0 or initialization failed? As shown
{{{5}}}
{{{5}}}
{{{5}}}
Question:Modifying the integration time cannot trigger an interrupt or keep repeating the interrupt?
Therefore, you should modify the threshold value if the sample rate is fast. And please increase the brightness of the LED when you set integrate time to 2.4ms.
{{{5}}}
Support
Technical Support
If you need technical support or have any feedback/review, please click the Submit Now button to submit a ticket, Our support team will check and reply to you within 1 to 2 working days. Please be patient as we make every effort to help you to resolve the issue.
Working Time: 9 AM - 6 PM GMT+8 (Monday to Friday)