# ESP32-C5 Seven-Color E-Paper Art Frame

An interactive local-network art frame built with an ESP32-C5 and a Waveshare 4-inch seven-color E-Paper HAT+ (E). A small Python web console accepts artwork uploads, converts images to the panel format, and lets the user select a specific work for display.

This project adapts the core image-server-to-e-paper workflow from [0015/7-Color-E-Paper-Digital-Photo-Frame](https://github.com/0015/7-Color-E-Paper-Digital-Photo-Frame) to ESP32-C5 and a 4-inch E6 panel, with an interactive gallery and device status feedback.

## Highlights

- Multi-image web gallery: upload, select, and delete artworks.
- On-demand seven-color quantization with a fixed 120000-byte panel payload.
- Web-triggered display change: the ESP receives the target revision, automatically restarts, and redraws the selected artwork using the stable boot-time refresh path.
- Device progress feedback: online, restart, download, refreshing, completion, and error states.
- ESP32-C5 hardware SPI implementation for the 4-inch E6 panel.
- Download retry, BUSY timeout, and persistent command revision for more reliable local demos.

## Demo

The screenshots below show the gallery while waiting for a device and after the ESP has returned online. They contain no network address, Wi-Fi credential, or local service URL.

![Gallery waiting for the device](docs/images/gallery-offline.jpg)

![Gallery with the ESP online](docs/images/gallery-online.jpg)

## Hardware

| ESP32-C5 GPIO | E-Paper HAT signal | Purpose |
|---|---|---|
| GPIO13 | DIN | SPI MOSI |
| GPIO14 | CLK | SPI clock |
| GPIO10 | CS | Chip select |
| GPIO9 | DC | Command/data select |
| GPIO8 | RST | Panel controller reset |
| GPIO7 | BUSY | Panel busy input |
| GPIO6 | PWR | HAT power control |
| 3.3V | VCC | Power |
| GND | GND | Common ground |

Use 3.3V for the HAT supply and ensure all grounds are connected.

## Quick Start

### 1. Install the Python dependency

```bash
python -m pip install -r requirements.txt
```

### 2. Configure the device

Copy the example configuration:

```text
firmware/epaper_photo_frame/wifi_secrets.example.h
```

to `wifi_secrets.h` in the same folder. Enter your own Wi-Fi credentials and the LAN address of the computer running the Python service. `wifi_secrets.h` is intentionally ignored by Git.

### 3. Start the image service

```bash
cd server/epaper_photo_server
python -u server.py
```

Open the service from a browser using the computer's current LAN address and port `9999`.

### 4. Build and upload the firmware

Install Arduino CLI and the Arduino ESP32 core, then build for:

```text
esp32:esp32:esp32c5
```

Upload to the serial port used by your ESP32-C5. The project uses the Arduino ESP32 core, not ESP-IDF.

## How Display Switching Works

1. The gallery stores the selected artwork and increments a persistent revision token.
2. The ESP polls the token while connected to Wi-Fi.
3. When the token changes, the ESP automatically restarts.
4. On boot, it downloads the selected 120000-byte payload and performs a full E-Paper refresh.
5. The gallery receives progress and completion callbacks.

This restart-based route intentionally reuses the panel's proven boot-time refresh sequence, avoiding unreliable in-place repeated full-refresh behavior observed on this hardware.

## Project Layout

```text
firmware/epaper_photo_frame/     ESP32-C5 firmware and E6 driver
server/epaper_photo_server/      Web gallery, image encoder, HTTP API, tests
docs/images/                     Demonstration photos
requirements.txt                 Python dependency list
```

## Verification

Run the service tests from `server/epaper_photo_server`:

```bash
python -m unittest -v test_server.py
```

The test suite covers gallery selection, cached payloads, command revision updates, device progress, deletion, and retaining existing artworks after an upload.

## License and Attribution

This repository retains the MIT license from the upstream reference project. The implementation here contains hardware-specific adaptations and additional gallery/status functionality for ESP32-C5 and the 4-inch E6 display.
