OLED_DHT — Aitewinrobot Esp32C3 Supermini simulation

An interactive Aitewinrobot Esp32C3 Supermini circuit simulation you can run free in your browser on Velxio, by edelarosagon.

Components

Sketch code

from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
import dht
import time
i2c = I2C(0, scl=Pin(7), sda=Pin(6))
oled = SSD1306_I2C(128, 64, i2c)

sensor = dht.DHT22(Pin(4))


def mostrar_mensaje(linea1, linea2=""):
    oled.fill(0)
    oled.text(linea1, 0, 0)
    oled.text(linea2, 0, 16)
    oled.show()


def mostrar_datos(temp, hum):
    oled.fill(0)
    oled.text("TIC's Encino", 15, 0)
    oled.hline(0, 10, 128, 1)
    oled.text("Temp:", 0, 25)
    oled.text("{:.1f} C".format(temp), 50, 25)
    oled.text("Hum:", 0, 50)
    oled.text("{:.1f} %".format(hum), 50, 50)
    oled.show()


mostrar_mensaje("Iniciando...")
time.sleep(2)  # El DHT22 necesita un momento tras encender

while True:
    try:
        sensor.measure()
        temperatura = sensor.temperature()
        humedad = sensor.humidity()
        mostrar_datos(temperatura, humedad)
        print("Temperatura: {:.1f} C  Humedad: {:.1f} %".format(temperatura, humedad))
    except OSError:
        mostrar_mensaje("Error sensor", "Revisa DHT22")
        print("Error al leer el DHT22")

    time.sleep(2)  # El DHT22 admite una lectura cada ~2 s

More projects by edelarosagon