from machine import Pin, SoftI2C
import time
import dht
from lcd_api import LcdApi
from i2c_lcd import I2cLcd
led = Pin(5, Pin.OUT)
sensor = dht.DHT22(Pin(14))
# Setup LCD
I2C_ADDR = 0x27
totalRows = 2
totalColumns = 16
i2c = SoftI2C(scl=Pin(22), sda=Pin(21), freq=10000) #initializing the I2C method for ESP32
#i2c = I2C(scl=Pin(5), sda=Pin(4), freq=10000) #initializing the I2C method for ESP8266
lcd = I2cLcd(i2c, I2C_ADDR, totalRows, totalColumns)
lcd.putstr("I2C LCD Tutorial")
h = -1
while True:
# Doc du lieu cam bien
sensor.measure()
t = sensor.temperature()
if h != sensor.humidity():
h = sensor.humidity()
lcd.clear()
lcd.putstr(str(h))
if t > 40:
led.on()
else:
led.off()
time.sleep(0.5)