from machine import Pin, SoftI2C
import dht
import ssd1306
from time import sleep
sensor_dht = dht.DHT11(Pin(4))
i2c = I2C(scl = Pin(22), sda = Pin(21))
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
while True:
try:
sensor_dht.measuere()
temperatura = sensor_dht.temperature()
humedad = sensor_dht.humidity()
print("valor temperatura =", temperatura, "ºc")
print("valor de Humedad =", humedad, "º%")
#Limpiar la info de OLED
oled.fill(0)
#Mostrar en la pantalla OLED
oled.text("Estacion meteorologica",10 ,10)
oled.text(f"Temp= {temperatura} ºC", 10 ,10)
oled.text(f"Hum= {humedad} %", 10 , 45)
#Actualizar la pantalla OLED
oled.show()
except Exception as e:
print ("error", e)
sleep(2)