Skip to content

Instantly share code, notes, and snippets.

@ReneHollander
Last active January 1, 2019 22:26
Show Gist options
  • Save ReneHollander/3b9986e0dc2136bc07d8a917a14277f9 to your computer and use it in GitHub Desktop.
Save ReneHollander/3b9986e0dc2136bc07d8a917a14277f9 to your computer and use it in GitHub Desktop.
RaspberryPi read DHT22 with Adafruit_Python_DHT
#!/usr/bin/python3
import sys
import Adafruit_DHT
sensor = Adafruit_DHT.DHT22
sensor_name = sys.argv[1]
pin = sys.argv[2]
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin, delay_seconds=3)
if humidity is not None and temperature is not None:
print('ambient,sensor_name={} temperature={:0.1f},humidity={:0.1f}'.format(sensor_name, temperature, humidity))
sys.exit(0)
else:
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment