LoginSignup
0
0

M5StickC Plus で温湿度センサ DHT20 を使う(おそらくM5StickCやM5Stickも)

Last updated at Posted at 2023-11-03

はじめに

  • VSCode と拡張機能の PlatformIO を使って実装しました
  • M5StickCPlusで動作確認しています

ライブラリ

zipファイルはこちらにあります
https://github.com/multifeb13/M5StickCPlus_DHT20/releases

ライブラリのコピー場所

PlatformIO

プロジェクト内 lib フォルダ内に DHT20 フォルダと、その中に DHT20.cpp, DHT20.hpp をコピーしてください
lib_path_platformIO.png

サンプルコード

main.cpp
#include <M5StickCPlus.h>
#include <Wire.h>

#include "DHT20.hpp"

TFT_eSprite sprite(&M5.Lcd);
DHT20 dht20(32, 33);

void setup() {
  M5.begin();

  M5.Lcd.setRotation(1);
  sprite.createSprite(M5.Lcd.width(), M5.Lcd.height());
}

void loop() {
  delay(500);

  float tp;
  float hu;
  dht20.read(tp, hu);

  sprite.fillScreen(BLACK);
  sprite.drawString("T=" + String(tp) + "'C", 0, 30, 4);
  sprite.drawString("H=" + String(hu) + "%", 0, 60, 4);
  sprite.pushSprite(0, 0);
}

M5StickC / M5Stack対応

M5StickC および M5Stackの実機を持っていないのでイマジナリーなコードを書きます。
実機をお持ちの方はコメントで情報をいただけると嬉しいです

M5StickC

  1. include変更
#include <M5StickCPlus.h>

#include <M5StickC.h>

で動くのではないかと

M5Stick

  • include変更
#include <M5Stack.h>

#include <M5Stack.h>
  • 初期化変更
DHT20 dht20(32, 33);

DHT20 dht20();

で動くのではないかと

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