from machine import Pin, ADC, I2C
from utime import sleep, sleep_ms
from ssd1306 import SSD1306_I2C
from dht import DHT22
ancho = 128
alto = 64
i2c = I2C(0, scl=Pin(9), sda=Pin(8))
oled = SSD1306_I2C(ancho, alto, i2c)
sensor= DHT22(Pin(47))
print("Dirección:", i2c.scan())
while True:
sensor.measure()
tem = sensor.temperature()
hum = sensor.humidity()
print("Tem:{}°c, Hum:{}%".format(tem,hum))
oled.fill(0)
oled.pixel(64, 60, 1)
oled.hline(0, 0, 128, 1)
oled.hline(0, 20, 128, 1)
oled.vline(0, 0, 20, 1)
oled.vline(127, 0,20, 1)
oled.text("Datos", 40, 7, 1)
oled.text("Tem:", 0, 30, 1)
oled.text(str(tem), 40, 30, 1)
oled.text("Hum:", 0, 50, 1)
oled.show()
sleep(1)