4
1

More than 5 years have passed since last update.

ESP32+MicroPythonで温湿度センサAM2320を扱う

Last updated at Posted at 2018-02-03

結論から言うと,dhtモジュールでDHT22の1-Wireモードとして扱えば読み取れます.

接続方法

AM2320 ESP32
1: VDD 3V3
2: SDA 任意のIOピン+プルアップ(3V3と~10kΩ抵抗で接続)
3: GND GND
4: SCL GND

esp32_am2320.jpg

読み取り

>>> import machine,dht
>>> d = dht.DHT22(machine.Pin(21))
>>> d.measure()
>>> d.temperature()
24.7
>>> d.humidity()
52.4

なお,プルアップ出来ていない等で通信に失敗すると下記のようにタイムアウトエラーになります.

>>> d.measure()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "dht.py", line 16, in measure
OSError: [Errno 110] ETIMEDOUT

参考

AM2320の操作例を探していたところ,上記チュートリアルにAM2320のピン説明が載っていて,もしやと思って試したらあっさり読めました.I2Cでゴリゴリ書かなくて済んだ.

4
1
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
4
1