import dht
from machine import Pin
from machine import Pin, SoftI2C
from machine_i2c_lcd import I2cLcd
from time import sleep
LED_PIN1 = Pin(32,Pin.OUT)
LED_PIN2 = Pin(0,Pin.OUT)
I2C_ADDR = 0x27
I2C_NUM_ROWS = 2
I2C_NUM_COLS = 16
i2c = SoftI2C(sda=Pin(21), scl=Pin(22), freq=400000)
sensor = dht.DHT22(Pin(14))
lcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS)
try:
while True:
sleep(2)
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
if temp >= 25:
LED_PIN1.value(1)
else:
LED_PIN1.value(0)
if hum >= 25:
LED_PIN2.value(1)
else:
LED_PIN2.value(0)
lcd.putstr('Temperature: %3.1f C' %temp)
lcd.move_to(0, 1)
lcd.putstr('Humidity: %3.1f %%' %hum)
sleep(2)
except KeyboardInterrupt:
print("Keyboard interrupt")
lcd.backlight_off()
lcd.display_off()