Skip to content

Instantly share code, notes, and snippets.

@anoochit
Last active August 29, 2015 14:05
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 anoochit/1e966f901d7b78a5e421 to your computer and use it in GitHub Desktop.
Save anoochit/1e966f901d7b78a5e421 to your computer and use it in GitHub Desktop.
read temperature from dht22 for raspberry pi
#!/usr/bin/python
import sys
import time
import Adafruit_DHT
sensor = Adafruit_DHT.DHT22
pin = 4
while True:
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
if humidity is not None and temperature is not None:
print 'Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity)
time.sleep(2)
else:
print 'Failed to get reading. Try again!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment