Skip to content

Instantly share code, notes, and snippets.

Created May 7, 2014 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/dd5d16e3dc105ef21ebf to your computer and use it in GitHub Desktop.
Save anonymous/dd5d16e3dc105ef21ebf to your computer and use it in GitHub Desktop.
#Initialize DHT22 Sensor and read data.
#to access, run python as root. (sudo) (shouldn’t be a problem if script is run as system service)
import dhtreader
type = 22 # we are using the DHT22
pin = 18 # and it is on GPIO 18 in this example.
dhtreader.init()
print dhtreader.read(type, pin)
# will print Temperature [0], and Humidity[1] as (Temperature, Humidity).
x = dhtreader.read(type, pin)
while x is None
x = dhtreader.read(type, pin)
# x[0] will be temp. x[1] will be Hum. Lets set those to their own variables to keep from confusing.
dhtemp = x[0]
dhhum = x[1]
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment