Arduinoの覚書

自分の備忘録です。Arduino以外もあります。

ATOM Lite 3.温湿度&気圧測定


 温湿度と気圧を測定しPC上に表示。ENV2センサを接続して10秒ごとにPC上のシリアルモニタに測定値を表示します。

必要なもの

  • ATOM Lite (スイッチサイエンス) 968円

   https://www.switch-science.com/catalog/6262/

  • M5Stack用環境センサENV2 (スイッチサイエンス) 572円

   https://www.switch-science.com/catalog/6344/

  • USB Type-C 充電&通信ケーブル 1m 2A (ダイソー) 110円

センサENV2について

  • 温度:(0~40)±0.2℃ (SHT30)
  • 湿度:(10~90)±2% (SHT30)
  • 気圧:(300~1100)±1hPa (BMP280)
  • I2C通信プロトコル:SHT30(0x44), BMP280(0x76)
  • GROVE互換インターフェース

 ボード設定

前回と同様に。ただしENV2の設定はM5Stackで使用したことがあるとして略します。

  1. PCとATOM LiteをUSBケーブルで接続
  2. Arduino IDE > ツール > ボード > ESP32 Arudino > ESP32 Pico Kit
  3. Arduino IDE > ツール > Upload Speed=921600→115200
  4. Arduino IDE > ツール > シリアルポート > ATOM Liteがつながっているポート番号を選択

実行

  1. 下記ファイルを開く
  2. Arduino IDE > スケッチ > マイコンボードに書き込む
  3. 動作開始前に
  4. Arduino IDE > ツール > シリアルモニタ
  5. シリアルモニタの表示は「22.3'C 46% 1025hPa」(例)となる。

スケッチ

// SHT30  温湿度センサ 精度±0.2℃, ±2%
// BMP280 気圧センサ   精度±1hPa
// シリアルモニタに測定値を表示 10秒ごとに
#include "M5Atom.h"           // ATOMを使用
#include <Adafruit_SHT31.h>  // 温湿度センサを使用
#include <Adafruit_BMP280.h>  // 気圧センサを使用
Adafruit_SHT31  sht = Adafruit_SHT31(&Wire);
Adafruit_BMP280 bme = Adafruit_BMP280(&Wire);
float tmp = 0.0;              // 温度変数 浮動小数点
float hum = 0.0;              // 湿度変数 浮動小数点
float pre = 0.0;              // 気圧変数 浮動小数点

void setup() {
  M5.begin(true, false, true);
                  // (LCD,PowerEnable=true,Serial)
  Wire.begin(26,32);   // I2C通信でG26とG32信号を使用
  while (!bme.begin(0x76)) {  // BMP280を初期化できなければ
                              // (スレーブアドレス)
    Serial.println("not find BMP280");
  }
  while (!sht.begin(0x44)) {  // SHT30を初期化できなければ
    Serial.println("not find SHT30");
  }
}

void loop() {
  pre = bme.readPressure();     // センサーの圧力を読む
  tmp = sht.readTemperature();  // センサーの温度を読む
  hum = sht.readHumidity();     // センサーの湿度を読む
  Serial.printf("%4.1f'C%3.0f%%%5.0fhPa\r\n", tmp, hum, pre / 100);
  // 温度00.0'C, 湿度000%, 気圧00000hPaをシリアルモニタに表示
  delay(10000);                 // 10秒待つ
}




以上