2
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 5 years have passed since last update.

M5Stackでオムロンの絶対圧センサー2SMPB-02Eの圧をAmbientに送信

Posted at

とあるイベントでオムロンの絶対圧センサー 2SMPB-02E をいただいたので、使ってみました。
平成のうちに記事化出来ずにすみません。

58441871_2403755849910866_8302220221809164288_n.jpg

オムロン 絶対圧センサー 2SMPB-02E

データシートはこちら
製品ページ 2SMPB-02E MEMS絶対圧センサ

M5Stack用のライブラリ
2SMPB-02EにはGroveコネクタが着いた評価モジュールがあり、そのためのライブラリもgithubで公開されています。
ですので、それをそのまま利用すれば簡単に温度と圧が取得出来ます。
https://github.com/omron-devhub/2smpb02e-grove-m5stack

参考記事

基本的な接続方法や使用方法は既出の記事をご参照ください。
M5Stackで使おう オムロン 絶対圧センサ評価モジュール 2SMPB-02E

Ambientでロギング

サンプルはM5のLCDに表示するかたちになっていたので、同じデータをAmbientに送信してグラフ表示するように変更しました。

M5Stack_Omron_Pressure_Sample.ino
# include <driver/dac.h>
# include <M5Stack.h>
# include "Omron2SMPB02E.h"
# include <WiFi.h>
# include <esp_wifi.h>
# include "Ambient.h"
# include "config.h"

WiFiClient client;
Ambient ambient;
Omron2SMPB02E prs;

# define PERIOD 5 * 60
# define JST 3600* 9
# define DELAY_CONNECTION 100

void setupWiFi(void)
{
    int ret, i;
    while ((ret = WiFi.status()) != WL_CONNECTED) {
        Serial.printf("> stat: %02x", ret);
        ret = WiFi.begin(ssid, password);  //  Wi-Fi APに接続
        i = 0;
        while ((ret = WiFi.status()) != WL_CONNECTED) {  //  Wi-Fi AP接続待ち
            delay(DELAY_CONNECTION);
            if ((++i % (1000 / DELAY_CONNECTION)) == 0) {
                Serial.printf(" >stat: %02x", ret);
            }
            if (i > 10 * 1000 / DELAY_CONNECTION) { // 10秒経過してもDISCONNECTEDのままなら、再度begin()
                break;
            }
        }
    }
    Serial.println("WiFi connected\r\nIP address: ");
    Serial.println(WiFi.localIP());
}

void setupAmbient(void)
{
  ambient.begin(channelId, writeKey, &client); // チャネルIDとライトキーを指定してAmbientの初期化
}

void setupPrs(void)
{
  prs.begin();
  prs.set_mode(MODE_NORMAL);
}

void setup()
{
  M5.begin();
  dac_output_disable(DAC_CHANNEL_1);
  Serial.begin(115200);
  setupPrs();
  setupWiFi();
  setupAmbient();
  delay(300);
}

void loop()
{
  delay(2000);
  float temp = prs.read_temp();
  float pressure = prs.read_pressure();
  M5.Lcd.fillScreen(BLACK);
  M5.Lcd.setCursor(0, 0);
  M5.Lcd.setTextSize(2);
  M5.Lcd.printf("Temperature:\r\n%f[degC]\r\n\r\n", temp);
  M5.Lcd.printf("Pressure:\r\n%f[Pa]\r\n", pressure);

  ambient.set(1, String(temp).c_str());
  ambient.set(2, String(pressure).c_str());
  ambient.send();
}

別に config.hでWifiパスワードとAmbentのチャネル、WriteKeyを設定してください。

config.h
const char* ssid = "XXXXXXXXXXXXXXXXXX";
const char* password = "YYYYYYYY";

unsigned int channelId = 999999; // AmbientのチャネルID
const char* writeKey = "aaaaaaaaaaaaaaaa"; // ライトキー

実験結果

建物の屋内で1Fと3F(地上から約10m)で圧を測ってみました。

11:40 - 12:30 : 3F
12:30 - 15:00 : 1F

結果の10分の平均値をプロットしたのがこのグラフです。
image.png

1Fに移動した12:30頃に気圧が変化しているかというと、その前に徐々に変化している影響の方が大きそうです。
ローパスフィルタをかけなくても長時間の結果を見れば傾向がみてとれるかと思ったのですが、それ以上に天候の影響の方が大きそうです。(この日は曇りのち雨でした。)

感想

絶対圧センサーはライブラリが用意されているので、温度と絶対圧はすぐに表示して確認は出来ます。
ただ、使ってみた感想としては単体だけでは外乱の影響の方が大きく、それなりの高さの気圧の差でないと比較は厳しそうです。
もしくは、センサーを2つ用意して、片側は1Fに常に固定するなどして、差分を見てもう片方のセンサーがあるデバイスの高さを推定するといった使い方が良さそうです。

2
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
2
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?