from machine import Pin, SoftI2C
from time import sleep
from i2c_lcd import I2cLcd
import dht
sdaPIN = Pin(21) # Definimos el Pin del SDA
sclPIN = Pin(22) # Definimos el Pin del SCL
sensor = dht.DHT22(Pin(13)) # Definimos el sensor DHT22
I2C_ADDR = 0x27 # Definimos la dirección del LCD
totalRows = 2 # Definimos las filas
totalColumns = 16 # Definimos las columnas
i2c = SoftI2C(sda=sdaPIN, scl=sclPIN, freq=10000) # Se inicializa el I2C
lcd = I2cLcd(i2c, I2C_ADDR, totalRows, totalColumns) # Se inicializa el LCD para poder trabajar con el
while True:
sensor.measure() # Sensor comienza a medir
t = sensor.temperature()
h = sensor.humidity()
if t>50: #Si la temperatura es mayor a 50° se manda la alerta
lcd.clear()
lcd.move_to(1,0)
lcd.putstr("La temperatura")
lcd.move_to(0,1)
lcd.putstr("es mayor a 50 %sC"%chr(223))
else: #Si la temperatura es menor a 50° se manda la lectura del sensor
lcd.clear()
lcd.move_to(0,0)
lcd.putstr("Temp: %3.1f %sC" % (t, chr(223)))
lcd.move_to(0,1)
lcd.putstr("Humedad: %3.1f%s"%(h, chr(37)))
sleep(5) # Espera 5 segundos antes de la próxima lectura