UNIT_TVOC「TVOC/eCO2 ガスセンサユニット(SGP30)」を動かす
2021/12/30
初版
UNIT_TVOC
UNIT_TVOC
概要
UNIT_TVOC「TVOC/eCO2 ガスセンサユニット(SGP30)」を動かす。
ソースは共通になっており、ターゲットのM5StickCPlus,M5Core2をplatformio.iniの内容で切り替えてビルドする。
ソース
src/main.ino
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core2 sample source code
* 配套 M5Core2 示例源代码
* Visit the website for more information:https://docs.m5stack.com/en/unit/tvoc
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/unit/tvoc
*
* describe: TVOC/eCO2.
* date:2021/8/26
*******************************************************************************
Description: The screen will display TVOC and CO2. 屏幕将显示TVOC和CO2。
Note: SGP30 needs 15 seconds to initialize calibration after power on. SGP30开机后需要15秒进行初始校准。
*/
#ifdef M5C2
#include <M5Core2.h>
#endif
#ifdef M5STICK_CP
#include <M5StickCPlus.h>
#endif
#include "Adafruit_SGP30.h"
Adafruit_SGP30 sgp;
long last_millis = 0;
void setup() {
#ifdef M5C2
M5.begin(true, false, true, true);
M5.Lcd.setTextSize(2);
M5.Lcd.setCursor(80,0);
M5.Lcd.println("TVOC TEST");
#endif
#ifdef M5STICK_CP
M5.begin();
M5.Axp.ScreenBreath(12);
M5.Lcd.setRotation(3);
M5.lcd.setTextSize(2);
M5.Lcd.setCursor(0,0);
M5.Lcd.println("TVOC TEST");
#endif
if (!sgp.begin()){ //Init the sensor. 初始化传感器
M5.Lcd.println("Sensor not found");
while (1);
}
#ifdef M5C2
M5.Lcd.setCursor(0,80);
M5.Lcd.println("\nInitialization...");
#endif
#ifdef M5STICK_CP
M5.Lcd.setCursor(10,0);
M5.Lcd.println("\nInitialization...");
#endif
}
void loop() {
static int i = 15;
while(i > 0) {
if(millis()- last_millis > 1000) {
last_millis = millis();
i--;
#ifdef M5C2
M5.Lcd.fillRect(20, 120, 60, 30, BLACK);
M5.Lcd.drawNumber(i, 20, 120, 2);
#endif
#ifdef M5STICK_CP
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setCursor(10,0);
M5.Lcd.println("\nInitialization...");
//M5.Lcd.fillRect(10, 60, 30, 15, BLACK);
M5.Lcd.drawNumber(i, 10, 60, 2);
#endif
}
}
#ifdef M5C2
M5.Lcd.fillRect(0, 80, 90, 100, BLACK);
#endif
#ifdef M5STICK_CP
M5.Lcd.fillScreen(BLACK);
//M5.Lcd.fillRect(0, 40, 45, 50, BLACK);
#endif
if (! sgp.IAQmeasure()) { //Commands the sensor to take a single eCO2/VOC measurement. 命令传感器进行一次eCO2/VOC测量
Serial.println("Measurement failed");
return;
}
#ifdef M5C2
M5.Lcd.fillRect(100, 40, 220, 90, TFT_BLACK);
M5.Lcd.setCursor(0,50);
M5.Lcd.printf("TVOC:%d ppb\n",sgp.TVOC);
M5.Lcd.printf("eCO2:%d ppm\n",sgp.eCO2);
#endif
#ifdef M5STICK_CP
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setCursor(0,0);
M5.Lcd.printf("TVOC TEST");
M5.Lcd.setCursor(0,30);
M5.Lcd.printf("TVOC:%d ppb\n",sgp.TVOC);
M5.Lcd.printf("eCO2:%d ppm\n",sgp.eCO2);
#endif
delay(500);
}
platformio.ini
M5Core2用
[env:m5core2]
platform = espressif32
board = m5stack-core2
framework = arduino
upload_speed = 2000000
monitor_speed = 115200
board_build.partitions = default_16MB.csv
build_flags =
-DM5C2
-DCORE_DEBUG_LEVEL=4
-DBOARD_HAS_PSRAM
-mfix-esp32-psram-cache-issue
lib_deps =
https://github.com/m5stack/M5Core2.git
https://github.com/FastLED/FastLED
;https://github.com/m5stack/M5Core2/blob/master/examples/core2_for_aws/ArduinoECCX08.zip
lovyan03/LovyanGFX
adafruit/Adafruit BMP280 Library @ ^2.5.0
adafruit/Adafruit Unified Sensor @ ^1.1.4
m5stack/UNIT_ENV @ ^0.0.2
adafruit/Adafruit SGP30 Sensor @ ~2.0.0
lib_ldf_mode = deep+
M5StickCPlus用
[env:M5StickCPlus]
platform = espressif32
board = m5stick-c
framework = arduino
build_flags = -DM5STICK_CP
monitor_speed = 115200
lib_ldf_mode = deep+
lib_deps =
m5stack/M5StickCPlus @ ^0.0.5
tinyu-zhao/FFT @ ^0.0.1
m5stack/UNIT_ENV @ ^0.0.2
adafruit/Adafruit BMP280 Library @ ^2.5.0
adafruit/Adafruit Unified Sensor @ ^1.1.4
adafruit/Adafruit SGP30 Sensor @ ^2.0.0
動作
TVOC(総揮発性有機化合物)とeCO2(二酸化炭素相当量)濃度を測定し LCDに表示する。
参考情報
terminal関連:
Bootterm – a developer-friendly serial terminal program
platformio関連:
arduinoフレームワーク用platformio.ini集
Building Core2 FactoryDemo in PlatformIO
VSCodeとPlatformIOでM5Stack Core2開発
M5Stack Core2とVSCode + PlatformIOとでM5Stackプログラミングを始めてみた。
Arduino-IDE関連:
Arduino IDE environment - M5Paper
Arduino IDEのインストールと設定 (Windows, Mac, Linux対応)
M5Stackファミリ関連:
M5Core2 Arduino Install
M5Paper Arduino Install
M5CoreInk Arduino Install
M5Stamp-PICO Arduino Install
M5Stamp-C3 Arduino Install
Wio-Terminal/ESP8622/ESP32ボードを共通のスケッチで動かす(NTP-CLIENT編)
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(STARWARS編)
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(MQTT編)
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(REST-API編)
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(OSC編)
以上
| 固定リンク
「PlatformIO」カテゴリの記事
- NuEVI/NuRADのビルド(2022.08.18)
- Wio_ExtFlashLoad(WriteSampleMenu.ino)スケッチをplatformioでビルドする(2022.02.03)
- uncannyeyesスケッチをplatformioでビルドする(2022.01.31)
- LovyanGFX-Display ライブラリを使用したスケッチをplatformioでビルドする(2022.01.30)
- Wio-Terminal/M5Core2のWiFiAnallyzer(2022.01.24)
この記事へのコメントは終了しました。


コメント