0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

M5Stack: 環境センサーから計測値を取得する

Last updated at Posted at 2023-01-28

M5Stack で、各種環境センサーから計測値を取得する方法を整理しました。

使用したセンサーは以下のものです。

これらのセンサーは I2C ポート(Port.A) に接続する必要があります。I2C 拡張ハブユニット を使用することで、複数のセンサーを併用することもできます。

ENV III: 温湿度センサー (SHT30) / 気圧センサー (QMP6988)

ENV III に実装されている SHT30 から温度・湿度、QMP6988 から気圧を取得します。SHT30 は M5Paper では内蔵されています。(本体内部にあるので外気温の計測には適さないと思いますが。)

使用したライブラリ

実装例

#include <SHT3X.h>

void getSHT30()
{
  SHT3X sht30;
  if (sht30.get() != 0) return;
  float temp = sht30.cTemp; // 温度 (℃)
  float humidity = sht30.humidity; // 湿度 (%)
}

void getQMP6988()
{
  QMP6988 qmp6988;
  if (!qmp6988.init()) return;
  float pressure = qmp6988.calcPressure() / 100; // 気圧 (hPa)
}

ENV II: 気圧センサー (BMP280)

ENV II に実装されている BMP280 から、温度・気圧を取得します。SHT30 は ENV III と同様です。

使用したライブラリ

実装例

#include <Adafruit_BMP280.h>
#include <Adafruit_Sensor.h>

void getBMP280()
{
  Adafruit_BMP280 bme;
  if (!bme.begin(0x76)) return;
  float temp = bme.readTemperature(); // 気温 (℃)
  float pressure = bme.readPressure() / 100; // 気圧 (hPa)
}

ガスセンサー (SGP30)

SGP30 から、値を取得します。

使用したライブラリ

実装例

#include <Adafruit_SGP30.h>
#include <Adafruit_Sensor.h>

void getSGP30()
{
  Adafruit_SGP30 sgp;
  gpe.begin();
  if (!gpe.IAQmeasure()) return;
  float tvoc = sgp.TVOC; // TVOC (Total Volatile Organic) : 総揮発性有機化合物量 (ppb = 0.000000001%)
  float eCO2 = sgp.eCO2; // 二酸化炭素濃度 (ppm = 0.000001%)
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?