from machine import Pin
import machine
import dht
import time
from utime import sleep
dht_pin = machine.Pin(2)
dht_sensor = dht.DHT22(dht_pin)
time.sleep(0.1) # Wait for USB to become ready
print("Hello, Pi Pico W!")
led = Pin(5, Pin.OUT)
while True:
led.toggle()
sleep(0.5)
try:
dht_sensor.measure()
temp_cel = dht_sensor.temperature()
humidity_pct = dht.dht_sensor.humidity()
print("Temperature: {:.2f} C", format(temp_cel))
print("Humidity: {:.2f} %", format(humidity_pct))
except Exception as e:
print("Error reading DHT22:", str(e))
time.sleep(0.1)