"""
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Raspberry Pi Pico DHT22 Sensor Reader (MicroPython)      ┃
┃                                                          ┃
┃ A program to read temperature and humidity data from a   ┃
┃ DHT22 sensor and display the values on the console.      ┃
┃                                                          ┃
┃ Copyright (c) 2023 Anderson Costa                        ┃
┃ GitHub: github.com/arcostasi                             ┃
┃ License: MIT                                             ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
"""

import machine
import utime
import dht

# Configure the sensor data pin
DATA_PIN = machine.Pin(28, machine.Pin.IN, machine.Pin.PULL_UP)

# Create an instance of the DHT22 sensor
sensor = dht.DHT22(DATA_PIN)

def read_and_display_data():
    # Function to read and display data from the DHT22 sensor
    try:
        sensor.measure()
        temp = sensor.temperature()
        humidity = sensor.humidity()
        print("Temperature: {:.2f}°C, Humidity: {:.2f}%".format(temp, humidity))
    except Exception as e:
        print("Error reading sensor data:", e)

# Main loop
while True:
    read_and_display_data()
    utime.sleep(1)  # Wait for 1 seconds before reading the data again
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT
pico:GP0
pico:GP1
pico:GND.1
pico:GP2
pico:GP3
pico:GP4
pico:GP5
pico:GND.2
pico:GP6
pico:GP7
pico:GP8
pico:GP9
pico:GND.3
pico:GP10
pico:GP11
pico:GP12
pico:GP13
pico:GND.4
pico:GP14
pico:GP15
pico:GP16
pico:GP17
pico:GND.5
pico:GP18
pico:GP19
pico:GP20
pico:GP21
pico:GND.6
pico:GP22
pico:RUN
pico:GP26
pico:GP27
pico:GND.7
pico:GP28
pico:ADC_VREF
pico:3V3
pico:3V3_EN
pico:GND.8
pico:VSYS
pico:VBUS
dht1:VCC
dht1:SDA
dht1:NC
dht1:GND