次のページを参考にしました。
Grove - Temperature&Humidity Sensor Pro(DHT22)
必要なライブラリーのインストール
curl -sL https://github.com/Seeed-Studio/grove.py/raw/master/install.sh | sudo bash -s -
プログラム
dht_simpleread.py
#! /usr/bin/python3
import time
import seeed_dht
sensor = seeed_dht.DHT("22", 16)
while True:
humi, temp = sensor.read()
if not humi is None:
print('DHT{0}, humidity {1:.1f}%, temperature {2:.1f}*'.format(s
ensor.dht_type, humi, temp))
else:
print('DHT{0}, humidity & temperature: {1}'.format(sensor.dht_ty
pe, temp))
time.sleep(2)
#
実行結果
$ ./dht_simpleread.py
DHT22, humidity 68.3%, temperature 26.6*
DHT22, humidity 68.3%, temperature 26.6*
DHT22, humidity 70.1%, temperature 26.6*
DHT22, humidity 83.5%, temperature 26.8*
DHT22, humidity 85.0%, temperature 26.8*
DHT22, humidity 89.1%, temperature 27.0*
DHT22, humidity 88.6%, temperature 27.1*
DHT22, humidity 77.7%, temperature 27.2*
DHT22, humidity 76.6%, temperature 27.3*