Skip to content

Instantly share code, notes, and snippets.

@shoarai
Created July 17, 2021 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shoarai/a98cf027914d43139f4dbe579f726b8b to your computer and use it in GitHub Desktop.
Save shoarai/a98cf027914d43139f4dbe579f726b8b to your computer and use it in GitHub Desktop.
// 追記:M5StickC Plusで必要なヘッダをインクルードする。
#include <M5StickCPlus.h>
#include <MHZ19_uart.h>
// 変更:接続するピンの番号を変更する。
const int rx_pin = 36;
const int tx_pin = 26;
MHZ19_uart mhz19;
void setup()
{
// 追記:M5StickC Plusの初期化と、G36ピンを使うためにG25ピンをフローティングにする。
M5.begin();
pinMode(36, INPUT);
gpio_pulldown_dis(GPIO_NUM_25);
gpio_pullup_dis(GPIO_NUM_25);
Serial.begin(9600);
mhz19.begin(rx_pin, tx_pin);
mhz19.setAutoCalibration(false);
// 追記:デフォルトだと画面が見づらいので、横向き表示でフォントを大きくする。
M5.Lcd.setRotation(3);
M5.Lcd.setTextSize(4);
// 変更:文字を画面に表示する。
M5.Lcd.println("MH-Z19 is warming up now.");
delay(10 * 1000);
}
void loop()
{
int co2ppm = mhz19.getCO2PPM();
int temp = mhz19.getTemperature();
// 追記:画面の表示とカーソルを初期化することで、前回の文字の表示を消す。
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setCursor(0, 0);
// 変更:文字を画面に表示する。
M5.Lcd.print("co2: ");
M5.Lcd.println(co2ppm);
M5.Lcd.print("temp: ");
M5.Lcd.println(temp);
delay(5000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment