“SKU:RB-02S161 IIC 顏色傳感器”的版本間的差異

來自ALSROBOT WiKi
跳轉至: 導航、 搜索
?example2_Arduino
?使用方法
第98行: 第98行:
  
 
* 硬件連接
 
* 硬件連接
 +
[[文件:02S161021.png|500px|縮略圖|居中]]
  
 
* 示例程序
 
* 示例程序
第197行: 第198行:
  
 
* 程序效果
 
* 程序效果
?
 
+
顏色傳感器識別不同顏色的同時,RGB LED 發(fā)出相應顏色的光。
 
===example_Raspberry Pi===
 
===example_Raspberry Pi===
?
 
  
 
==相關資料==
 
==相關資料==

2018年9月10日 (一) 14:13的版本

02S161000.png

目錄

產品概述

IIC顏色傳感器使用TCS34725顏色傳感器進行顏色識別。TCS34725是一款高性價比的RGB全彩顏色識別傳感器,傳感器通過光學感應來識別物體的表面顏色。支持紅、綠、藍(RGB)三基色,支持明光感應,可以輸出對應的具體數(shù)值,幫助您還原顏色本真。
為了提高精度,防止周邊環(huán)境干擾,我們在傳感器上添加了一個鏡頭罩,有效減少外界雜光干擾傳感器,讓顏色管理更加準確。板載自帶2個高亮LED,可以讓傳感器在低環(huán)境光的情況下依然能夠正常使用,實現(xiàn)“補光”的功能。模塊采用I2C通信,擁有4P防插反接口,更加便利。

產品參數(shù)

基本參數(shù)

1.品名:IIC顏色傳感器
2.貨號:RB-02S161
3.品牌:奧松機器人
4.產地:哈爾濱
5.尺寸:25*40
6.固定孔:M3*2

電氣參數(shù)

1.接口類型:KF2510-4P防插反接口
2.信號類型:IIC通訊
3.指示燈:高亮LED
4.工作電壓:5V
5.工作電流:100mA
6.引腳定義:

+:電源正極
-:電源負極
SDA:IIC數(shù)據(jù)端口
SCL:IIC時鐘端口

7.擴展接口:

LED:兩個板載LED控制端口,懸空或高電平點亮,低電平熄滅
INT:中斷引腳

8.連接線:4P 傳感器連接線
9.檢測范圍:紅、綠、藍及白光檢測
10.工作溫度:-40 - 85℃
產品尺寸圖:

02S16101.png

使用方法

example1_Arduino

  • 主要硬件
Arduino UNO 控制器
傳感器擴展板 V5.0
IIC 顏色傳感器
USB 數(shù)據(jù)線
  • 硬件連接
02S161020.png
  • 示例程序
/* Example code for the ALS_TCS34725 breakout library */

/* Connect SCL    to analog 5
   Connect SDA    to analog 4
   Connect VDD    to 5V DC
   Connect GROUND to common ground */

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

ALS_TCS34725 tcs = ALS_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);

void setup(void) {
  Serial.begin(9600);
  
  if (tcs.begin()) {
    Serial.println("Found sensor");
  } else {
    Serial.println("No TCS34725 found");
    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);
  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(" ");
}
  • 程序效果

打開 Arduino IDE 自帶的串口監(jiān)視器,將顏色傳感器放于不同顏色的表面,可以看到串口監(jiān)視器中打印不同的數(shù)值

02S16103.png

example2_Arduino

  • 主要硬件
Arduino UNO 控制器
傳感器擴展板 V5.0
串行 RGB LED
RB - 65PG舵機
IIC 顏色傳感器
  • 硬件連接
02S161021.png
  • 示例程序
#include <Wire.h>
#include <ALS_TCS34725.h>
#include <ChainableLED.h>
#include <Servo.h>
float r, g, b;

Servo myservo; 
#define NUM_LEDS  1
ChainableLED leds(5, 6, NUM_LEDS); //DIN 連接 D6, CIN 連接 D5

ALS_TCS34725 tcs = ALS_TCS34725(TCS34725_INTEGRATIONTIME_24MS, TCS34725_GAIN_1X);
const int interruptPin = 2;
volatile boolean state = false;
int pos = 0; 

//Interrupt Service Routine
void isr() 
{
  state = true;
}

void getRawData_noDelay(uint16_t *r, uint16_t *g, uint16_t *b, uint16_t *c)
{
  *c = tcs.read16(TCS34725_CDATAL);
  *r = tcs.read16(TCS34725_RDATAL);
  *g = tcs.read16(TCS34725_GDATAL);
  *b = tcs.read16(TCS34725_BDATAL);
}


void setup() {
   myservo.attach(10);
   myservo.write(20);
   
   leds.init();
   
  pinMode(interruptPin, INPUT_PULLUP); //TCS interrupt output is Active-LOW and Open-Drain
  attachInterrupt(digitalPinToInterrupt(interruptPin), isr, FALLING);

  Serial.begin(9600);
  
  if (tcs.begin()) {
  } else {
    while (1);
  }
  
  // Set persistence filter to generate an interrupt for every RGB Cycle, regardless of the integration limits
tcs.write8(TCS34725_PERS, TCS34725_PERS_NONE); 
tcs.setInterrupt(true);
  
Serial.flush();
}


void loop() {
  checkcolor();
    for (pos = 20; pos <= 160; pos += 1) { 
    myservo.write(pos);              
    checkcolor();
    for (byte i=0; i<NUM_LEDS; i++)
    leds.setColorRGB(i, (int)r, (int)g, ( int)b); 
   }
   
   for (pos = 160; pos >= 20; pos -= 1) { 
    myservo.write(pos);            
    checkcolor();
    for (byte i=0; i<NUM_LEDS; i++)
 leds.setColorRGB(i, (int)r, (int)g, (int)b); 
  }

}

void checkcolor()
{
  if (state) {
    uint16_t  red, green, blue,clear;
    getRawData_noDelay(&red, &green, &blue,&clear);
    uint32_t sum = clear;
  
  r = red; r /= sum;
  g = green; g /= sum;
  b = blue; b /= sum;
  r *= 256; g *= 256; b *= 256;
 Serial.print("\tR:\t"); Serial.print(r);
 Serial.print("\tG:\t"); Serial.print(g);
 Serial.print("\tB:\t"); Serial.print(b);
 Serial.println();
 Serial.flush();

 tcs.clearInterrupt();
 state = false;
  }
  }
  • 程序效果

顏色傳感器識別不同顏色的同時,RGB LED 發(fā)出相應顏色的光。

example_Raspberry Pi

相關資料

Erweima.png
  • IIC 顏色傳感器傳感器 datasheet & 示例程序

下載鏈接:

  • 相關資料

[ datasheet]