File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Adafruit_DHT_Driver_Python Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+ # -*- coding:utf-8 -*-
3+
4+ import sys
5+ import dhtreader
6+
7+ DHT11 = 11
8+ DHT22 = 22
9+ AM2302 = 22
10+
11+
12+ dhtreader .init ()
13+
14+ if len (sys .argv ) != 3 :
15+ print ("usage: {0} [11|22|2302] GPIOpin#" .format (sys .argv [0 ]))
16+ print ("example: {0} 2302 Read from an AM2302 connected to GPIO #4" .format (sys .argv [0 ]))
17+ sys .exit (2 )
18+
19+ dev_type = None
20+ if sys .argv [1 ] == "11" :
21+ dev_type = DHT11
22+ elif sys .argv [1 ] == "22" :
23+ dev_type = DHT22
24+ elif sys .argv [1 ] == "2302" :
25+ dev_type = AM2302
26+ else :
27+ print ("invalid type, only 11, 22 and 2302 are supported for now!" )
28+ sys .exit (3 )
29+
30+ dhtpin = int (sys .argv [2 ])
31+ if dhtpin <= 0 :
32+ print ("invalid GPIO pin#" )
33+ sys .exit (3 )
34+
35+ print ("using pin #{0}" .format (dhtpin ))
36+ t , h = dhtreader .read (dev_type , dhtpin )
37+ if t and h :
38+ print ("Temp = {0} *C, Hum = {1} %" .format (t , h ))
39+ else :
40+ print ("Failed to read from sensor, maybe try again?" )
You can’t perform that action at this time.
0 commit comments