FarmBot/farmbot-arduino-firmware

Arduino firmware that executes g-code like commands over a serial line to move the FarmBot and operate the tool mount

What it solves

This firmware runs on the Arduino Mega 2560 inside a FarmBot, a precision farming robot. It acts as the robot's motor controller and pin interface. The Raspberry Pi sends G-Code commands over a serial connection, and this firmware interprets them to move the robot's X, Y, and Z axes, read sensors, control water valves, and report status back to the Pi. Without this firmware, the Pi would have no way to translate high-level instructions into physical motion.

How it works

The firmware is written in the Arduino language (a C++ variant) and is organized around a main loop that reads incoming commands. The flow is: the controller receives a G-Code or Farm-command, processes it, and then dispatches to the appropriate handler, such as Movement (for axis motion) or PinControl (for reading/writing Arduino pins). It supports a wide set of standardized G-Codes (like G00 for absolute movement, G28 for homing) and Farm-specific commands (like F22 to write parameters, F41 to set a pin value). It also sends report messages (R codes) back to the Pi to indicate idle, command success, errors, axis states, and calibration progress.

Key details: the firmware requires configuration approval before it will move (send F22 P2 V1 Q0). It supports multiple FarmBot board versions (RAMPS, FARMDUINO, Express) with different capabilities like encoders, stall detection, and current sensors. Developers can compile and upload it using Arduino IDE, Make, or VSCode. The firmware is bundled automatically into FarmBot OS, but can be developed independently.

Who it's for

This project is for developers, hobbyists, or researchers working with FarmBot hardware who want to customize or extend the low-level control firmware. It's also useful for anyone studying how Arduino firmware handles G-Code parsing and motor control for CNC or 3D printer-like systems. The README assumes familiarity with Arduino programming, G-Codes, and basic electronics.

Highlights

  • Acts as the brain between the Raspberry Pi and the FarmBot's motors, sensors, and pins.
  • Supports a comprehensive set of G-Codes and custom Farm commands for motion, homing, calibration, pin I/O, and parameter tuning.
  • Reports status back to the Pi with detailed error codes, axis states, and calibration progress.
  • Designed for multiple board versions, from basic RAMPS to advanced FARMDUINO with encoders and stall detection.
  • Includes a large parameter list (200+ settings) for tuning movement speeds, acceleration, encoder behavior, and pin guards.
  • Can be compiled with Arduino IDE, Make (Linux), or VSCode, and can be run as an independent project outside FarmBot OS.

Related

  • Project
  • Project
  • Project
  • Project