Last active
August 29, 2015 14:05
-
-
Save anoochit/1e966f901d7b78a5e421 to your computer and use it in GitHub Desktop.
read temperature from dht22 for raspberry pi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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