[Diao Ye learns programming] Arduino hands-on (165)---TCS34725 color recognition module

The reference to 37 sensors and modules has been widely circulated on the Internet. In fact, there must be more than 37 sensor modules compatible with Arduino. In view of the fact that I have accumulated some sensor and actuator modules on hand, in accordance with the concept of true knowledge (must be hands-on), for the purpose of learning and communication, here I am going to try and do more experiments one by one. Whether it is successful or not, it will be recorded ——Small progress or unsolvable problems, I hope to be able to throw bricks and spark jade.

[Arduino] 168 kinds of sensor module series experiments (data code + simulation programming + graphics programming)
Experiment 165: TCS34725 color recognition sensor RGB IIC bright light sensor module ColorSensor

insert image description here
insert image description here

Knowledge Point: TCS3472 Chip
The TCS3472 device provides digital return of red, green, blue (RGB) and clear light sensing values. An IR-blocking filter, integrated on-chip and positioned to the color-sensing photodiode, minimizes the infrared spectrum component of incident light and allows accurate color measurement. High sensitivity, wide dynamic range and IR blocking filter make the TCS3472 an ideal color sensor solution for different lighting conditions and through attenuating materials.

The TCS3472 color sensor has a wide range of applications including RGB LED backlight control, solid-state lighting, health/fitness products, industrial process control, and medical diagnostic equipment. In addition an IR blocking filter enables the TCS3472 to perform ambient light sensing (ALS). Ambient light sensing applications are widely used in display-based products such as mobile phones, laptops and TVs to sense the lighting environment and enable automatic display brightness for optimal viewing and power saving. The TCS3472 itself can enter a low-power wait state between light sensing to further reduce average power consumption.

insert image description here
TCS34725 Features
1. Red, Green, Blue (RGB),
and Clear Light IR Blocking Filter Detection
− Programmable Analog Gain and Integration Time
− 3,800,000:1 Dynamic Range
− Very High Sensitivity − Ideal for Operation Behind Black Glass

2. Maskable interrupt
− Programmable upper and lower thresholds and persistence filters

3. Power management
− Low power consumption - 2.5- A sleep state
− 65- wait state with programmable wait state
time from 2.4 ms to > 7 seconds

4. I2C fast mode compatible interface
− data rate up to 400 kbit/s
− input voltage level compatible with VDD
or 1.8 V bus

5. Register set and pin compatible with
TCS3x71 series

insert image description here

TCS34725 Functional Block Diagram
insert image description here
TCS3472 Operating Principle
The TCS3472 optical-to-digital converter includes a 3 × 4 photodiode array, four analog-to-digital converters (ADCs) integrating photodiode current, data registers, state machines, and I2C interface. The 3×4 photodiode array consists of red-filtered, green-filtered, blue-filtered, and clear (unfiltered) photodiodes.

In addition, the photodiode is coated with an infrared blocking filter. Four integrating ADCs simultaneously convert the amplified photodiode current to a 16-bit digital value. After the conversion cycle is complete, the results are transferred to the data registers, which are double-buffered to ensure data integrity. All internal timing and low power wait states are controlled by a state machine.

Communication of data to the TCS3472 is via a fast 2-wire I2C serial bus up to 400 kHz. This industry standard I2C bus facilitates easy, direct connection to microcontrollers and embedded processors. In addition to the I2C bus, the TCS3472 also provides a separate interrupt signal output. When the interrupt is enabled and exceeds a user-defined threshold, the active-low interrupt is asserted and remains asserted until it is cleared by the controller. This interrupt feature simplifies and improves system efficiency by eliminating the need to poll the TCS3472. Users can define upper and lower outage thresholds and apply outage persistence filters. The outage persistence filter allows the user to define the number of consecutive threshold violation events required before an outage is generated. The interrupt output is open-drain so it can be wired-ORed with other devices.
insert image description here
TCS3472 Spectral Response

insert image description here
Relevant technical documents (English version)
http://pdf-html.ic37.com/pdf_file_B/20200531/pdf_pdf/pdf6/AMSCO/TCS3472_datasheet_1159592/188527/TCS347_datasheet.pdf
Aoxue Electronics (Chinese version)
https://www.waveshare .net/w/upload/3/3c/TCS34725_Color_Sensro_user_manual_cn.pdf

insert image description here
TCS34725 Color Sensor Module

[Introduction]
I am a color sensor that supports the output of RGB color data and light intensity through the I2C interface. It has the advantages of high sensitivity, wide dynamic range and accurate measurement.
[Features]
Adopt TCS34725FN, built-in ADC, high sensitivity, wide dynamic range
Communication through I2C interface, will not occupy too many interface pin resources
Integrated infrared blocking filter, can greatly reduce the infrared spectrum of incident light
Support output RGB color Data, no need for white balance
Support output light intensity, can get similar to the human eye's response
to light Support light intensity interrupt output, programmable upper and lower limit thresholds
Support LED light supplementary light control, brightness can be adjusted by PWM
Onboard level conversion circuit , Compatible with 3.3V/5V working level
Provide complete supporting information manuals (Raspberry/Arduino/STM32 and other sample programs)
[Parameters]
Control chip: TCS34725FN
Communication interface: I2C
Working voltage: 3.3V/5V
Product size: 27mm × 20mm
resolution: 4 channels RGBC, 16 bits per channel
Recommended detection distance: 2mm
【Application】
Color sorting, sensing and calibrating ambient light, product color recognition and classification, etc.

insert image description here
TCS34725 Color Recognition Sensor Module Electrical Schematic

insert image description here
insert image description here
TCS34725 Color Recognition Module Overview
This module is a color sensor based on ams AG's TCS34725FN color light-to-digital converter. The sensor provides digital output of red, green, blue (RGB) and clear light sensing values. An integrated IR blocking filter minimizes the IR spectral component of the incident light and enables accurate color measurement. Features high sensitivity, wide dynamic range and IR cut filter. Minimizes IR and UV spectral component effects to produce accurate color measurements. And with ambient light detection and maskable interrupt. Communication is via the I2C interface.

Parameters
Working voltage: 3.3V/5V
Control chip TCS34725FN
Logic voltage: 3.3V/5V
Communication interface: I2C
Product size: 27X20(mm)

Interface description
insert image description here
Schematic diagram of experimental hardware connection

insert image description here

[Arduino] 168 sensor module series experiments (data code + simulation programming + graphics programming)

Experiment 165: TCS34725 Color Recognition Sensor RGB IIC Bright Light Sensing Module ColorSensor

Project 1: simple color recognition, serial port output recognition

Arduino experiment open source code

/*

 【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)

  实验一百六十五:TCS34725颜色识别传感器 RGB IIC明光感应模块 ColorSensor

 项目之一:简单的颜色识别,串口输出识别情况

*/

#include "DEV_Config.h"

#include "TCS34725.h"

RGB rgb, RGB888;

UWORD  RGB565 = 0;

void setup() {
    
    

 Config_Init();

 if (TCS34725_Init() != 0) {
    
    

  Serial.print("TCS34725 初始化错误!\r\n");

  return 0;

 }

 Serial.print("TCS34725 初始化成功!\r\n");

}

void loop() {
    
    

 rgb = TCS34725_Get_RGBData();

 RGB888 = TCS34725_GetRGB888(rgb);

 RGB565 = TCS34725_GetRGB565(rgb);

 Serial.print("RGB888 :R=");

 Serial.print(RGB888.R);

 Serial.print(" G=");

 Serial.print(RGB888.G);

 Serial.print(" B=");

 Serial.print(RGB888.B);

 Serial.print("\r\n");

 Serial.print("RGB 编号= 0x");

 Serial.println((RGB565), HEX);

 if (TCS34725_GetLux_Interrupt(0xff00, 0x00ff) == 1) {
    
    

  Serial.print("Lux_Interrupt = 1\r\n");

 } else {
    
    

  Serial.print("勒克斯中断 = 0\r\n");

 }

 Serial.print("\r\n");

 DEV_Delay_ms(1000);

}

Experimental serial port return

insert image description here
Experimental scene graph

insert image description here
Experimental open source graphics programming (Mind+, Mixly, learning while editing)
project two: TCS34725 color recognition

insert image description here
Experimental serial port return

insert image description here
[Arduino] 168 sensor module series experiments (data code + simulation programming + graphics programming)

Experiment 165: TCS34725 Color Recognition Sensor RGB IIC Bright Light Sensing Module ColorSensor

Project 3: Testing the Breakout Library for Adafruit TCS34725

Arduino experiment open source code

/*

 【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)

  TCS34725颜色识别传感器 RGB IIC明光感应模块 ColorSensor

 项目之三:测试Adafruit TCS34725 的突破库

 模块接线:

 TCS34725 Arduino

 VCC    5V

 GND    GND

 SDA    A4

 SCL    A5

*/

#include <Wire.h>

#include "Adafruit_TCS34725.h"

/* Initialise with default values (int time = 2.4ms, gain = 1x) */

// Adafruit_TCS34725 tcs = Adafruit_TCS34725();

//使用特定的 int 时间和增益值初始化

Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_614MS, TCS34725_GAIN_1X);

void setup(void) {
    
    

 Serial.begin(9600);

 if (tcs.begin()) {
    
    

  Serial.println("Found sensor");

 } else {
    
    

  Serial.println("No TCS34725 found ... check your connections");

  while (1);

 }

 // 现在我们准备好获取读数了!

}

void loop(void) {
    
    

 uint16_t r, g, b, c, colorTemp, lux;

 tcs.getRawData(&r, &g, &b, &c);

 // colorTemp = tcs.calculateColorTemperature(r, g, b);

 colorTemp = tcs.calculateColorTemperature_dn40(r, g, b, c);

 lux = tcs.calculateLux(r, g, b);

 Serial.print("Color Temp: "); Serial.print(colorTemp, DEC); Serial.print(" K - ");

 Serial.print("Lux: "); Serial.print(lux, DEC); Serial.print(" - ");

 Serial.print("R: "); Serial.print(r, DEC); Serial.print(" ");

 Serial.print("G: "); Serial.print(g, DEC); Serial.print(" ");

 Serial.print("B: "); Serial.print(b, DEC); Serial.print(" ");

 Serial.print("C: "); Serial.print(c, DEC); Serial.print(" ");

 Serial.println(" ");

}

Experimental serial port return

insert image description here
Experimental schematic diagram of the simplest wiring method

insert image description here
[Arduino] 168 sensor module series experiments (data code + simulation programming + graphics programming)

Experiment 165: TCS34725 Color Recognition Sensor RGB IIC Bright Light Sensing Module ColorSensor

Project 4: RGB light color sensor using TCS34725 module

Arduino experiment open source code

/*
  【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  实验一百九十三:TCS34725颜色识别传感器 RGB IIC明光感应模块 ColorSensor
  项目之四:使用 TCS34725 模块的 RGB 灯颜色传感器
*/

#include <Wire.h>
#include "Adafruit_TCS34725.h"

#define redpin 3
#define greenpin 5
#define bluepin 6

#define commonAnode false
byte gammatable[256];
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);

void setup() {
    
    
  Serial.begin(9600);
  Serial.println("Color View Test!");

  if (tcs.begin()) {
    
    
    Serial.println("Found sensor");
  } else {
    
    
    Serial.println("No TCS34725 found ... check your connections");
    while (1); // halt!
  }

  // use these three pins to drive an LED
  pinMode(redpin, OUTPUT);
  pinMode(greenpin, OUTPUT);
  pinMode(bluepin, OUTPUT);

  for (int i = 0; i < 256; i++) {
    
    
    float x = i;
    x /= 255;
    x = pow(x, 2.5);
    x *= 255;

    if (commonAnode) {
    
    
      gammatable[i] = 255 - x;
    } else {
    
    
      gammatable[i] = x;
    }
    //Serial.println(gammatable[i]);
  }
}

void loop() {
    
    
  uint16_t clear, red, green, blue;
  tcs.setInterrupt(false);      // turn on LED
  delay(60);
  tcs.getRawData(&red, &green, &blue, &clear);
  tcs.setInterrupt(true);

  Serial.print("C:\t"); Serial.print(clear);
  Serial.print("\tR:\t"); Serial.print(red);
  Serial.print("\tG:\t"); Serial.print(green);
  Serial.print("\tB:\t"); Serial.print(blue);

  // Figure out some basic hex code for visualization
  uint32_t sum = clear;
  float r, g, b;
  r = red; r /= sum;
  g = green; g /= sum;
  b = blue; b /= sum;
  r *= 256; g *= 256; b *= 256;
  Serial.print("\t");
  Serial.print((int)r, HEX); Serial.print((int)g, HEX); Serial.print((int)b, HEX);
  Serial.println();

  //Serial.print((int)r ); Serial.print(" "); Serial.print((int)g);Serial.print(" ");  Serial.println((int)b );
  analogWrite(redpin, gammatable[(int)r]);
  analogWrite(greenpin, gammatable[(int)g]);
  analogWrite(bluepin, gammatable[(int)b]);
}

Code breakdown:

#define redpin 3
#define greenpin 5
#define bluepin 6

This part is where you assign the RGB pins to the arduino. Here 3 is chosen as the red pin, 5 as the green pin, 6 as the blue pin, and the last pin is used for GND because a common common cathode RGB LED is used. If you are using a common anode, it should be tied to VCC.

#define commonAnode false

Set this to true if a common anode RGB LED is used.

pinMode(redpin, OUTPUT);
pinMode(greenpin, OUTPUT);
pinMode(bluepin, OUTPUT);

In this section, we specify the RGB LED as the output of the RGB sensor. We use RGB LEDs driven by these three pins.

analogWrite(redpin, gammatable[(int)r]);
analogWrite(greenpin, gammatable[(int)g]);
analogWrite(bluepin, gammatable[(int)b]);

Finally, the AnalogWrite function is used because we want our output to be any number (analog) compared to the DigitalWrite function, which only has HIGH and LOW (digital).

The return of the experimental serial port
insert image description here
Measure a red object, and the RGB light will emit red light

insert image description here
Measure the red object, the RGB light emits red light, and the experimental serial port returns

insert image description here

Measure green objects, RGB light emits green light

insert image description here
Measure the green object, the RGB light emits green light, and the experimental serial port returns

insert image description here

Guess you like

Origin blog.csdn.net/weixin_41659040/article/details/131778645
Recommended