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
Dòng 50: Dòng 50:
 
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 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.
  
[[Hình:mmodule-cam-bien-mau-sac-tcs34725-connect-arduino.png|x300px]]
+
[[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 60:
 
=== 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à:
Dòng 68: Dòng 68:
 
* '''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 đề.
 
* '''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]]
+
[[Hình:module-cam-bien-mau-sac-tcs34725-library-1.png|600px]]
  
==== Thử với MAX30100_Minimal ====
+
==== Thử với ====
  
 
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" style="border-radius: 6px 6px 6px 6px;border: 1px dotted">
#include <Wire.h>
+
//
#include "MAX30100_PulseOximeter.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..");
 
 
 
    // Initialize the PulseOximeter instance
 
    // Failures are generally due to an improper I2C wiring, missing power supply
 
    // or wrong target chip
 
    if (!pox.begin()) {
 
        Serial.println("FAILED");
 
        for(;;);
 
    } else {
 
        Serial.println("SUCCESS");
 
    }
 
 
 
    // 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-7.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]

Phiên bản lúc 00:44, ngày 31 tháng 10 năm 2017

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: 1.8 - 5.5 VDC (khuyên dùng 5V)
  • Giao tiếp I2C, mức TTL
  • 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

x200px

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)
2 SCL Input I2C SCL
3 SDA I/O I2C SDA
4 INT Output Chân INT của MAX30100
5 IRD Chân IR_DRV của MAX30100
6 RD Chân R_DRV của MAX30100
7 GND Power Điện áp đất 0V

Sử dụng 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.

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à:

  • 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 đề.

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

Thử với

Nội dung code mẫu

//

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