from machine import Pin, I2C
from lcd_api import LcdApi
from pico_i2c_lcd import I2cLcd
from time import sleep
import dht
# LCD
I2C_ADDR = 0x27
I2C_NUM_ROWS = 2
I2C_NUM_COLS = 16
i2c = I2C(0, sda=machine.Pin(0), scl=machine.Pin(1), freq=400000)
lcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS)
lcd.backlight_on()
# Working
LED = Pin(2, Pin.OUT)
def ledBlink():
LED.on()
sleep(1)
LED.off()
sleep(1)
sensor = dht.DHT22(Pin(5))
while True:
try:
sleep(1)
sensor.measure()
lcd.clear()
lcd.putstr(f"Temp: {sensor.temperature():.1f}")
lcd.move_to(0,1)
lcd.putstr(f"Humidity: {sensor.humidity():.1f}")
except OSError as e:
lcd.putstr('Failed reception')