Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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