from machine import Pin
import dht
import time
dht_pin = Pin(17)
sensor = dht.DHT22(dht_pin)
while True:
try:
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
print("Temperature: %-3.1f C" % temp)
print("Humidity: %-3.1f %%" % hum)
except OSError as e:
print('Failed to read sensor.')
time.sleep(6)