from machine import Pin, SoftI2C
from i2c_lcd import I2cLcd
import dht
import time
# Khởi tạo cảm biến DHT22
d = dht.DHT22(Pin(4))
# Khởi tạo LCD
i2c = SoftI2C(scl=Pin(22), sda=Pin(21), freq=100000)
lcd = I2cLcd(i2c, 0x27, 2, 16)
while True:
# Đọc giá trị từ cảm biến DHT22
d.measure()
temp = d.temperature()
hum = d.humidity()
# Hiển thị giá trị lên LCD
lcd.move_to(0, 0)
lcd.putstr("Temp: {:.1f} C".format(temp))
lcd.move_to(0, 1)
lcd.putstr("Humidity: {:.1f} %".format(hum))