作者daniel098962 (丹尼尔)
看板Python
标题[问题] raspberry pi 温湿度定时器
时间Thu Jul 14 12:14:55 2016
各位大大好,小弟最近在玩raspberry pi
没找到PI的专版 就到这边来问了~
最近在PI上加了DHT 11抓温湿度
想要加个定时器让他可以每隔一段时间便抓一次温湿度
因为没什麽碰过python的语言
想请教一下要怎麽去写
抓温湿度的程式是参考网路上叶难的文章
程式码以下
「先安装所需套件:
$ sudo apt-get update
$ sudo apt-get install build-essential python-dev
然後下载,进入该目录:
$ git clone
https://github.com/adafruit/Adafruit_Python_DHT.git
$ cd Adafruit_Python_DHT
安装:
$ sudo python setup.py install
接着就能读取DHT11了,执行写好的范例Python程式:
$ cd examples
$ sudo ./AdafruitDHT.py 11 4
Temp=27.0*C Humidity=81.0%」
我在网路看到的定时器范例像以下
import threading
import time
def hello(name):
print "hello %s\n" % name
global timer
timer = threading.Timer(2.0, hello, ["Hawk"])
timer.start()
if __name__ == "__main__":
timer = threading.Timer(2.0, hello, ["Hawk"])
timer.start()
若我今天重复执行抓温度的程式的话
方法那边该怎麽写呢
谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 220.128.240.242
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1468469697.A.330.html
1F:推 ihcaoe: 可以用linux指令,`watch ./AdafruitDHT.p 11 4` 07/14 13:14
2F:→ ihcaoe: 要python也可以while+Thread.sleep() 07/14 13:15
4F:→ enjoyloli: 你试试看 不行的话在commit我改看看 07/14 14:47
5F:→ enjoyloli: *comment 07/14 14:47