CASAHOST Smart Home ESP32 — ESP32 simulation

Système de contrôle de température CASAHOST avec ESP32, DHT22, LCD et MQTT.

An interactive ESP32 circuit simulation you can run free in your browser on Velxio, by yenihandresk.

Components

Sketch code

from lcd_api import LcdApi
import time

class I2cLcd(LcdApi):
    def __init__(self, i2c, i2c_addr, num_lines, num_columns):
        self.i2c = i2c
        self.i2c_addr = i2c_addr
        self.backlight = 0x08
        super().__init__(num_lines, num_columns)
        time.sleep_ms(50)
        self._write4bits(0x03); time.sleep_ms(5)
        self._write4bits(0x03); time.sleep_ms(5)
        self._write4bits(0x03); time.sleep_ms(1)
        self._write4bits(0x02)
        self.hal_write_command(0x2C)  # 4 bits, 4 lines, 5x8 font
        self.hal_write_command(0x0C)  # display on, cursor off
        self.clear()

    def hal_write_command(self, cmd):
        self._send(cmd & 0xF0, 0)
        self._send((cmd << 4) & 0xF0, 0)

    def hal_write_data(self, data):
        self._send(data & 0xF0, 1)
        self._send((data << 4) & 0xF0, 1)

    def _write4bits(self, value):
        self._send(value, 0)

    def _send(self, data, mode):
        buf = bytes([data | mode | self.backlight | 0x04])
        self.i2c.writeto(self.i2c_addr, buf)
        self.i2c.writeto(self.i2c_addr, bytes([data | mode | self.backlight]))
        time.sleep_us(50)

More projects by yenihandresk