# robtillaart/hx711 architecture

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

- Interactive diagram: https://gitdiagram.com/robtillaart/hx711
- Repository: https://github.com/robtillaart/hx711

## Overview

##### Main Components

a. Hardware Layer:
- HX711 ADC Chip
- Load Cell Sensors
- Arduino/Microcontroller
- Connection pins (DATA, CLOCK)

b. Software Layer:
- HX711 Library Core
- Reading Modes Module
- Calibration Module
- Power Management Module
- Channel/Gain Control

**[Physical Layer]**
- Load Cell → HX711 ADC → Arduino
- ↑
**[Hardware Interface Layer]**
- Data Pin ←→ Clock Pin
- ↑
**[Core Library Layer]**
- HX711 Class

- ┌────┴────────────────┐
- ↓         ↓           ↓
**[Functional Modules]**

##### Component Details

a. Core Library Module (HX711 Class):
- Main methods:
- begin()
- read()
- get_value()
- get_units()

b. Reading Modes Module:
- As a connected component
- Modes:
- Raw
- Average
- Median
- Running Average

c. Calibration Module:
- Include:
- Tare functionality
- Scale calibration
- Offset management

d. Hardware Interface:
- Pin connections
- Channel selection (A/B)
- Gain settings (32/64/128)

##### Data Flow Indicators

- Raw data flow from sensor → ADC → Library
- Configuration flow from Library → ADC
- Processed data flow to user application

##### Implementation Details

Implementation features:
- 24-bit ADC resolution
- Float-based calculations
- Sampling rates (10/80 SPS)
- Gain selection impact

- The hardware-software interface
- Data processing pipeline
- Calibration workflow
- Multiple reading modes
- Error handling paths

Remember to:
- Keep hardware connections clear
- Data transformation stages
- Configuration points
- Critical timing paths
- Power management states

This system design should help developers understand both the hardware interaction and software processing aspects of the HX711 library, making it easier to implement and maintain the system.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Hardware
        LC[Load Cell]:::hardware
        ADC[HX711 ADC]:::hardware
        MCU[Arduino/MCU]:::hardware
        LC --> ADC
        ADC --> MCU
    end

    subgraph "Hardware Interface"
        DP["Data Pin"]:::interface
        CP["Clock Pin"]:::interface
        ADC --- DP
        ADC --- CP
    end

    subgraph "Core Library"
        HC["HX711 Core"]:::core
        click HC "https://github.com/RobTillaart/HX711/blob/master/HX711.cpp"
        HC --- DP
        HC --- CP
    end

    subgraph "Functional Modules"
        RM["Reading Modes"]:::module
        click RM "https://github.com/RobTillaart/HX711/blob/master/examples/HX_set_mode/HX_set_mode.ino"
        
        CM["Calibration"]:::module
        click CM "https://github.com/RobTillaart/HX711/blob/master/examples/HX_calibration/HX_calibration.ino"
        
        PM["Power Management"]:::module
        CG["Channel/Gain Control"]:::module
        
        DA["Data Analysis"]:::module
        click DA "https://github.com/RobTillaart/HX711/blob/master/examples/HX_get_noise_statistics/HX_get_noise_statistics.ino"
        
        MS["Multiple Sensors"]:::module
        click MS "https://github.com/RobTillaart/HX711/blob/master/examples/HX_loadcell_array/HX_loadcell_array.ino"
        
        TF["Testing Framework"]:::module
        click TF "https://github.com/RobTillaart/HX711/blob/master/test/unit_test_001.cpp"
    end

    subgraph "Reading Methods"
        Raw["Raw Reading"]:::method
        Avg["Average"]:::method
        Med["Median"]:::method
        click Med "https://github.com/RobTillaart/HX711/blob/master/examples/HX_read_median/HX_read_median.ino"
        RunAvg["Running Average"]:::method
    end

    subgraph "Example Applications"
        KS["Kitchen Scale"]:::app
        click KS "https://github.com/RobTillaart/HX711/blob/master/examples/HX_kitchen_scale/HX_kitchen_scale.ino"
        GS["Grocery Scale"]:::app
        click GS "https://github.com/RobTillaart/HX711/blob/master/examples/HX_grocery_scale/HX_grocery_scale.ino"
        Perf["Performance Monitor"]:::app
        click Perf "https://github.com/RobTillaart/HX711/blob/master/examples/HX_performance/HX_performance.ino"
    end

    HC --> RM
    HC --> CM
    HC --> PM
    HC --> CG
    HC --> DA
    HC --> MS
    HC --> TF

    RM --> Raw
    RM --> Avg
    RM --> Med
    RM --> RunAvg

    CM --> KS
    CM --> GS
    DA --> Perf

    classDef hardware fill:#a8d1f0
    classDef interface fill:#ffd700
    classDef core fill:#90EE90
    classDef module fill:#FFB6C1
    classDef method fill:#DDA0DD
    classDef app fill:#98FB98

    %% Legend
    subgraph Legend
        H1[Hardware]:::hardware
        I1[Interface]:::interface
        C1[Core]:::core
        M1[Modules]:::module
        MT1[Methods]:::method
        A1[Applications]:::app
    end
```
