from machine import Pin
import time
from machine import Pin, SoftI2C, sleep
from lcd_api import LcdApi
from i2c_lcd import I2cLcd
import dht
sensor = dht.DHT22(Pin(15))
I2C_ADDR = 0x27
totalRows = 4
totalColums = 20
i2c = SoftI2C(scl=Pin(22), sda=Pin(21), freq=10000)
lcd = I2cLcd(i2c, I2C_ADDR, totalRows, totalColums)
lcd.move_to(0,0)
lcd.putstr("Nguyen The Tra \n191403848")
while True:
try:
sleep(2)
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
lcd.move_to(0,2)
lcd.putstr("Nhiet do: " + str(temp) +" C" )
lcd.move_to(0,3)
lcd.putstr("Do am: " + str(hum) + " %")
except OSError as e:
lcd.clear()
lcd.putstr("Failed to read sensor")