Skip to content

Instantly share code, notes, and snippets.

@shoarai
Last active July 18, 2021 06:59
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/a1c14238e4856c840886e40828e65928 to your computer and use it in GitHub Desktop.
Save shoarai/a1c14238e4856c840886e40828e65928 to your computer and use it in GitHub Desktop.
#include <M5StickCPlus.h>
#include <MHZ19_uart.h>
// Ambientライブラリをインクルードする。
#include "Ambient.h"
const int rx_pin = 36;
const int tx_pin = 26;
// WiFiアクセスポイントのSSIDとパスワードを設定する。
const char* ssid = "...";
const char* password = "...";
// Ambientで作ったチャネルのチャネルIDとライトキーを設定する。
unsigned int channelId = ...;
const char* writeKey = "...";
MHZ19_uart mhz19;
// WiFiとAmbientの変数を宣言する。
WiFiClient client;
Ambient ambient;
void setup()
{
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);
// Wi-Fiアクセスポイントに接続する。
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
}
M5.Lcd.println("WiFi connected.");
// Ambientを初期化する。
ambient.begin(channelId, writeKey, &client);
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);
// 測定値をAmbientに送信する。
ambient.set(1, co2ppm);
ambient.set(2, temp);
ambient.send();
delay(5000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment