from machine import Pin, I2C
import ssd1306
import dht
from time import sleep

sensor = dht.DHT22(Pin(15))
i2c = I2C(0, scl=Pin(22), sda=Pin(21), freq=100000)
oled = ssd1306.SSD1306_I2C(128, 64, i2c)

while True:
    try:
        sensor.measure()
        t = sensor.temperature()
        h = sensor.humidity()
        oled.fill(0)
        oled.text("T: %3.1f C" % t, 10, 10)
        oled.text("H: %3.1f %%" % h, 10, 20)
        if t > 50:
            oled.text("Muy caliente", 10, 40)
        if h > 80:
            oled.text("Muy humedo", 10, 50)
        oled.show()
        sleep(2)
    except Exception as e:
        print("Error:", e)
esp:VIN
esp:GND.2
esp:D13
esp:D12
esp:D14
esp:D27
esp:D26
esp:D25
esp:D33
esp:D32
esp:D35
esp:D34
esp:VN
esp:VP
esp:EN
esp:3V3
esp:GND.1
esp:D15
esp:D2
esp:D4
esp:RX2
esp:TX2
esp:D5
esp:D18
esp:D19
esp:D21
esp:RX0
esp:TX0
esp:D22
esp:D23
dht1:VCC
dht1:SDA
dht1:NC
dht1:GND
oled1:GND
oled1:VCC
oled1:SCL
oled1:SDA