from time import sleep_ms, ticks_ms
from machine import I2C, Pin
from i2c_lcd import I2cLcd
import dht
sensor = dht.DHT22(Pin(2))
AddressOfLcd = 0x27
i2c = I2C(scl=Pin(22), sda=Pin(21), freq=400000) # connect scl to GPIO 22, sda to GPIO 21
lcd = I2cLcd(i2c, AddressOfLcd, 2, 16)
for i in range(100):
try:
sleep_ms(200)
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
lcd.move_to(0,0)
lcd.putstr("Temperature " + str(temp))
lcd.move_to(0,1)
lcd.putstr("Humidity " + str(hum))
except OSError as e:
print('Failed to read sensor.')
sleep_ms(200)