Khác biệt giữa các bản “Cảm Biến Màu Sắc TCS34725”

Từ ChipFC Wiki
Bước tới: chuyển hướng, tìm kiếm
(Tạo trang mới với nội dung “Category:Sensor 300px|thumb|right|ChipI Button Top.jpg|Mô-đun Chipi Button == G…”)
 
(Thử với tcs34725)
 
(Không hiển thị 10 phiên bản của cùng người dùng ở giữa)
Dòng 1: Dòng 1:
 
[[Category:Sensor]]
 
[[Category:Sensor]]
  
[[Image:module-cam-bien-nhip-tim-va-oxy-trong-mau-max30100-1.jpg|300px|thumb|right|ChipI Button Top.jpg|Mô-đun Chipi Button]]
+
[[Image:module-cam-bien-mau-sac-tcs34725-1.jpg|300px|thumb|right]]
  
 
== Giới thiệu ==
 
== Giới thiệu ==
  
[https://chipfc.com/module-chuc-nang/cam-bien/sinh-hoc/module-cam-bien-nhip-tim-va-oxy-trong-mau-max30100.html Module Cảm Biến Nhịp Tim và Oxy Trong Máu MAX30100] trên trang chủ
+
[https://chipfc.com/module-chuc-nang/cam-bien/dieu-kien-moi-truong/module-cam-bien-mau-sac-tcs34725.html Module Cảm Biến Màu Sắc TCS34725] trên trang chủ
  
Module tích hợp Cảm biến MAX30100 của hãng Maxim, khả năng đo được nồng độ Oxy trong máu và nhịp tim. Đó một cảm biến quang học, nó phát ra hai bước sóng ánh sáng từ hai đèn LED - một LED đỏ một LED hồng ngoại - sau đó đo sự hấp thụ của xung huyết (pulsing blood) bằng cách thu tín hiệu thông qua một bộ cảm biến ánh sáng (photodetector). Sự kết hợp màu LED đặc biệt này được tối ưu hóa để đọc dữ liệu ở đầu ngón tay.
+
Thiết bị điện tử của bạn bây giờ thể nhìn thấy màu sắc rực rỡ với module cảm biến nhỏ xíu đáng yêu này. Bạn sẽ thấy TCS34725 chính là cảm biến màu sắc tốt nhất trên thị trường, nó có thể nhận biết từng màu thành phần màu RGB cường độ sáng trắng.
  
Cảm biến nhịp tim và Oxy trong máu MAX30100 được ứng dụng nhiều trong lĩnh vực y sinh, cảm biến sử dụng phương pháp đo quang phổ biến hiện nay, với thiết kế và chất liệu mắt đo từ chính hãng Maxim cho độ chính xác và độ bền cao, độ nhiễu thấp. Ngoài ra, cảm biến sử dụng giao tiếp I2C rất dễ tiếp cận với Arduino.
+
[[Image:module-cam-bien-mau-sac-tcs34725-top.jpg|x200px]]
 
+
[[Image:module-cam-bien-mau-sac-tcs34725-bot.jpg|x200px]]
[[Image:module-cam-bien-nhip-tim-va-oxy-trong-mau-max30100-top.jpg|x200px]]
 
[[Image:module-cam-bien-nhip-tim-va-oxy-trong-mau-max30100-bot.jpg|x200px]]
 
 
 
=== Đặc điểm chính ===
 
 
 
* Tích hợp IC MAX30100 của Maxim, đây chính là bộ cảm biến quang học gồm hai LED, được tối ưu và giảm nhiễu.
 
* Sử dụng nguyên lý đo sự hấp thụ quang học của máu.
 
* Tốc độ lấy mẫu và trạng thái LED có thể lập trình được phục vụ cho mục đích tiết kiệm năng lượng.
 
* Giao tiếp thông qua kết nối I2C.
 
* Siêu tiết kiệm năng lượng, giúp tăng tuổi thọ pin cho các ứng dụng đeo tay.
 
* Giải pháp tích hợp đo nhịp tim và oxy trong máu trong cùng một thiết bị.
 
  
 
=== Thông số kỹ thuật ===
 
=== Thông số kỹ thuật ===
  
* IC: MAX30100
+
* IC TCS34725
* Điện áp hoạt động: 1.8 - 5.5 VDC (khuyên dùng 5V)
+
* Điện áp hoạt động 3.3/5.0 VDC
* Giao tiếp I2C, mức TTL
+
* Giao tiếp I2C
* Kích thước: 19 x 14 x 3 (mm)
+
* I2C address 0x29 (7-bit)
* Khối lượng: 5g
+
* Khối lượng: 3.23g
 +
* Kích thước: 20.44mm / 0.8" x 20.28mm / 0.79"
  
 
== Mô tả các chân kết nối ==
 
== Mô tả các chân kết nối ==
  
[[Hình:module-cam-bien-nhip-tim-va-oxy-trong-mau-max30100-pinout.png|x200px]]
+
[[Hình:module-cam-bien-mau-sac-tcs34725-pinout.jpg|x200px]]
  
 
{| class="wikitable sortable"
 
{| class="wikitable sortable"
Dòng 39: Dòng 29:
 
! Thứ tự chân !! Ký hiệu !! Loại !! Mô tả
 
! Thứ tự chân !! Ký hiệu !! Loại !! Mô tả
 
|-
 
|-
| 1 || VIN || Power || Nguồn cấp 1.8V - 5.5V (khuyên dùng 5V)
+
| 1 || VIN || Power || Nguồn cấp 3.6-5.5V
 
|-
 
|-
| 2 || SCL || Input || I2C SCL
+
| 2 || GND || Power || Điện áp đất 0V
 
|-
 
|-
| 3 || SDA || I/O|| I2C SDA
+
| 3 || 3V3 || Power || Điện áp nguồn 3.3V
 
|-
 
|-
| 4 || INT || Output || Chân INT của MAX30100
+
| 4 || SCL || Input || I2C SCL
 
|-
 
|-
| 5 || IRD || || Chân IR_DRV của MAX30100
+
| 5 || SDA || I/O  || I2C SDA
 
|-
 
|-
| 6 || RD || || Chân R_DRV của MAX30100
+
| 6 || INT || Input || Chân INT của TCS34725
 
|-
 
|-
| 7 || GND || Power || Điện áp đất 0V
+
| 7 || LED || Input || Bật/Tắt LED
 
|}
 
|}
  
Dòng 58: Dòng 48:
 
=== Kết nối module với Arduino ===
 
=== Kết nối module với Arduino ===
  
Kết nối cơ bản giữa module MAX30100 và Arduino như hình bên dưới. Chú ý là cần mắc 2 điện trở 4.7KΩ kéo lên cho hai đường SCL và SDA của I2C.
+
Kết nối cơ bản giữa module TCS34725 và Arduino như hình bên dưới.  
  
[[Hình:module-cam-bien-nhip-tim-va-oxy-trong-mau-max30100-connect-arduino.png|x300px]]
+
Chú ý: nếu điện áp cấp nguồn là 3.3V thì cấp vào chân 3V3 thay vì VIN.
 +
 
 +
[[Hình:module-cam-bien-mau-sac-tcs34725-connect-arduino.png|x300px]]
  
 
=== Tải thư viện ===
 
=== Tải thư viện ===
  
Dùng thư viện [http://download.chipfc.com/download.php?id=17&token=JxhImR50tFxOMSdJrINfKme2MnZSafVK Arduino-MAX30100 library] được phát triển bởi [https://github.com/oxullo/Arduino-MAX30100 oxullo]
+
Dùng thư viện [http://download.chipfc.com/download.php?id=20&token=PdkJoV2a9ZHmJePAM97AQbMiuthMs7W8 Adafruit_TCS34725 Arduino library] được phát triển bởi [https://github.com/adafruit/Adafruit_TCS34725 Adafruit]
  
 
Nếu bạn chưa biết cách sử dụng một thư viện Arduino có thể xem hướng dẫn tại [[Thư viện Arduino]]
 
Nếu bạn chưa biết cách sử dụng một thư viện Arduino có thể xem hướng dẫn tại [[Thư viện Arduino]]
Dòng 70: Dòng 62:
 
=== Sử dụng ví dụ mẫu ===
 
=== Sử dụng ví dụ mẫu ===
  
Sau khi cài đặt thành công thư viện Arduino-MAX30100, Arduino IDE sẽ xuất hiện mục '''MAX30100lib'''.  
+
Sau khi cài đặt thành công thư viện Adafruit_TCS34725, Arduino IDE sẽ xuất hiện mục '''Adafruit TCS34725'''.  
  
 
Với các Example được viết sẵn là:
 
Với các Example được viết sẵn là:
* '''MAX30100_Debug''': được dùng kết hợp với Processing pde "rolling_graph" (thư mục extras), để hiển thị dữ liệu với nhiều giai đoạn xử lý khác nhau.
 
* '''MAX30100_Minimal''': một ví dụ đơn giản hiển thị kết quả dễ đọc qua Serial Monitor.
 
* '''MAX30100_DrawData''': ví dụ lấy dữ liệu gốc từ cảm biến, chưa qua xử lý, có thể quan sát kết quả qua Serial Plotter hoặc Serial Monitor.
 
* '''MAX30100_Tester''': sketch này giúp bạn tìm nguyên nhân gây ra lỗi cảm biến trong trường hợp cảm biến gặp vấn đề.
 
  
[[Hình:module-cam-bien-nhip-tim-va-oxy-trong-mau-max30100-library-1.png|600px]]
+
* '''colorview''': Đọc giá trị màu sắc và hiển thị ra LED RGB.
 +
* '''tcs34725''': Đọc giá trị màu sắc và hiển thị ra Serial.
 +
* '''tcs34725autorange''': Một thử nghiệm thực hiện việc cải thiện độ sáng lux và nhiệt độ màu.
  
==== Thử với MAX30100_Minimal ====
+
[[Hình:module-cam-bien-mau-sac-tcs34725-library-1.png|600px]]
  
Nội dung code mẫu
+
==== Thử với tcs34725 ====
  
<syntaxhighlight lang="cpp" style="border-radius: 6px 6px 6px 6px;border: 1px dotted">
+
Nội dung code mẫu:
 +
 
 +
<syntaxhighlight lang="cpp">
 
#include <Wire.h>
 
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
+
#include "Adafruit_TCS34725.h"
  
#define REPORTING_PERIOD_MS    1000
+
/* Example code for the Adafruit TCS34725 breakout library */
  
// PulseOximeter is the higher level interface to the sensor
+
/* Connect SCL    to analog 5
// it offers:
+
  Connect SDA    to analog 4
/* beat detection reporting
+
  Connect VDD    to 3.3V DC
//  * heart rate calculation
+
  Connect GROUND to common ground */
// * SpO2 (oxidation level) calculation
+
 
PulseOximeter pox;
+
/* Initialise with default values (int time = 2.4ms, gain = 1x) */
 +
// Adafruit_TCS34725 tcs = Adafruit_TCS34725();
  
uint32_t tsLastReport = 0;
+
/* Initialise with specific int time and gain values */
 +
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);
  
// Callback (registered below) fired when a pulse is detected
+
void setup(void) {
void onBeatDetected()
+
  Serial.begin(9600);
{
+
 
     Serial.println("Beat!");
+
  if (tcs.begin()) {
 +
    Serial.println("Found sensor");
 +
  } else {
 +
     Serial.println("No TCS34725 found ... check your connections");
 +
    while (1);
 +
  }
 +
 
 +
  // Now we're ready to get readings!
 
}
 
}
  
void setup()
+
void loop(void) {
{
+
  uint16_t r, g, b, c, colorTemp, lux;
    Serial.begin(115200);
+
 
 
+
  tcs.getRawData(&r, &g, &b, &c);
    Serial.print("Initializing pulse oximeter..");
+
  colorTemp = tcs.calculateColorTemperature(r, g, b);
 
+
  lux = tcs.calculateLux(r, g, b);
    // Initialize the PulseOximeter instance
+
 
    // Failures are generally due to an improper I2C wiring, missing power supply
+
  Serial.print("Color Temp: "); Serial.print(colorTemp, DEC); Serial.print(" K - ");
    // or wrong target chip
+
   Serial.print("Lux: "); Serial.print(lux, DEC); Serial.print(" - ");
    if (!pox.begin()) {
+
  Serial.print("R: "); Serial.print(r, DEC); Serial.print(" ");
        Serial.println("FAILED");
+
  Serial.print("G: "); Serial.print(g, DEC); Serial.print(" ");
        for(;;);
+
  Serial.print("B: "); Serial.print(b, DEC); Serial.print(" ");
    } else {
+
  Serial.print("C: "); Serial.print(c, DEC); Serial.print(" ");
        Serial.println("SUCCESS");
+
  Serial.println(" ");
    }
 
 
 
    // The default current for the IR LED is 50mA and it could be changed
 
    //   by uncommenting the following line. Check MAX30100_Registers.h for all the
 
    //  available options.
 
    // pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
 
 
 
    // Register a callback for the beat detection
 
    pox.setOnBeatDetectedCallback(onBeatDetected);
 
}
 
 
 
void loop()
 
{
 
    // Make sure to call update as fast as possible
 
    pox.update();
 
 
 
    // Asynchronously dump heart rate and oxidation levels to the serial
 
    // For both, a value of 0 means "invalid"
 
    if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
 
        Serial.print("Heart rate:");
 
        Serial.print(pox.getHeartRate());
 
        Serial.print("bpm / SpO2:");
 
        Serial.print(pox.getSpO2());
 
        Serial.print("% / temp:");
 
        Serial.print(pox.getTemperature());
 
        Serial.println("C");
 
 
 
        tsLastReport = millis();
 
    }
 
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Sau khi Upload thành công lên Arduino, hãy thử mở '''Serial Monitor''' (menu Tools) để xem kết quả.
+
Sau khi Upload thành công lên Arduino, hãy thử mở '''Serial Monitor''' (trong menu Tools) để xem kết quả.
  
 
* Serial Monitor
 
* Serial Monitor
[[Hình:module-cam-bien-nhip-tim-va-oxy-trong-mau-max30100-library-7.png|x400px]]
+
[[Hình:module-cam-bien-mau-sac-tcs34725-library-2.png|x400px]]
 
 
==== Thử với MAX30100_DrawData ====
 
 
 
Nội dung code mẫu
 
 
 
<syntaxhighlight lang="cpp" style="border-radius: 6px 6px 6px 6px;border: 1px dotted">
 
#include <Wire.h>
 
#include "MAX30100.h"
 
 
 
// Tweakable parameters
 
// Sampling and polling frequency must be set consistently
 
#define POLL_PERIOD_US                      1E06 / 100
 
#define SAMPLING_RATE                      MAX30100_SAMPRATE_100HZ
 
 
 
// The LEDs currents must be set to a level that avoids clipping and maximises the
 
// dynamic range
 
#define IR_LED_CURRENT                      MAX30100_LED_CURR_50MA
 
#define RED_LED_CURRENT                    MAX30100_LED_CURR_27_1MA
 
 
 
// The pulse width of the LEDs driving determines the resolution of
 
// the ADC (which is a Sigma-Delta).
 
// set HIGHRES_MODE to true only when setting PULSE_WIDTH to MAX30100_SPC_PW_1600US_16BITS
 
#define PULSE_WIDTH                        MAX30100_SPC_PW_1600US_16BITS
 
#define HIGHRES_MODE                        true
 
 
 
 
 
// Instantiate a MAX30100 sensor class
 
MAX30100 sensor;
 
uint32_t tsLastPollUs = 0;
 
 
 
void setup()
 
{
 
    Serial.begin(115200);
 
 
 
    Serial.print("Initializing MAX30100..");
 
 
 
    // Initialize the sensor
 
    // Failures are generally due to an improper I2C wiring, missing power supply
 
    // or wrong target chip
 
    if (!sensor.begin()) {
 
        Serial.println("FAILED");
 
        for(;;);
 
    } else {
 
        Serial.println("SUCCESS");
 
    }
 
 
 
    // Set up the wanted parameters
 
    sensor.setMode(MAX30100_MODE_SPO2_HR);
 
    sensor.setLedsCurrent(IR_LED_CURRENT, RED_LED_CURRENT);
 
    sensor.setLedsPulseWidth(PULSE_WIDTH);
 
    sensor.setSamplingRate(SAMPLING_RATE);
 
    sensor.setHighresModeEnabled(HIGHRES_MODE);
 
}
 
 
 
void loop()
 
{
 
    // Using this construct instead of a delay allows to account for the time
 
    // spent sending data thru the serial and tighten the timings with the sampling
 
    if (micros() < tsLastPollUs || micros() - tsLastPollUs > POLL_PERIOD_US) {
 
        sensor.update();
 
        tsLastPollUs = micros();
 
 
 
        Serial.print(sensor.rawIRValue);
 
        Serial.print('\t');
 
        Serial.println(sensor.rawRedValue);
 
    }
 
}
 
</syntaxhighlight>
 
 
 
Sau khi Upload thành công lên Arduino, hãy thử mở '''Serial Plotter''' (menu Tools) để xem kết quả.
 
 
 
* Serial Plotter
 
[[Hình:module-cam-bien-nhip-tim-va-oxy-trong-mau-max30100-library-6.png|x400px]]
 
  
 
=== Chú ý ===
 
=== Chú ý ===
 
* Cảm biến được tối ưu để đo chính xác nhất ở đầu ngón tay. Đặt đầu ngón tay lên cảm biến (che 2 LED trên cảm biến) khi đo.
 
* Khi cảm biến hoạt động, sẽ có một trong 2 LED trên cảm biến sáng màu đỏ.
 
  
 
== Tham khảo ==
 
== Tham khảo ==
  
* [https://github.com/oxullo/Arduino-MAX30100 Arduino-MAX30100 library]
+
* [https://learn.adafruit.com/adafruit-color-sensors?view=all Adafruit Color Sensors]
 +
* [https://github.com/adafruit/Adafruit_TCS34725 Arduino Library]
 +
* [http://download.chipfc.com/download.php?id=19&token=xBSVW1moRTAscPYIpFyKkgf2f5SZ1kYo TCS34725 Data Sheet]

Bản hiện tại lúc 11:58, ngày 2 tháng 3 năm 2018

Module-cam-bien-mau-sac-tcs34725-1.jpg

Giới thiệu

Module Cảm Biến Màu Sắc TCS34725 trên trang chủ

Thiết bị điện tử của bạn bây giờ có thể nhìn thấy màu sắc rực rỡ với module cảm biến nhỏ xíu đáng yêu này. Bạn sẽ thấy TCS34725 chính là cảm biến màu sắc tốt nhất trên thị trường, nó có thể nhận biết từng màu thành phần màu RGB và cường độ sáng trắng.

Module-cam-bien-mau-sac-tcs34725-top.jpg Module-cam-bien-mau-sac-tcs34725-bot.jpg

Thông số kỹ thuật

  • IC TCS34725
  • Điện áp hoạt động 3.3/5.0 VDC
  • Giao tiếp I2C
  • I2C address 0x29 (7-bit)
  • Khối lượng: 3.23g
  • Kích thước: 20.44mm / 0.8" x 20.28mm / 0.79"

Mô tả các chân kết nối

Module-cam-bien-mau-sac-tcs34725-pinout.jpg

Thứ tự chân Ký hiệu Loại Mô tả
1 VIN Power Nguồn cấp 3.6-5.5V
2 GND Power Điện áp đất 0V
3 3V3 Power Điện áp nguồn 3.3V
4 SCL Input I2C SCL
5 SDA I/O I2C SDA
6 INT Input Chân INT của TCS34725
7 LED Input Bật/Tắt LED

Sử dụng với Arduino

Kết nối module với Arduino

Kết nối cơ bản giữa module TCS34725 và Arduino như hình bên dưới.

Chú ý: nếu điện áp cấp nguồn là 3.3V thì cấp vào chân 3V3 thay vì VIN.

Module-cam-bien-mau-sac-tcs34725-connect-arduino.png

Tải thư viện

Dùng thư viện Adafruit_TCS34725 Arduino library được phát triển bởi Adafruit

Nếu bạn chưa biết cách sử dụng một thư viện Arduino có thể xem hướng dẫn tại Thư viện Arduino

Sử dụng ví dụ mẫu

Sau khi cài đặt thành công thư viện Adafruit_TCS34725, Arduino IDE sẽ xuất hiện mục Adafruit TCS34725.

Với các Example được viết sẵn là:

  • colorview: Đọc giá trị màu sắc và hiển thị ra LED RGB.
  • tcs34725: Đọc giá trị màu sắc và hiển thị ra Serial.
  • tcs34725autorange: Một thử nghiệm thực hiện việc cải thiện độ sáng lux và nhiệt độ màu.

Module-cam-bien-mau-sac-tcs34725-library-1.png

Thử với tcs34725

Nội dung code mẫu:

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

/* Example code for the Adafruit TCS34725 breakout library */

/* Connect SCL    to analog 5
   Connect SDA    to analog 4
   Connect VDD    to 3.3V DC
   Connect GROUND to common ground */
   
/* Initialise with default values (int time = 2.4ms, gain = 1x) */
// Adafruit_TCS34725 tcs = Adafruit_TCS34725();

/* Initialise with specific int time and gain values */
Adafruit_TCS34725 tcs = Adafruit_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 ... check your connections");
    while (1);
  }
  
  // Now we're ready to get readings!
}

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(" ");
}

Sau khi Upload thành công lên Arduino, hãy thử mở Serial Monitor (trong menu Tools) để xem kết quả.

  • Serial Monitor

x400px

Chú ý

Tham khảo