from machine import Pin, SoftI2C
import dht
import time
from lcd_api import LcdApi
from i2c_lcd import I2cLcd
i2c = SoftI2C(scl=Pin(22), sda=Pin(21), freq=400000)
lcd = I2cLcd(i2c, 0x27, 2, 16)
dht_pin = Pin(2, Pin.IN)
sensor = dht.DHT22(dht_pin)
while True:
try:
sensor.measure()
temperature = sensor.temperature()
humidity = sensor.humidity()
lcd.clear()
lcd.putstr("Temp: {:.1f} C\n".format(temperature))
lcd.putstr("Hum: {:.1f} %".format(humidity))
except Exception as e:
lcd.clear()
lcd.putstr("Error: {}".format(str(e)))
time.sleep(0.5)