连接正负极及gpio引脚
sudo apt-get update
sudo apt-get install build-essential python-dev
git clone git@github.com:adafruit/Adafruit_Python_DHT.git
sudo python setup.py install
vim /home/pi/pydht11.py
import Adafruit_DHT as dht
import sys
pin = int(sys.argv[1])
sensor = dht.DHT11
humidity, temperature = dht.read_retry(sensor, pin)
if humidity is not None and temperature is not None:
print '{0:d} {1:0.1f} c {2:0.1f} %'.format(0,temperature, humidity)
else:
print '{0:d} {1:d} c {2:d} %'.format(3,0,0)
$ python /home/pi/pydht11.py 26
成功打印0 20.0 c 46.0 %
运行正常,然后就可以通过homebridge显示在Home 应用上。
标签: 树莓派
发表评论 登录: