# doohans/arduino_surface_tx_4ch architecture

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

- Interactive diagram: https://gitdiagram.com/doohans/arduino_surface_tx_4ch
- Repository: https://github.com/doohans/arduino_surface_tx_4ch

## Overview

##### Project Type and Purpose
- This is an embedded Arduino project focused on implementing a surface transmitter (TX) for RC surface vehicles like cars or boats.
- Its purpose is to manage different aspects of a RC transmitter—reading button inputs, performing calibrations, displaying information on an LCD screen, generating PPM output for remote control, monitoring battery voltage, and storing persistent configuration via EEPROM.
- The README explains its key modifications (model naming, exponential curves, endpoint adjustments, calibration routines, error prevention for EEPROM wear, etc.) and how it interfaces with an external multiprotocol PPM module.

##### File Structure
- The project’s root contains documentation folders (Doc, Images) and a central README.
- The main code lives in the “SurfTX_4CH” directory with multiple .ino files, each focusing on a particular module of the firmware (e.g., Battery.ino, Buttons.ino, Screen.ino, Calibration.ino, etc.). This clear separation by file indicates a modular design approach.
- There is also a header file “Config.h” for configuration and constant definition.
- This separation suggests the design divides system functionality into independent yet interacting components.

##### Main Components
a. Core Control Unit (Arduino Microcontroller):
- Represents the processing unit running the firmware.
b. User Interface Subsystem:
- LCD Display (12864-06d LCD screen)
- Button Inputs (UP, SELECT, DOWN, D/R button handling)
- Buzzer output for alarms and feedback.
c. Calibration Module:
- Handles the Two-step calibration procedures (range and center calibration).
- Likely interconnects with both the UI (buttons, screen) and the stored configurations.
d. Signal Generation Subsystem:
- PPM Output generation via modules like “PPM_Channels.ino” and “PPM_Output.ino.”
- Represents the communication interface to the external multiprotocol TX module.
e. Power/Battery Management:
- Battery monitoring code (Battery.ino, Read_ADC.ino) to read and interpret analog battery voltage.
- Low voltage alarm configuration using fixed thresholds.
f. Memory and Configuration Persistence:
- EEPROM handling (Eeprom.ino) for saving calibration settings, model names, and other customizations.
- “Config.h” acting as a central configuration resource.
g. Additional Functional Modules:
- Expo adjustments (Expo.ino)
- Switches and Buttons functionalities (Switches.ino, Buttons.ino)

##### Relationships and Interactions
- The main loop (SurfTX_4CH.ino) coordinates the operation of all modules.
- Button presses trigger calibration routines, change model settings, or update the UI on the LCD screen.
- Battery and ADC readings inform both the UI (by alerting low-voltage conditions with a buzzer) and calibration logic.
- The PPM channel and output modules work in tandem to compute and issue signal outputs, referencing data from calibration results and user inputs.
- EEPROM access interplays with system configuration to ensure settings persist across power cycles.

##### Architectural Patterns and Design Principles
- Modular Design: Each .ino file holds a clearly separated functionality, making it easier to view independent modules.
- Event-Driven/UI Loop: The control flow is likely organized around a main loop reacting to button events and sensor inputs.
- Hardware Abstraction: Clearly distinct modules for hardware interfaces (ADC, PPM output, LCD display) which abstract the underlying circuitry.
- Data Flow: Input devices (buttons, battery sensors) feed data into processing routines that update visual displays and signal outputs.

- Optionally, include annotations or notes on key functions like “Calibration Routine” which involves two steps managed via button inputs, or “low voltage alarm configuration” in the Battery module.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Control Unit
    M["Main Loop (SurfTX_4CH.ino)"]:::core

    %% User Interface Subsystem
    subgraph "User Interface Subsystem"
        UI1["LCD Display"]:::ui
        UI2["Button Input & Handling"]:::ui
        UI3["Buzzer"]:::ui
    end

    %% Signal Generation Subsystem
    subgraph "Signal Generation Subsystem"
        P1["PPM Channels"]:::sig
        P2["PPM Output"]:::sig
    end

    %% Other Modules
    Cal["Calibration Module"]:::cal
    Batt["Battery Monitor"]:::batt
    Mem["EEPROM & Config"]:::mem
    Expo["Expo Adjustments"]:::expo

    %% Interconnections and Data Flow
    M -->|"controls"| UI1
    M -->|"monitors"| UI2
    M -->|"activates"| UI3
    UI2 -->|"triggers"| Cal
    M -->|"initiates"| Cal
    Cal -->|"updates"| Mem
    Mem -->|"provides_config"| M
    Mem -->|"configures"| Cal
    Batt -->|"voltage_data"| M
    Batt -->|"alerts"| UI3
    M -->|"generates"| P1
    M -->|"generates"| P2
    Expo -->|"adjusts"| P1

    %% Click Events
    click M "https://github.com/doohans/arduino_surface_tx_4ch/blob/master/SurfTX_4CH/SurfTX_4CH.ino"
    click UI1 "https://github.com/doohans/arduino_surface_tx_4ch/blob/master/SurfTX_4CH/Screen.ino"
    click UI2 "https://github.com/doohans/arduino_surface_tx_4ch/blob/master/SurfTX_4CH/Buttons.ino"
    click UI2 "https://github.com/doohans/arduino_surface_tx_4ch/blob/master/SurfTX_4CH/Switches.ino"
    click UI3 "https://github.com/doohans/arduino_surface_tx_4ch/blob/master/SurfTX_4CH/Buzzer.ino"
    click Cal "https://github.com/doohans/arduino_surface_tx_4ch/blob/master/SurfTX_4CH/Calibration.ino"
    click P1 "https://github.com/doohans/arduino_surface_tx_4ch/blob/master/SurfTX_4CH/PPM_Channels.ino"
    click P2 "https://github.com/doohans/arduino_surface_tx_4ch/blob/master/SurfTX_4CH/PPM_Output.ino"
    click Batt "https://github.com/doohans/arduino_surface_tx_4ch/blob/master/SurfTX_4CH/Battery.ino"
    click Batt "https://github.com/doohans/arduino_surface_tx_4ch/blob/master/SurfTX_4CH/Read_ADC.ino"
    click Mem "https://github.com/doohans/arduino_surface_tx_4ch/blob/master/SurfTX_4CH/Eeprom.ino"
    click Mem "https://github.com/doohans/arduino_surface_tx_4ch/blob/master/SurfTX_4CH/Config.h"
    click Expo "https://github.com/doohans/arduino_surface_tx_4ch/blob/master/SurfTX_4CH/Expo.ino"

    %% Styling
    classDef core fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef ui fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef cal fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef sig fill:#FFA500,stroke:#000,stroke-width:2px;
    classDef batt fill:#FFFF99,stroke:#000,stroke-width:2px;
    classDef mem fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef expo fill:#DA70D6,stroke:#000,stroke-width:2px;
```
