結論から言うと,dhtモジュールでDHT22の1-Wireモードとして扱えば読み取れます.
接続方法
AM2320 | ESP32 |
---|---|
1: VDD | 3V3 |
2: SDA | 任意のIOピン+プルアップ(3V3と~10kΩ抵抗で接続) |
3: GND | GND |
4: SCL | GND |
読み取り
>>> 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でゴリゴリ書かなくて済んだ.