from time import sleep_ms, ticks_ms
from machine import I2C, Pin
from i2c_lcd import I2cLcd
import dht
import time
import machine
Address0fLcd = 0x27
i2c = I2C(scl=Pin(22), sda=Pin(21), freq=400000)
lcd = I2cLcd(i2c, Address0fLcd, 2, 16)
sensor =dht.DHT22(machine.Pin(18))
def read_temp_humi():
try:
sensor.measure()
temp = sensor.temperature()
humi = sensor.humidity()
lcd.move_to(3,0)
lcd.putstr("temp: {} C".format(temp))
lcd.move_to(3,1)
lcd.putstr("humi: {} %".format(humi))
print("temp: {} C".format(temp))
print("humi: {} %".format(humi))
except OsError as e:
print("Fialed to read sensor")
if __name__ == '__main__':
while True:
read_temp_humi()
time.sleep(5)