from machine import I2C, Pin, Timer
from esp8266_i2c_lcd import I2cLcd
import utime, gc, dht
def lcd_show(text, clear=True):
if clear:
lcd.clear()
lcd.move_to(0, 0)
lcd.putstr(text)
gc.enable()
DEFAULT_I2C_ADDR = 0x27
hw_i2c0 = I2C(1, freq=200000)
lcd = I2cLcd(hw_i2c0, DEFAULT_I2C_ADDR, 2, 16)
sensor = dht.DHT22(Pin(17))
t=h=0
while 1:
sensor.measure() # read the parameters from the sensor
if t !=sensor.temperature() or h!=sensor.humidity():
t = sensor.temperature()
h = sensor.humidity()
lcd_show('Temp:'+str(t)+'c Humidity:'+str(h)+'%')
utime.sleep(5)