# lorenzopalaia/arduino-oscilloscope architecture

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

- Interactive diagram: https://gitdiagram.com/lorenzopalaia/arduino-oscilloscope
- Repository: https://github.com/lorenzopalaia/arduino-oscilloscope

## Overview

##### Main Components
a. Arduino Firmware:
- Divided across the “avr_common” and “avr_src” directories.
- The “avr_common” directory includes shared source files such as ADC and UART interrupt code, along with configuration (avrdude.conf and avr.mk).
- The “avr_src” directory contains the main firmware (arduino.c) and a Makefile to build/upload the firmware.
- Implements two sampling modes (continuous and buffered) and uses interrupts to time the sampling and communication events.
b. PC Client Application:
- The “client_src” directory contains client.c which is responsible for configuring the serial port, transmitting configuration parameters to Arduino, and receiving ADC samples.
- Handles user input, error checking, serial communication using termios, and writing the received data into output files (located in the “outputs” folder), one per channel.
c. Visualization Component:
- The project uses Gnuplot for graphing the sampled data at client termination.
- The shell script “run.sh” ties the build process and integrates Gnuplot into the workflow.
d. Additional Assets & Configuration:
- The provided LICENSE.txt and README.md serve documentation purposes.

##### Relationships and Data Flows
a. Interaction between Arduino and Client:
- That parameters (sampling frequency, sample size, selected channels) are sent from the client to the Arduino and ADC values are sent back.
b. Client to Gnuplot:
c. Hardware and External Interactions:
- An “Arduino Hardware” block that connects the firmware implementation to the physical sensors (potentiometer, ADC channels) and to the PC via a USB/serial port.

##### Architectural Patterns and Design Principles
a. Separation of Concerns:
- That the firmware and client code are neatly split (embedded vs. PC application factors), each with its own build process (Makefiles in “avr_src” and “avr_common”, possibly a separate compile process for “client_src”).
b. Interrupt-driven processing in the firmware: clearly indicate the role of interrupts in managing ADC sampling and communication.
c. Reliable I/O Handling:
- The client application ensures robust file I/O operations and serial communications, including proper error handling and resource cleanup during termination.
d. External Data Visualization:
- Gnuplot integration is a key design choice for real-time graphing, ensuring users can immediately view oscilloscope outputs.

##### Relevant Technologies & Libraries
- Arduino, AVR C, and use of Makefiles for firmware builds.
- C programming for the client application including termios for handling serial port I/O.
- GNUplot for rendering output graphs.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Embedded Layer
    subgraph "Embedded Layer"
        HW["Arduino Hardware"]:::hardware
        subgraph "Arduino Firmware"
            subgraph "avr_common"
                AC_adc["adc.c"]:::embedded
                AC_uart["uartINT.c"]:::embedded
                AC_conf["avrdude.conf"]:::embedded
                AC_mk["avr.mk"]:::embedded
            end
            subgraph "avr_src"
                AS_arduino["arduino.c"]:::embedded
                AS_Makefile["Makefile"]:::embedded
            end
        end
    end

    %% PC Client Application Layer
    subgraph "PC Client Application"
        PC_client["client.c"]:::client
        PC_outputs["outputs"]:::client
    end

    %% Visualization & Documentation Layer
    subgraph "Visualization & Documentation"
        VS_run["run.sh"]:::vis
        subgraph "Documentation & Assets"
            DOC_repo["repo_assets"]:::docs
            DOC_readme["README.md"]:::docs
            DOC_license["LICENSE.txt"]:::docs
        end
    end

    %% Connections between layers
    HW -->|"USB/Serial"| AS_arduino
    PC_client -->|"ControlCommands"| AS_arduino
    AS_arduino -->|"ADCData"| PC_client
    PC_client -->|"LogData"| PC_outputs
    PC_client -->|"TriggerPlot"| VS_run

    %% Click Events for Arduino Firmware Files (avr_common)
    click AC_adc "https://github.com/lorenzopalaia/arduino-oscilloscope/blob/main/avr_common/adc.c"
    click AC_uart "https://github.com/lorenzopalaia/arduino-oscilloscope/blob/main/avr_common/uartINT.c"
    click AC_conf "https://github.com/lorenzopalaia/arduino-oscilloscope/blob/main/avr_common/avrdude.conf"
    click AC_mk "https://github.com/lorenzopalaia/arduino-oscilloscope/blob/main/avr_common/avr.mk"

    %% Click Events for Arduino Firmware Files (avr_src)
    click AS_arduino "https://github.com/lorenzopalaia/arduino-oscilloscope/blob/main/avr_src/arduino.c"
    click AS_Makefile "https://github.com/lorenzopalaia/arduino-oscilloscope/tree/main/avr_src/Makefile"

    %% Click Events for PC Client Application
    click PC_client "https://github.com/lorenzopalaia/arduino-oscilloscope/blob/main/client_src/client.c"
    click PC_outputs "https://github.com/lorenzopalaia/arduino-oscilloscope/tree/main/outputs"

    %% Click Event for Visualization Component
    click VS_run "https://github.com/lorenzopalaia/arduino-oscilloscope/blob/main/run.sh"

    %% Click Events for Documentation & Assets
    click DOC_repo "https://github.com/lorenzopalaia/arduino-oscilloscope/tree/main/repo_assets"
    click DOC_readme "https://github.com/lorenzopalaia/arduino-oscilloscope/blob/main/README.md"
    click DOC_license "https://github.com/lorenzopalaia/arduino-oscilloscope/blob/main/LICENSE.txt"

    %% Styles
    classDef embedded fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef client fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef vis fill:#ffcccb,stroke:#000,stroke-width:2px;
    classDef docs fill:#ffffe0,stroke:#000,stroke-width:2px;
    classDef hardware fill:#d3d3d3,stroke:#000,stroke-width:2px;
```
