3.接下来安装python开发环境
apt-get update
apt-get install build-essential
python-dev
4.下载Adafruit公司的代码并安装。(核心是c语言,执行时python,有兴趣的可以去看看source目录的代码)
git clone
git://github.com/adafruit/Adafruit_Python_DHT.git
python setup.py install
5.检测温度:输入如下命令
/home/pi/dht/examples/AdafruitDHT.py 11
4
11是型号,4数据输入的GPIO编号,我们插的是4号,所以用4。
6.例子
pi@raspberrypi:~$
/home/pi/dht/examples/AdafruitDHT.py 11 4
Temp=20.0*
Humidity=47.0%
7.每一小时记录一次温湿度
写脚本:vi /root/test.sh
#!/bin/bash
time=`/bin/date`
temp=`/home/pi/dht/examples/AdafruitDHT.py 11
4`
echo "$time | $temp" >>
/home/pi/test.txt
8.写crontab:crontab -e
*/60 * * * *
/root/test.sh
9.新建储存文档:
echo "" >
/home/pi/test.txt
10.几个小时后效果:
pi@raspberrypi:~$ cat
/home/pi/test.txt
Tue Dec 6
19:10:01 CST 2016 | Temp=21.0*
Humidity=48.0%
Tue Dec 6
20:00:01 CST 2016 | Temp=21.0*
Humidity=48.0%
Tue Dec 6
21:00:01 CST 2016 | Temp=19.0*
Humidity=48.0%
Tue Dec 6
22:00:02 CST 2016 | Temp=18.0*
Humidity=50.0%
Tue Dec 6
23:00:01 CST 2016 | Temp=18.0*
Humidity=51.0%