Adafruit_Python_DHT

https://github.com/adafruit/Adafruit_Python_DHT

一、安装库

sudo apt-get update

sudo apt-get install build-essential python-dev

git clone https://github.com/adafruit/Adafruit_Python_DHT

cd Adafruit_Python_DHT

 

 

如果使用python2

sudo python setup.py install

 

 

如果使用python3

sudo python3 setup.py install

 

 

二、读取数据超级简单

import Adafruit_DHT

import time

DHT11 = Adafruit_DHT.DHT11

while(1):

humidity, temperature = Adafruit_DHT.read_retry(DHT11, 4)#4 是 GPIO 的引脚编号

print ("time:", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),"temperature :", temperature, "*C, humidity :", humidity, "%")

time.sleep(2)

 

 

三、输出

time: 2018-01-26 13:28:21 temperature : 25.0 *C, humidity : 46.0 %

time: 2018-01-26 13:28:24 temperature : 25.0 *C, humidity : 46.0 %

time: 2018-01-26 13:28:29 temperature : 25.0 *C, humidity : 47.0 %

time: 2018-01-26 13:28:31 temperature : 25.0 *C, humidity : 47.0 %

 

 

 

发表评论

你的电子邮件地址不会被公开 * 为必填字段

提交评论