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
(Thử với tcs34725)
 
(Không hiển thị 9 phiên bản của cùng người dùng ở giữa)
Dòng 14: Dòng 14:
 
=== Thông số kỹ thuật ===
 
=== Thông số kỹ thuật ===
  
* IC: TCS34725
+
* 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
 
* I2C address 0x29 (7-bit)
 
* I2C address 0x29 (7-bit)
 
* Khối lượng: 3.23g
 
* Khối lượng: 3.23g
Dòng 23: Dòng 23:
 
== 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-mau-sac-tcs34725-pinout.png|x200px]]
+
[[Hình:module-cam-bien-mau-sac-tcs34725-pinout.jpg|x200px]]
  
 
{| class="wikitable sortable"
 
{| class="wikitable sortable"
Dòng 29: 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 48: 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:mmodule-cam-bien-mau-sac-tcs34725-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 60: 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.
 +
 
 +
[[Hình:module-cam-bien-mau-sac-tcs34725-library-1.png|600px]]
  
==== Thử với MAX30100_Minimal ====
+
==== Thử với tcs34725 ====
  
Nội dung code mẫu
+
Nội dung code mẫu:
  
<syntaxhighlight lang="cpp" style="border-radius: 6px 6px 6px 6px;border: 1px dotted">
+
<syntaxhighlight lang="cpp">
 
#include <Wire.h>
 
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
+
#include "Adafruit_TCS34725.h"
 
 
#define REPORTING_PERIOD_MS    1000
 
 
 
// PulseOximeter is the higher level interface to the sensor
 
// it offers:
 
//  * beat detection reporting
 
//  * heart rate calculation
 
//  * SpO2 (oxidation level) calculation
 
PulseOximeter pox;
 
 
 
uint32_t tsLastReport = 0;
 
 
 
// Callback (registered below) fired when a pulse is detected
 
void onBeatDetected()
 
{
 
    Serial.println("Beat!");
 
}
 
 
 
void setup()
 
{
 
    Serial.begin(115200);
 
  
    Serial.print("Initializing pulse oximeter..");
+
/* Example code for the Adafruit TCS34725 breakout library */
  
    // Initialize the PulseOximeter instance
+
/* Connect SCL    to analog 5
    // Failures are generally due to an improper I2C wiring, missing power supply
+
  Connect SDA    to analog 4
    // or wrong target chip
+
  Connect VDD    to 3.3V DC
    if (!pox.begin()) {
+
  Connect GROUND to common ground */
        Serial.println("FAILED");
+
 
        for(;;);
+
/* Initialise with default values (int time = 2.4ms, gain = 1x) */
    } else {
+
// Adafruit_TCS34725 tcs = Adafruit_TCS34725();
        Serial.println("SUCCESS");
 
    }
 
  
    // The default current for the IR LED is 50mA and it could be changed
+
/* Initialise with specific int time and gain values */
    //  by uncommenting the following line. Check MAX30100_Registers.h for all the
+
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);
    //   available options.
 
    // pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
 
  
     // Register a callback for the beat detection
+
void setup(void) {
     pox.setOnBeatDetectedCallback(onBeatDetected);
+
  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 loop(void) {
{
+
  uint16_t r, g, b, c, colorTemp, lux;
    // Make sure to call update as fast as possible
+
 
    pox.update();
+
  tcs.getRawData(&r, &g, &b, &c);
 
+
  colorTemp = tcs.calculateColorTemperature(r, g, b);
    // Asynchronously dump heart rate and oxidation levels to the serial
+
  lux = tcs.calculateLux(r, g, b);
    // For both, a value of 0 means "invalid"
+
 
    if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
+
  Serial.print("Color Temp: "); Serial.print(colorTemp, DEC); Serial.print(" K - ");
        Serial.print("Heart rate:");
+
  Serial.print("Lux: "); Serial.print(lux, DEC); Serial.print(" - ");
        Serial.print(pox.getHeartRate());
+
  Serial.print("R: "); Serial.print(r, DEC); Serial.print(" ");
        Serial.print("bpm / SpO2:");
+
  Serial.print("G: "); Serial.print(g, DEC); Serial.print(" ");
        Serial.print(pox.getSpO2());
+
  Serial.print("B: "); Serial.print(b, DEC); Serial.print(" ");
        Serial.print("% / temp:");
+
  Serial.print("C: "); Serial.print(c, DEC); Serial.print(" ");
        Serial.print(pox.getTemperature());
+
  Serial.println(" ");
        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