Skip to content

Instantly share code, notes, and snippets.

@akagisho
Created July 3, 2018 01:56
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 akagisho/6b093e5141cff7e8a2c6270a900ceda4 to your computer and use it in GitHub Desktop.
Save akagisho/6b093e5141cff7e8a2c6270a900ceda4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
from datetime import datetime
import Adafruit_DHT as DHT
SENSOR_TYPE = DHT.DHT22
DHT_GPIO = 18
print(datetime.now().strftime('%Y/%m/%d %H:%M:%S') + "\t"),
DHT.read_retry(SENSOR_TYPE, DHT_GPIO)
for i in range(3):
humidity, temperature = DHT.read_retry(SENSOR_TYPE, DHT_GPIO)
if humidity is not None and temperature is not None and humidity >= 0 and humidity <= 100:
print("{0:0.1f}\t{1:0.1f}".format(temperature, humidity))
sys.exit(0)
print('Failed to get reading. Try again!')
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment