Adafruit_Learning_System_Gu.../Introducing_Gemma_M0/dht22/code.py
2022-02-23 14:30:29 -05:00

22 lines
572 B
Python

# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import time
import adafruit_dht
import board
dht = adafruit_dht.DHT22(board.D2)
while True:
try:
temperature = dht.temperature
humidity = dht.humidity
# Print what we got to the REPL
print("Temp: {:.1f} *C \t Humidity: {}%".format(temperature, humidity))
except RuntimeError as e:
# Reading doesn't always work! Just print error and we'll try again
print("Reading from DHT failure: ", e.args)
time.sleep(1)