# farmbot/farmbot-arduino-firmware architecture

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

- Interactive diagram: https://gitdiagram.com/farmbot/farmbot-arduino-firmware
- Repository: https://github.com/farmbot/farmbot-arduino-firmware

## Overview

This is FarmBot’s Arduino firmware: it receives G-code commands from a Raspberry Pi, executes motion and device-control operations, and reports results over the serial protocol. The documented runtime path runs from controller input through command parsing and G-code dispatch to command handlers, then to motion or pin control. Handlers cover movement, homing/calibration, configuration, reports, pins, and servos. The graph preserves substantial indexed modules; unsampled dispatch and hardware details are shown only where the README or indexed references support them.

Main entry points: [`src/Movement.cpp`](https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/Movement.cpp) (Movement planner), [`src/farmbot_arduino_controller.cpp`](https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/farmbot_arduino_controller.cpp) (Firmware controller), [`src/GCodeHandler.h`](https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/GCodeHandler.h) (Command handlers), [`src/GCodeProcessor.cpp`](https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/GCodeProcessor.cpp) (G-code processor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_protocol["Serial command flow"]
  node_controller["Firmware controller"]
  node_command["Command parser<br/>[Command.h]"]
  node_processor["G-code processor<br/>[GCodeProcessor.cpp]"]
  node_serial_result["Serial reports"]
end

subgraph group_commands["Command capabilities"]
  node_handler["Command handlers<br/>[GCodeHandler.h]"]
  node_motion_commands["Move and home<br/>[G00Handler.cpp]"]
  node_calibration["Home and calibrate<br/>[F11Handler.cpp]"]
  node_parameters["Parameter commands<br/>[ParameterList.cpp]"]
  node_pin_commands["Pin commands<br/>[F41Handler.cpp]"]
  node_servo["Servo commands<br/>[F61Handler.cpp]"]
  node_reports["Status reports<br/>[F81Handler.cpp]"]
end

subgraph group_motion["Motion control"]
  node_movement["Movement planner<br/>[Movement.cpp]"]
  node_axis["Axis control<br/>[MovementAxis.cpp]"]
  node_encoder["Encoder tracking"]
  node_timer["Movement timer<br/>[TimerOne.cpp]"]
  node_drivers["TMC2130 drivers<br/>[TMC2130.cpp]"]
end

subgraph group_state["State and hardware"]
  node_pincontrol["Pin control<br/>[PinControl.h]"]
  node_pingguard["Pin guard<br/>[PinGuard.h]"]
  node_currentstate["Current state<br/>[CurrentState.cpp]"]
  node_statuslist["Status values<br/>[StatusList.h]"]
  node_config["Firmware configuration<br/>[Config.h]"]
  node_board["Board pin mapping<br/>[pins.h]"]
end

node_raspberry(("Raspberry Pi"))

node_raspberry -->|"sends G-code"| node_controller
node_controller -->|"creates command"| node_command
node_controller -->|"submits command"| node_processor
node_command -->|"parsed command"| node_processor
node_processor -->|"dispatches command"| node_handler
node_handler -->|"invokes motion"| node_movement
node_handler -->|"controls pins"| node_pincontrol
node_motion_commands -.->|"requests movement"| node_movement
node_calibration -->|"homes axes"| node_movement
node_controller -->|"checks changes"| node_parameters
node_movement -->|"uses axes"| node_axis
node_movement -->|"uses encoders"| node_encoder
node_movement -->|"updates state"| node_currentstate
node_movement -->|"reads settings"| node_parameters
node_controller -->|"configures timer"| node_timer
node_controller -->|"loads guard"| node_pingguard
node_controller -->|"prints reports"| node_serial_result
node_serial_result -->|"reports results"| node_raspberry
node_movement -.->|"configures drivers"| node_drivers
node_pin_commands -.->|"sets pin I/O"| node_pincontrol
node_servo -.->|"drives servo pins"| node_pincontrol

click node_controller "https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/farmbot_arduino_controller.cpp"
click node_command "https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/Command.h"
click node_processor "https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/GCodeProcessor.cpp"
click node_handler "https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/GCodeHandler.h"
click node_motion_commands "https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/G00Handler.cpp"
click node_calibration "https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/F11Handler.cpp"
click node_parameters "https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/ParameterList.cpp"
click node_pin_commands "https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/F41Handler.cpp"
click node_servo "https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/F61Handler.cpp"
click node_reports "https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/F81Handler.cpp"
click node_movement "https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/Movement.cpp"
click node_axis "https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/MovementAxis.cpp"
click node_encoder "https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/MovementEncoder.cpp"
click node_timer "https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/TimerOne.cpp"
click node_drivers "https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/TMC2130.cpp"
click node_pincontrol "https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/PinControl.h"
click node_pingguard "https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/PinGuard.h"
click node_currentstate "https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/CurrentState.cpp"
click node_statuslist "https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/StatusList.h"
click node_config "https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/Config.h"
click node_board "https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/pins.h"
click node_serial_result "https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/farmbot_arduino_controller.cpp"

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_controller,node_command,node_processor,node_serial_result toneBlue
class node_handler,node_motion_commands,node_calibration,node_parameters,node_pin_commands,node_servo,node_reports toneAmber
class node_movement,node_axis,node_encoder,node_timer,node_drivers toneMint
class node_pincontrol,node_pingguard,node_currentstate,node_statuslist,node_config,node_board toneRose
class node_raspberry toneIndigo
```

## Components

### Serial command flow

- [Firmware controller](https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/farmbot_arduino_controller.cpp): `src/farmbot_arduino_controller.cpp`
- [Command parser](https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/Command.h): `src/Command.h`
- [G-code processor](https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/GCodeProcessor.cpp): `src/GCodeProcessor.cpp`
- [Serial reports](https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/farmbot_arduino_controller.cpp): `src/farmbot_arduino_controller.cpp`

### Command capabilities

- [Command handlers](https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/GCodeHandler.h): `src/GCodeHandler.h`
- [Move and home](https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/G00Handler.cpp): `src/G00Handler.cpp`
- [Home and calibrate](https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/F11Handler.cpp): `src/F11Handler.cpp`
- [Parameter commands](https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/ParameterList.cpp): `src/ParameterList.cpp`
- [Pin commands](https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/F41Handler.cpp): `src/F41Handler.cpp`
- [Servo commands](https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/F61Handler.cpp): `src/F61Handler.cpp`
- [Status reports](https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/F81Handler.cpp): `src/F81Handler.cpp`

### Motion control

- [Movement planner](https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/Movement.cpp): `src/Movement.cpp`
- [Axis control](https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/MovementAxis.cpp): `src/MovementAxis.cpp`
- [Encoder tracking](https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/MovementEncoder.cpp): `src/MovementEncoder.cpp`
- [Movement timer](https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/TimerOne.cpp): `src/TimerOne.cpp`
- [TMC2130 drivers](https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/TMC2130.cpp): `src/TMC2130.cpp`

### State and hardware

- [Pin control](https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/PinControl.h): `src/PinControl.h`
- [Pin guard](https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/PinGuard.h): `src/PinGuard.h`
- [Current state](https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/CurrentState.cpp): `src/CurrentState.cpp`
- [Status values](https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/StatusList.h): `src/StatusList.h`
- [Firmware configuration](https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/Config.h): `src/Config.h`
- [Board pin mapping](https://github.com/farmbot/farmbot-arduino-firmware/blob/main/src/pins.h): `src/pins.h`

### Other components

- **Raspberry Pi**

## Connections

- Raspberry Pi → Firmware controller: sends G-code
- Firmware controller → Command parser: creates command (evidence: `src/farmbot_arduino_controller.cpp`)
- Firmware controller → G-code processor: submits command (evidence: `src/farmbot_arduino_controller.cpp`)
- Command parser → G-code processor: parsed command
- G-code processor → Command handlers: dispatches command
- Command handlers → Movement planner: invokes motion
- Command handlers → Pin control: controls pins
- Move and home → Movement planner: requests movement
- Home and calibrate → Movement planner: homes axes
- Firmware controller → Parameter commands: checks changes (evidence: `src/farmbot_arduino_controller.cpp`)
- Movement planner → Axis control: uses axes
- Movement planner → Encoder tracking: uses encoders
- Movement planner → Current state: updates state
- Movement planner → Parameter commands: reads settings
- Firmware controller → Movement timer: configures timer (evidence: `src/farmbot_arduino_controller.cpp`)
- Firmware controller → Pin guard: loads guard (evidence: `src/farmbot_arduino_controller.cpp`)
- Firmware controller → Serial reports: prints reports (evidence: `src/farmbot_arduino_controller.cpp`)
- Serial reports → Raspberry Pi: reports results
- Movement planner → TMC2130 drivers: configures drivers
- Pin commands → Pin control: sets pin I/O
- Servo commands → Pin control: drives servo pins
