TCS3430 XYZ三刺激真彩传感器

简介

iPhone上的原彩显示可以使手机根据环境光线色温等条件自动调整屏幕以在不同环境下保持色彩显示一致,让人观看屏幕时更舒适、更接近环境下真实的色彩,其中就有XYZ三刺激色传感器的功劳,现在原彩显示已经成为手机屏幕的宣传卖点。


TCS3430具有先进的数字环境光感测(ALS)和CIE 1931三刺激色彩感测(XYZ),CIE1931 XYZ三刺激模型是根据人眼中三种视锥细胞设立的XYZ标准,CIE1931 XYZ色彩空间包含普通视力的人可以看到的所有色彩感觉。TCS3430的光谱响应几乎和人眼一致,可以实现高精度的照度和色温测量,因此可以实现所测即所见。
XYZ三刺激传感器在其他领域也有应用,例如:相机(更精准的自动白平衡,成像色彩更真实)、网购(商品色彩匹配,降低因色差退货率)等需要真实色彩的场景。

您可以在此了解一些有关CIE 1931-XYZ系统的知识

特性

应用场景

技术规格

引脚说明

序号 丝印 功能描述
1 + 电源正极
2 - 电源负极
3 SCL I2C时钟线
4 SDA I2C数据线
5 LED LED驱动
6 INT 中断输出

使用教程

准备

关于如何安装库文件,点击链接

  /**
   * @brief  Set the ALS gain 
   * @param  aGain  the value of gain
   */
  void setALSGain(uint8_t aGain);

  /**
   * @brief  Set the internal integration time of the  four-channel ADCs
   * @param  aTIme  integration time
   */
  void setIntegrationTime(uint8_t aTime);

    /**
   * @brief  get channel 0 value
   * @return  the z data
   */
  uint16_t getZData();

  /**
   * @brief  get channel 1 value
   * @return  the y data
   */
  uint16_t getYData();

  /**
   * @brief  get channel 2 value
   * @return  the IR1 data 
   */
  uint16_t getIR1Data();

  /**
   * @brief  get channel 3 value
   * @return  the x data
   */
  uint16_t getXData();

  /**
   * @brief  get channel 3 value
   * @return  the IR2 data
   */
  uint16_t getIR2Data();

接线图

样例代码1 - 读取数据

读取XYZ、IR1和IR2的值并打印

/*!
 * @file getXYZIRData.ino
 * @brief Detection of XYZ tristimulus and infrared data
 * @copyright  Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
 * @licence     The MIT License (MIT)
 * @author [yangfeng]<feng.yang@dfrobot.com>
 * @version  V1.0
 * @date  2021-01-26
 * @get from https://www.dfrobot.com
 * @url  https://github.com/DFRobot/DFRobot_TCS3430
 */
#include <DFRobot_TCS3430.h>

DFRobot_TCS3430 TCS3430;
void setup() {
  Serial.begin(115200);

  while(!TCS3430.begin()){
    Serial.println("Please check that the IIC device is properly connected");
    delay(1000);
  }
}

void loop() {
  uint16_t XData = TCS3430.getXData();
  uint16_t YData = TCS3430.getYData();
  uint16_t ZData = TCS3430.getZData();
  uint16_t IR1Data = TCS3430.getIR1Data();
  uint16_t IR2Data = TCS3430.getIR2Data();
  String str = "X : " + String(XData) + "    Y : " + String(YData) + "    Z : " +  String(ZData) + "    IR1 : "+String(IR1Data) + "    IR2 : "+String(IR2Data);
  Serial.println(str);
  delay(1000);
}

结果

SEN0403RESULT1

样例代码2 - 阈值中断

当Z通道值连续10次超过阈值,则产生一次中断

/*!
 * @file setALSInterrupt.ino
 * @brief Turn on the ambient light sense interrupt function to obtain the ambient light data within the specified range
 * @copyright  Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
 * @licence     The MIT License (MIT)
 * @author [yangfeng]<feng.yang@dfrobot.com>
 * @version  V1.0
 * @date  2021-01-26
 * @get from https://www.dfrobot.com
 * @url  https://github.com/DFRobot/DFRobot_TCS3430
 */
#include <DFRobot_TCS3430.h>


DFRobot_TCS3430 TCS3430;

int LEDpin = 12;
int interruptPin = 2;

volatile int state = 0;

void handleInterrupt(){

  Serial.println("WARNING:The data obtained exceeds the threshold");
  state = 1;
}

void setup() {
  Serial.begin(115200);

  pinMode(interruptPin, INPUT_PULLUP);

  while(!TCS3430.begin()){
    Serial.println("Please check that the IIC device is properly connected");
    delay(1000);
  }

// Configure the sensor's ADC integration time, device waiting time, and gain

  //TCS3430.setWaitTimer(true);
  //TCS3430.setWaitLong(false);
    /*
   * By asserting wlong, in register 0x8D the wait time is given in multiples of 33.4ms (12x).
   * ----------------------------------------
   * | wtime | Wait Cycles | Wait Time      |
   * ----------------------------------------
   * |  0x00 |      1      | 2.78ms/ 33.4ms |
   * ----------------------------------------
   * |  0x01 |      2      | 5.56ms/ 66.7ms |
   * ----------------------------------------
   * |  ...  |     ...     |      ...       |
   * ----------------------------------------
   * |  0x23 |     36      | 100ms/ 1.20s   |
   * ----------------------------------------
   * |  ...  |     ...     |       ...      |
   * ----------------------------------------
   * |  0xff |     256     |  711ms/ 8.53s  |
   * ----------------------------------------
   */
  //TCS3430.setWaitTime(/*wTime=*/0x00);
  /*
   * Maximum ALS Value=  min [CYCLES * 1024, 65535]
   * ---------------------------------------------------------------------
   * | aTime | Integration Cycles | Integration Time | Maximum ALS Value |
   * ---------------------------------------------------------------------
   * |  0x00 |         1          |       2.78ms     |        1023       |
   * ---------------------------------------------------------------------
   * |  0x01 |         2          |       5.56ms     |        2047       |
   * ---------------------------------------------------------------------
   * |  ...  |        ...         |       ...        |        ...        |
   * ---------------------------------------------------------------------
   * |  0x11 |         18         |       50ms       |        18431      |
   * ---------------------------------------------------------------------
   * |  0x40 |         65         |       181ms      |        65535      |
   * ---------------------------------------------------------------------
   * |  ...  |        ...         |       ...        |        ...        |
   * ---------------------------------------------------------------------
   * |  0xff |        256         |       711ms      |        65535      |
   * ---------------------------------------------------------------------
   */
  TCS3430.setIntegrationTime(/*aTime=*/0x23);
  /*
   * AGAIN: ALS Gain Control. Sets the gain of the ALS DAC.
   * ----------------------------------------------------------
   * | Field Value |            ALS GAIN VALUE                |
   * ----------------------------------------------------------
   * |     0       |               1X Gain                    |
   * ----------------------------------------------------------
   * |     1       |               4X Gain                    |
   * ----------------------------------------------------------
   * |     2       |               16X Gain                   |
   * ----------------------------------------------------------
   * |     3       |               64X Gain                   |
   * ----------------------------------------------------------
   */
  TCS3430.setALSGain(/*aGian=*/3);
  //128X high gain
  //TCS3430.setHighGAIN()

/* Turn on the ALS interrupt function of the device */

  //mode = true : enable ALS Interrupt
  TCS3430.setALSInterrupt(/*mode*/true);

  /*
   *                       APERS                              
   * ----------------------------------------------------------
   * | Field Value |            Persistence                   |
   * ----------------------------------------------------------
   * |     0x00    |   Every ALS cycle generates an interrupt |
   * ----------------------------------------------------------
   * |     0x01    |   Any value outside of threshold range   |
   * ----------------------------------------------------------
   * |     0x02    |   2 consecutive values out of range      |
   * ----------------------------------------------------------
   * |     0x03    |   3 consecutive values out of range      |
   * ----------------------------------------------------------
   * |     0x04    |   5 consecutive values out of range      |
   * ----------------------------------------------------------
   * |     0x05    |   10 consecutive values out of range     |
   * ----------------------------------------------------------
   * |     0x06    |   15 consecutive values out of range     |
   * ----------------------------------------------------------
   * |     0x07    |   20 consecutive values out of range     |
   * ----------------------------------------------------------
   * |     0x08    |   25 consecutive values out of range     |
   * ----------------------------------------------------------
   * |     0x09    |   30 consecutive values out of range     |
   * ----------------------------------------------------------
   * |     0x0A    |   35 consecutive values out of range     |
   * ----------------------------------------------------------
   * |     0x0B    |   40 consecutive values out of range     |
   * ----------------------------------------------------------
   * |     0x0C    |   45 consecutive values out of range     |
   * ----------------------------------------------------------
   * |     0x0D    |   50 consecutive values out of range     |
   * ----------------------------------------------------------
   * |     0x0E    |   55 consecutive values out of range     |
   * ----------------------------------------------------------
   * |     0x0F    |   60 consecutive values out of range     |
   * ----------------------------------------------------------
   */
  TCS3430.setInterruptPersistence(/*apers=*/0x05);

  // Set the threshold range(0-65535)
  TCS3430.setCH0IntThreshold(/*thresholdL=*/50,/*thresholdH=*/100);

  Serial.println("If the light data exceeds the threshold, an interrupt is triggered and a warning is printed.");

  attachInterrupt(digitalPinToInterrupt(interruptPin), handleInterrupt, FALLING);

}
void loop() {
  if (state == 1){
    state =0;
    TCS3430.getDeviceStatus(); 
  }else{
    Serial.println(TCS3430.getZData());
    delay(100);   //该延时只影响打印速度,并不会影响中断触发
  }
}

结果

SEN0403RESULT2

常见问题

还没有客户对此产品有任何问题,欢迎通过qq或者论坛联系我们!

更多问题及有趣的应用,可以 访问论坛 进行查阅或发帖。

更多

DFshopping_car1.png DFRobot商城购买链接