pdf-icon

Arduino入門

2. デバイス&サンプル

Unit Mini TVOC/eCO2 Arduino ユーザーガイド

1. 準備作業

ドライバライブラリ
M5Unit-ENV ライブラリには、Unit Mini TVOC/eCO2 センサー用のドライバとサンプルが含まれており、センサーのデータ読み取りが非常に簡単に行えます。

依存ライブラリ
上記のドライバライブラリ(M5UnitUnifiedM5Unit-ENV など)は、他の依存ライブラリ(例: M5HALM5Utility など)を必要とします。Arduino ライブラリマネージャを使用してインストールする場合は、表示される指示に従ってすべての依存ライブラリをインストールしてください。

2. サンプルプログラム

サンプル説明
このサンプルでは、Unit Mini TVOC/eCO2 を用いて TVOC (総揮発性有機化合物) と eCO2 (二酸化炭素相当) の濃度を測定します。
cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
#include <M5Unified.h>
#include <M5UnitUnified.h>
#include <M5UnitUnifiedENV.h>
auto& lcd = M5.Display;
m5::unit::UnitUnified Units;
m5::unit::UnitTVOC unit;
void setup()
{
M5.begin();
M5.Display.setFont(&fonts::lgfxJapanMinchoP_20);
M5.Display.setTextSize(1);
auto pin_num_sda = M5.getPin(m5::pin_name_t::port_a_sda);
auto pin_num_scl = M5.getPin(m5::pin_name_t::port_a_scl);
M5_LOGI("getPin: SDA:%u SCL:%u", pin_num_sda, pin_num_scl);
Wire.begin(pin_num_sda, pin_num_scl, 400 * 1000U);
if (!Units.add(unit, Wire) || !Units.begin()) {
M5_LOGE("Failed to begin");
M5.Display.clear(TFT_RED);
while (true) {
m5::utility::delay(10000);
}
}
M5_LOGI("M5UnitUnified has been begun");
M5_LOGI("%s", Units.debugInfo().c_str());
M5_LOGW("SGP30 measurement starts 15 seconds after begin");
M5.Display.setCursor(0, 0);
M5.Display.clear();
M5.Display.println("Init...");
}
void loop()
{
M5.update();
Units.update();
if (unit.updated()) {
M5.Display.setCursor(0, 0);
M5.Display.clear();
M5.Display.printf("\n>CO2eq:%u\n>TVOC:%u", unit.co2eq(), unit.tvoc());
}
}

3. コンパイルとアップロード

    1. ダウンロードモード: 各デバイスはプログラム書き込み前にダウンロードモードに入る必要があり、この手順は主制御デバイスによって異なる場合があります。詳細は Arduino IDE 入門チュートリアル ページ下部のデバイスプログラム書き込みチュートリアル一覧を参照し、具体的な操作方法をご確認ください。
  • CoreS3 の場合、リセットボタンを約2秒間長押しし、内部の緑色LEDが点灯するまで押し続けた後、ボタンを離すとデバイスがダウンロードモードに入り、書き込み待ち状態となります。
    1. デバイスポートを選択し、Arduino IDE の左上にあるコンパイル&アップロードボタンをクリックして、プログラムがコンパイルされデバイスにアップロードされるのを待ちます。

4. TVOC/eCO2 測定

On This Page
1. 準備作業
2. サンプルプログラム
3. コンパイルとアップロード
4. TVOC/eCO2 測定
Q&A
Submit a question
Select question category*
Arduino
MicroPython
UIFlow1
UIFlow2
EzData
M5Burner
Software
Hardware
Other
Product name
Product version
Question description*
(Supports pasting screenshots.)
Attachments
Add Files
Email*
Submit
OK

M5Stack Support

Hi, this is M5Stack Support. How can I help you today?