from time import sleep
from machine import I2C,Pin
from i2c_lcd import I2cLcd
import dht
sensor = dht.DHT22(Pin(32))
DirLcd = 0x27
configbus = I2C(scl=Pin(22), sda=Pin(21), freq=400000)
lcd=I2cLcd(configbus,DirLcd,2,16)
lcd.move_to(0,0)
lcd.putstr('TEMP=')
lcd.move_to(0,1)
lcd.putstr ('HUME=')
while True:
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
temp_f = temp * (9 / 5) + 32.0 # Convertir a °F
# Convertir a texto
temp_str = "{:.1f} ".format(temp)
hum_str = "{:.1f} ".format(hum)
lcd.move_to(5, 0)
#lcd.putstr(" ")
lcd.move_to(5, 0)
lcd.putstr(temp_str)
lcd.move_to(10, 0)
lcd.putstr("C")
lcd.move_to(5, 1)
#lcd.putstr(" ")
lcd.move_to(5, 1)
lcd.putstr(hum_str)
lcd.move_to(10, 1)
lcd.putstr("%")
print("Temperatura =", temp, "°C | Humedad =", hum, "%")
sleep(2)