'''from machine import Pin, ADC, PWM, I2C
from utime import sleep, sleep_ms
from dht import DHT22
from ssd1306 import SSD1306_I2C
alto = 64
ancho = 128
i2c=I2C(0, scl=Pin(22), sda=Pin(21))
oled = SSD1306_I2C(ancho, alto, i2c)
dht = DHT22(Pin(15))
print(i2c.scan(), "conectada")
while True:
dht.measure()
tem = dht.temperature()
hum = dht.humidity()
oled.fill(0)
oled.pixel(64,60,1)
oled.vline(0,0,20,1)
oled.vline(120,0,20,1) #columna fila
oled.hline(0,0,120,1)
oled.hline(0,20,120,1)
oled.text("DATOS", 10 ,10, 1)
oled.text("Tem:", 0 ,30, 1)
oled.text("Hum", 0 ,40, 1)
oled.text(str(tem), 60 ,30, 1)
oled.text(str(hum), 60 ,40, 1)
oled.show()
# sleep_ms(500)
#oled.show() #para mostrar en pantalla
#oled.fill(1)
#sleep_ms(500)
#oled.show()'''
import time
from machine import Pin, I2C
import dht
from ssd1306 import SSD1306_I2C
i2c = I2C(0, sda=Pin(21), scl=Pin(22), freq=400000)
oled_width = 128
oled_height = 64
oled = SSD1306_I2C(oled_width, oled_height, i2c)
sensor = dht.DHT22(Pin(15))
while True:
time.sleep(2)
sensor.measure()
temp=sensor.temperature()
hum=sensor.humidity()
oled.fill(1)
oled.text("Temperatura:", 0, 0, 0)
oled.text("{:.1f} C".format(temp), 0, 10, 0)
oled.text('Humedad:', 0, 30, 0)
oled.text("{:.1f}%".format(hum), 0, 40, 0)
oled.show()
time.sleep(2)
oled.fill(0)
oled.text("Temperatura:", 0, 0, 1)
oled.text("{:.1f} C".format(temp), 0, 10, 1)
oled.text('Humedad:', 0, 30, 1)
oled.text("{:.1f}%".format(hum), 0, 40, 1)
oled.show()
#oled.rect(0, 0, 128, 64, 1)
#oled.vline(5, 10, 49,1)