# tatobari/hx711py architecture

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

- Interactive diagram: https://gitdiagram.com/tatobari/hx711py
- Repository: https://github.com/tatobari/hx711py

## Overview

##### Main Components

a) Hardware Layer:
- HX711 ADC Load Cell Amplifier
- Load Cell Sensor
- Raspberry Pi GPIO Interface

b) Software Layer:
- Two Main Implementation Versions:
- Legacy Version (hx711.py)
- Modern Version (hx711v0_5_1.py)
- Emulator Component (hx711_emulator.py)

##### Physical Layer
- HX711's two channels (A & B) with their respective gains:
- Channel A: 128/64 gain options
- Channel B: Fixed 32 gain

##### Communication Layer
- GPIO pins connection between HX711 and Raspberry Pi
- Bi-directional data flow:
- Clock signal (output from Pi)
- Data signal (input to Pi)

##### Software Layer
- Split into two parallel implementations:

a) Modern Implementation (v0.5.1):
- Two operation modes:
- Interrupt-based path
- Polling-based path
- 10 SPS (Samples Per Second) timing

b) Legacy Implementation:
- Slower 1 SPS operation
- Channel switching capability

##### Testing/Simulation Layer
- Emulator component
- How it can replace the hardware layer for testing

Use these visual elements:

- Blue: Hardware components
- Green: Software components
- Yellow: Communication interfaces
- Red: Critical timing-sensitive paths

Important Notes to Include:

1. A warning symbol near the timing-sensitive operations, indicating the potential issues with Linux-based timing
##### Gain settings for different channels

Special Considerations:

## Diagram (Mermaid)

```mermaid
graph TB
    %% Define styles
    classDef hardware fill:#b3d9ff,stroke:#333
    classDef software fill:#90EE90,stroke:#333
    classDef interface fill:#FFE5B4,stroke:#333
    classDef critical fill:#FFB6C1,stroke:#333
    classDef warning fill:#FFD700,stroke:#333

    %% Hardware Layer
    subgraph Physical
        LC[Load Cell Sensor]:::hardware
        HX[HX711 ADC]:::hardware
        LC --> HX
        
        subgraph "HX711 Channels"
            CHA["Channel A<br/>(Gain: 128/64)"]:::hardware
            CHB["Channel B<br/>(Gain: 32)"]:::hardware
        end
        
        HX --> CHA
        HX --> CHB
    end

    %% Communication Layer
    subgraph Interface
        GPIO["Raspberry Pi GPIO Interface"]:::interface
        CLOCK["Clock Signal<br/>(Output)"]:::interface
        DATA["Data Signal<br/>(Input)"]:::interface
    end

    HX <--> GPIO
    GPIO --- CLOCK
    GPIO --- DATA

    %% Software Layer
    subgraph Implementation
        MODERN["Modern Implementation<br/>(10 SPS)"]:::software
        LEGACY["Legacy Implementation<br/>(1 SPS)"]:::software
        
        subgraph "Modern Operation Modes"
            INT["Interrupt-based"]:::software
            POLL["Polling-based"]:::software
        end
        
        MODERN --> INT
        MODERN --> POLL
    end

    GPIO --> MODERN
    GPIO --> LEGACY

    %% Testing Layer
    EMU["HX711 Emulator"]:::software
    EMU -.-> GPIO

    %% Warning Notes
    WARNING["⚠️ Timing Critical:<br/>Linux-based timing limitations"]:::warning

    %% Component Mappings
    click LEGACY "https://github.com/tatobari/hx711py/blob/master/hx711.py"
    click MODERN "https://github.com/tatobari/hx711py/blob/master/hx711v0_5_1.py"
    click EMU "https://github.com/tatobari/hx711py/blob/master/hx711_emulator.py"

    %% Legend
    subgraph Legend
        L1["Hardware Component"]:::hardware
        L2["Software Component"]:::software
        L3["Interface Component"]:::interface
        L4["Critical Path"]:::critical
        L5["Warning"]:::warning
    end
```
