# Home Assistant panel for the 4.0" ESP32-32E (E32R40T)

A Home Assistant touch panel for the inexpensive LCDwiki **E32R40T** board (4.0", 480×320, ST7796S, XPT2046 resistive touch, ESP32 without PSRAM). The firmware is ESPHome + LVGL and needs no coding: just enter your own entity IDs.

Six pages: Home (lights, fan, climate, safe, weather), Rack (power usage and power alarm), Servers (Proxmox, services, storage), Music, Camera (preview from HA) and Settings. Plus a shared top bar with the time, alerts and connection status.

| | | |
|---|---|---|
| ![Home](docs/screens/home.png) | ![Rack](docs/screens/rack.png) | ![Servers](docs/screens/servers.png) |
| ![Music](docs/screens/music.png) | ![Camera](docs/screens/camera.png) | ![Settings](docs/screens/settings.png) |

*Illustrative mockups with example data; page descriptions in [esphome/README.md](esphome/README.md#appearance).*

## Repository contents

| Path | What it is |
|---|---|
| [esphome/](esphome/) | Panel configuration and **installation guide** ([esphome/README.md](esphome/README.md)) |
| [docs/screens/](docs/screens/) | Mockups of the panel pages shown in this README |

## Quick start

1. Read [esphome/README.md](esphome/README.md), section "What you need in Home Assistant".
2. Copy `esphome/ha-dashboard.example.yaml` as your device file and fill in your entities.
3. Add the secrets (Wi-Fi, API key) in the ESPHome add-on, following `esphome/secrets.yaml.example`.
4. Flash from the ESPHome add-on in HA (the first time over USB-C).

## Hardware

4.0" ESP32-32E display module, SKU **E32R40T** (resistive touch) / E32N40T (no touch). Manufacturer docs: [LCDwiki 4.0inch ESP32-32E Display](https://www.lcdwiki.com/4.0inch_ESP32-32E_Display).

- MCU: ESP32-D0WD-V3 (dual-core LX6, 240 MHz), 520 KB SRAM, 4 MB flash, no PSRAM
- LCD: 320×480, ST7796S driver over 4-wire SPI (RGB565; the panel supports up to RGB666)
- Touch: XPT2046 resistive controller over SPI; needs calibration, unlike capacitive touch
- USB-C through a CH340C with auto-download, so you don't need to press BOOT to flash

### Pin map

| Function | Pins |
|---|---|
| LCD SPI (shared with touch) | SCLK 14, MOSI 13, MISO 12 |
| LCD control | CS 15, DC 2, backlight 27 (high = on) |
| LCD reset | Tied to ESP32 EN, so it has no GPIO (use `RST = -1` in drivers) |
| Touch | CS 33, IRQ 36 (low when touched) |
| MicroSD (separate SPI bus, shared with ext. SPI header) | CS 5, MOSI 23, SCLK 18, MISO 19 |
| External SPI header | CS 21, same bus as SD (18/19/23) |
| I2C header | SCL 25, SDA 32 |
| RGB LED (common anode, low = on) | R 22, G 16, B 17 |
| Audio | DAC out 26, amp enable 4 (low = enabled) |
| Battery voltage ADC | 34 |
| BOOT button | 0 |
| UART0 | TX 1, RX 3 |
| Free, input-only | 35, 39 |

### Hardware gotchas

- The LCD and the touch controller share one SPI bus (12/13/14) and differ only by CS. The SD card is on a *different* bus (18/19/23).
- GPIO 34, 35, 36 and 39 are input-only and have no internal pull-ups.
- The RGB LED and the audio amp enable are both active-low: driving them high turns them off.
- Holding the LCD or the ESP32 in reset resets both, because the LCD's reset line is EN.

## License

[MIT](LICENSE)
