from time import sleep_ms, ticks_ms
from machine import SoftI2C, Pin
from i2c_lcd import I2cLcd
import dht
import time
# LCD
i2c = SoftI2C(scl=Pin(22), sda=Pin(21),freq=100000)
lcd = I2cLcd(i2c, 0x27,2,16)
time.sleep(1)
lcd.clear()
# DHT11
d = dht.DHT22(Pin(25))
t = 0
h = 0
# START
text = 'Starting...'
lcd.putstr(text)
#lcd.backlight()
while True:
try:
d.measure()
time.sleep(2)
t = d.temperature()
h = d.humidity()
temp = 'Temp: {:.0f} C'.format(t)
humid = 'Humidity: {:.0f} %'.format(h)
print('DHT11:', t, h)
lcd.clear()
lcd.putstr(temp)
lcd.move_to(0,1)
lcd.putstr(humid)
lcd.color(0,0,1)
time.sleep(5)
except:
pass