from machine import Pin, SoftI2C
from i2c_lcd import I2cLcd
from utime import sleep
import dht
import network
import time
i2c = SoftI2C(sda=Pin(21), scl=Pin(22))
lcd = I2cLcd(i2c, 0x27, 2, 16)
lcd.backlight_on()
lcd.clear()
sensor = dht.DHT22(Pin(4))
led_high = Pin(13, Pin.OUT)
led_low = Pin(12, Pin.OUT)
while True:
time.sleep(2)
sensor.measure()
temp = sensor.temperature()
humi = sensor.humidity()
txtTemp = 'Temp: {:6.2f} {}C '.format(temp, chr(223))
lcd.move_to(0, 0)
lcd.putstr(txtTemp)
txtHumi = 'Humi: {:5.1f} % '.format(humi)
lcd.move_to(0, 1)
lcd.putstr(txtHumi)
txt = 'Temp: {:6.2f} C, Humi: {:5.1f} %'.format(temp, humi)
print(txt)
if temp > 40:
led_high.on()
led_low.off()
else:
led_high.off()
led_low.on()