from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
from utime import sleep
import dht
sensor = dht.DHT22(Pin(4))
ancho = 128
alto = 64
SodaP= I2C(sda=Pin(21), scl = Pin(22))
oled = SSD1306_I2C (ancho, alto, SodaP)
while True:
try:
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
print("Temperatura =", temp, "°C Humedad =", hum, "%")
oled.fill(0)
oled.text("Temperatura: {} C".format(temp), 0, 30)
oled.text("Humedad : {} %".format(hum), 0, 40)
oled.show()
except OSError as e:
print ("Ocurrio un error")
sleep(3)