# ddehimer/elbdisplay architecture

> Architecture diagram of the GitHub repository ddehimer/elbdisplay, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ddehimer/elbdisplay
- Repository: https://github.com/ddehimer/elbdisplay

## Overview

1. **Repository shape**
   - This repo contains a **two-MCU embedded system** plus the tooling/assets for the ESP32 display UI.
   - The main runtime code is split into:
     - **`RP2040 Code/`**: sensor acquisition and control firmware.
     - **`CrowPanel7inch/`**: ESP32-based display/UI firmware, with two alternative UI projects.
     - **Root README**: defines the cross-device architecture and UART contract.

2. **System boundary**
   - The clean architectural boundary is between:
     - **RP2040 = real-time data/control node**
     - **ESP32 display = UI, logging, and operator control node**
   - This separation is deliberate: timing-sensitive sensing stays on the RP2040, while the ESP32 handles the user-facing and storage-heavy work.

3. **RP2040 firmware responsibilities**
   - The RP2040 side is a **MicroPython-based control loop** (`main.py`, `current_control.py`) with local drivers under `drivers/`.
   - It reads hardware through **I2C ADCs and related sensors**:
     - `ads1115.py` for ADC acquisition
     - `current_dac.py` for current/output control
     - `temperature.py` for temperature sensing
   - Its job is to **sample, calibrate, convert, and stream** data deterministically.

4. **RP2040 runtime model**
   - The root README describes the RP2040 as a **non-blocking state machine** with states like `IDLE`, `ACTIVE`, and `ERROR`.
   - It emits structured telemetry over UART and responds to control commands such as **start/stop**.
   - The included test scripts (`tempTest.py`, `uart_test.py`, `test.py`) suggest the RP2040 logic is also exercised in isolation during development.

5. **ESP32 display responsibilities**
   - The ESP32 is the **human interface and logging node**.
   - It owns:
     - touch UI and screen rendering
     - operator actions like start/stop and filename entry
     - UART communication with the RP2040
     - SD card CSV logging
     - live status/error display

6. **ESP32 UI implementation variants**
   - There are **two parallel ESP32 UI projects** under `CrowPanel7inch/`:
     - **`Starter_EEZ-Open/`**: UI built from EEZ Studio / EEZ Open assets.
     - **`Starter_SquareLineUX/`**: UI built from SquareLine Studio assets.
   - They appear to solve the same display problem using different UI-generation toolchains, so for an architecture diagram they should be treated as **alternative front-end implementations** of the same ESP32 role.

7. **ESP32 application structure**
   - Both ESP32 projects use **PlatformIO** and an **LVGL-based UI stack**.
   - The code is split into:
     - generated UI screens/styles/fonts/images
     - application glue and event handlers
     - display driver wrapper (`lgfx/`, likely LovyanGFX)
     - communication/storage helpers
   - In the SquareLineUX variant, notable subsystems include `uart_link.*`, `sd_export.*`, `data_model.*`, and generated screen/component files.

8. **Data flow: measurement path**
   - The primary forward data path is:
     - **Sensors / current control hardware**
     - → **RP2040 acquisition and processing**
     - → **UART**
     - → **ESP32 UI**
     - → **screen display**
     - → **SD card CSV append**
   - The ESP32 is not the source of measurement truth; it is a consumer and recorder of the RP2040 stream.

9. **Data flow: control path**
   - The reverse path is operator-driven:
     - **touch input on ESP32**
     - → **UI callback / application logic**
     - → **UART command**
     - → **RP2040 state transition**
   - The documented commands are simple ASCII lines such as **`START`** and **`STOP`**, which keeps debugging and integration straightforward.

10. **Communication contract**
   - UART is the only runtime coupling between the MCUs.
   - The protocol is intentionally **line-delimited ASCII**, with messages such as:
     - `DATA,...`
     - `STATUS,...`
     - `ERROR,...`
   - This means the two halves are loosely coupled: the ESP32 can be updated independently as long as the message format stays stable.

11. **Storage and persistence**
   - **SD card writing is exclusively on the ESP32 side**.
   - Logged data is written as **CSV per session**, which matches the repo’s stated separation of concerns: the RP2040 never touches filesystem concerns.
   - The ESP32 project structure includes explicit export/logging helpers, reinforcing that storage is a first-class subsystem rather than UI side effect.

12. **Board and platform setup**
   - `CrowPanel7inch/BoardDefinition/` contains an **ESP32-S3 board definition** and install scripts, indicating the display hardware is a custom/declared board target rather than a generic dev kit.
   - The ESP32 code targets an embedded graphics stack with project metadata, generated assets, and config headers such as `lv_conf.h` and `touch.h`.

13. **Reusable/custom components**
   - Both ESP32 variants include a shared custom component library, including `LabelCount.ecomp` and a `Crowbits_DHT20` library.
   - This suggests the UI is not just static screens; it includes reusable widgets and at least one sensor-oriented library dependency in the display-side codebase.

14. **What to show in an architecture diagram**
   - The diagram should center on **two boxes**:
     - **RP2040 firmware**: acquisition + control + state machine
     - **ESP32 display firmware**: UI + logging + operator control
   - Between them, show a **UART link** carrying ASCII commands and telemetry.
   - On the RP2040 side, show **sensors/ADCs/DAC/temperature**.
   - On the ESP32 side, show **touch UI, display rendering, and SD card CSV storage**.
   - Optionally annotate that the ESP32 UI has **two implementation variants**: EEZ Open and SquareLineUX.

Main entry points: [`RP2040 Code/main.py`](https://github.com/ddehimer/elbdisplay/blob/HEAD/RP2040%20Code/main.py) (Main loop), [`CrowPanel7inch/Starter_SquareLineUX/src/main.cpp`](https://github.com/ddehimer/elbdisplay/blob/main/CrowPanel7inch/Starter_SquareLineUX/src/main.cpp) (App entry), [`CrowPanel7inch/Starter_SquareLineUX/src/ui.c`](https://github.com/ddehimer/elbdisplay/blob/main/CrowPanel7inch/Starter_SquareLineUX/src/ui.c) (SquareLine UI), [`CrowPanel7inch/Starter_SquareLineUX/src/uart_link.cpp`](https://github.com/ddehimer/elbdisplay/blob/main/CrowPanel7inch/Starter_SquareLineUX/src/uart_link.cpp) (UART link)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_repo["Repository"]
  node_readme["Architecture<br/>contract<br/>[README.md]"]
end

subgraph group_rp2040["RP2040 firmware"]
  node_rp_main["Main loop<br/>micropython runtime<br/>[main.py]"]
  node_rp_control["Control logic<br/>state machine<br/>[current_control.py]"]
  node_adc_driver["ADC driver<br/>sensor interface<br/>[ads1115.py]"]
  node_dac_driver["Output control<br/>actuator driver<br/>[current_dac.py]"]
  node_temp_driver["Temp sensing<br/>sensor driver<br/>[temperature.py]"]
  node_rp_tests["RP2040 tests<br/>test scripts<br/>[uart_test.py]"]
end

subgraph group_esp32["ESP32 display"]
  node_esp_main["App entry<br/>platformio app<br/>[main.cpp]"]
  node_uart_link["UART link<br/>serial protocol<br/>[uart_link.cpp]"]
  node_data_model["Data model<br/>ui state<br/>[data_model.cpp]"]
  node_sd_export["CSV export<br/>storage<br/>[sd_export.cpp]"]
  node_lgfx["Display driver<br/>graphics backend<br/>[lgfx.cpp]"]
  node_esp_board["Board setup<br/>board target"]
  node_shared_widgets["Custom widgets<br/>ui components<br/>[LabelCount.ecomp]"]
end

subgraph group_ui_variants["UI variants"]
  node_sq_ui["SquareLine UI<br/>generated ui<br/>[ui.c]"]
  node_eez_ui["EEZ Open UI<br/>generated ui<br/>[ui.c]"]
end

node_readme -->|"defines"| node_rp_main
node_readme -->|"defines"| node_esp_main
node_rp_main -->|"uses"| node_rp_control
node_rp_main -->|"reads"| node_adc_driver
node_rp_main -->|"controls"| node_dac_driver
node_rp_main -->|"reads"| node_temp_driver
node_rp_control -->|"streams"| node_uart_link
node_adc_driver -->|"feeds"| node_uart_link
node_temp_driver -->|"feeds"| node_uart_link
node_uart_link -->|"parses"| node_data_model
node_esp_main -->|"renders"| node_lgfx
node_esp_main -->|"hosts"| node_sq_ui
node_esp_main -.->|"alternative"| node_eez_ui
node_sq_ui -->|"sends"| node_uart_link
node_sq_ui -->|"logs"| node_sd_export
node_data_model -->|"updates"| node_sq_ui
node_sd_export -->|"persists"| node_esp_main
node_esp_board -->|"targets"| node_esp_main
node_shared_widgets -->|"extends"| node_sq_ui
node_shared_widgets -->|"extends"| node_eez_ui
node_rp_tests -.->|"exercises"| node_rp_main

click node_readme "https://github.com/ddehimer/elbdisplay/blob/main/README.md"
click node_rp_main "https://github.com/ddehimer/elbdisplay/blob/main/RP2040 Code/main.py"
click node_rp_control "https://github.com/ddehimer/elbdisplay/blob/main/RP2040 Code/current_control.py"
click node_adc_driver "https://github.com/ddehimer/elbdisplay/blob/main/RP2040 Code/drivers/ads1115.py"
click node_dac_driver "https://github.com/ddehimer/elbdisplay/blob/main/RP2040 Code/drivers/current_dac.py"
click node_temp_driver "https://github.com/ddehimer/elbdisplay/blob/main/RP2040 Code/drivers/temperature.py"
click node_rp_tests "https://github.com/ddehimer/elbdisplay/blob/main/RP2040 Code/uart_test.py"
click node_esp_main "https://github.com/ddehimer/elbdisplay/blob/main/CrowPanel7inch/Starter_SquareLineUX/src/main.cpp"
click node_uart_link "https://github.com/ddehimer/elbdisplay/blob/main/CrowPanel7inch/Starter_SquareLineUX/src/uart_link.cpp"
click node_data_model "https://github.com/ddehimer/elbdisplay/blob/main/CrowPanel7inch/Starter_SquareLineUX/src/data_model.cpp"
click node_sd_export "https://github.com/ddehimer/elbdisplay/blob/main/CrowPanel7inch/Starter_SquareLineUX/src/sd_export.cpp"
click node_lgfx "https://github.com/ddehimer/elbdisplay/blob/main/CrowPanel7inch/Starter_SquareLineUX/src/lgfx/lgfx.cpp"
click node_sq_ui "https://github.com/ddehimer/elbdisplay/blob/main/CrowPanel7inch/Starter_SquareLineUX/src/ui.c"
click node_eez_ui "https://github.com/ddehimer/elbdisplay/blob/main/CrowPanel7inch/Starter_EEZ-Open/src/ui/ui.c"
click node_esp_board "https://github.com/ddehimer/elbdisplay/blob/main/CrowPanel7inch/BoardDefinition/esp32-s3-devkitc-1-myboard.json"
click node_shared_widgets "https://github.com/ddehimer/elbdisplay/blob/main/CrowPanel7inch/Starter_SquareLineUX/components/LabelCount.ecomp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_readme toneBlue
class node_rp_main,node_rp_control,node_adc_driver,node_dac_driver,node_temp_driver,node_rp_tests toneAmber
class node_esp_main,node_uart_link,node_data_model,node_sd_export,node_lgfx,node_esp_board,node_shared_widgets toneMint
class node_sq_ui,node_eez_ui toneRose
```

## Components

### Repository

Two-MCU embedded system plus ESP32 UI tooling

- [Architecture](https://github.com/ddehimer/elbdisplay/blob/main/README.md): contract · Cross-device system boundary and UART protocol · `README.md`

### RP2040 firmware

Real-time sensing and control node

- [Main loop](https://github.com/ddehimer/elbdisplay/blob/HEAD/RP2040%20Code/main.py): micropython runtime · Entry point for acquisition and control state machine · `RP2040 Code/main.py`
- [Control logic](https://github.com/ddehimer/elbdisplay/blob/HEAD/RP2040%20Code/current_control.py): state machine · Non-blocking control and command handling · `RP2040 Code/current_control.py`
- [ADC driver](https://github.com/ddehimer/elbdisplay/blob/HEAD/RP2040%20Code/drivers/ads1115.py): sensor interface · I2C ADC acquisition from measurement hardware · `RP2040 Code/drivers/ads1115.py`
- [Output control](https://github.com/ddehimer/elbdisplay/blob/HEAD/RP2040%20Code/drivers/current_dac.py): actuator driver · Current and output control interface · `RP2040 Code/drivers/current_dac.py`
- [Temp sensing](https://github.com/ddehimer/elbdisplay/blob/HEAD/RP2040%20Code/drivers/temperature.py): sensor driver · Temperature measurement support · `RP2040 Code/drivers/temperature.py`
- [RP2040 tests](https://github.com/ddehimer/elbdisplay/blob/HEAD/RP2040%20Code/uart_test.py): test scripts · Standalone UART and sensor checks used during development · `RP2040 Code/uart_test.py`

### ESP32 display

UI, operator control, and logging node

- [App entry](https://github.com/ddehimer/elbdisplay/blob/main/CrowPanel7inch/Starter_SquareLineUX/src/main.cpp): platformio app · ESP32 display firmware entry point · `CrowPanel7inch/Starter_SquareLineUX/src/main.cpp`
- [UART link](https://github.com/ddehimer/elbdisplay/blob/main/CrowPanel7inch/Starter_SquareLineUX/src/uart_link.cpp): serial protocol · Line-delimited ASCII telemetry and commands · `CrowPanel7inch/Starter_SquareLineUX/src/uart_link.cpp`
- [Data model](https://github.com/ddehimer/elbdisplay/blob/main/CrowPanel7inch/Starter_SquareLineUX/src/data_model.cpp): ui state · Parsed telemetry and UI-facing state · `CrowPanel7inch/Starter_SquareLineUX/src/data_model.cpp`
- [CSV export](https://github.com/ddehimer/elbdisplay/blob/main/CrowPanel7inch/Starter_SquareLineUX/src/sd_export.cpp): storage · Session logging to SD card · `CrowPanel7inch/Starter_SquareLineUX/src/sd_export.cpp`
- [Display driver](https://github.com/ddehimer/elbdisplay/blob/main/CrowPanel7inch/Starter_SquareLineUX/src/lgfx/lgfx.cpp): graphics backend · LovyanGFX-style display and touch backend · `CrowPanel7inch/Starter_SquareLineUX/src/lgfx/lgfx.cpp`
- [Board setup](https://github.com/ddehimer/elbdisplay/blob/main/CrowPanel7inch/BoardDefinition/esp32-s3-devkitc-1-myboard.json): board target · ESP32-S3 board definition and install scripts · `CrowPanel7inch/BoardDefinition/esp32-s3-devkitc-1-myboard.json`
- [Custom widgets](https://github.com/ddehimer/elbdisplay/blob/main/CrowPanel7inch/Starter_SquareLineUX/components/LabelCount.ecomp): ui components · Reusable widget and sensor-oriented component library · `CrowPanel7inch/Starter_SquareLineUX/components/LabelCount.ecomp`

### UI variants

Alternative front-end implementations for the ESP32

- [SquareLine UI](https://github.com/ddehimer/elbdisplay/blob/main/CrowPanel7inch/Starter_SquareLineUX/src/ui.c): generated ui · Generated LVGL screens and event wiring · `CrowPanel7inch/Starter_SquareLineUX/src/ui.c`
- [EEZ Open UI](https://github.com/ddehimer/elbdisplay/blob/main/CrowPanel7inch/Starter_EEZ-Open/src/ui/ui.c): generated ui · Alternative LVGL UI project built from EEZ assets · `CrowPanel7inch/Starter_EEZ-Open/src/ui/ui.c`

## Connections

- Architecture → Main loop: defines · Documents RP2040 runtime role
- Architecture → App entry: defines · Documents ESP32 runtime role
- Main loop → Control logic: uses · Main loop drives state transitions
- Main loop → ADC driver: reads · Samples measurement hardware
- Main loop → Output control: controls · Drives current/output hardware
- Main loop → Temp sensing: reads · Monitors temperature channels
- Control logic → UART link: streams · Emits telemetry and accepts commands
- ADC driver → UART link: feeds · Acquired data is packaged for transport
- Temp sensing → UART link: feeds · Environmental data enters telemetry stream
- UART link → Data model: parses · Converts ASCII lines into UI state
- App entry → Display driver: renders · Initializes display and touch backend
- App entry → SquareLine UI: hosts · Runs the SquareLine-generated interface
- App entry → EEZ Open UI: alternative · Parallel EEZ Open front-end variant
- SquareLine UI → UART link: sends · Operator actions become UART commands
- SquareLine UI → CSV export: logs · UI triggers session CSV writing
- Data model → SquareLine UI: updates · Telemetry refreshes screen state
- CSV export → App entry: persists · Storage remains on ESP32 side
- Board setup → App entry: targets · Board definition configures firmware build
- Custom widgets → SquareLine UI: extends · Reusable components support the UI
- Custom widgets → EEZ Open UI: extends · Reusable components support the alternate UI
- RP2040 tests → Main loop: exercises · Development scripts validate runtime behavior
