How bdring/grbl_esp32 works
1. What this repo is
- This is the legacy Grbl_ESP32 firmware: a CNC motion controller for ESP32, built as an Arduino-style firmware project.
- The architecture is firmware-centric, not an application server: the ESP32 runs the control loop, serves a web UI, and drives motors/spindles/sensors directly.
2. Startup and top-level composition
- Grbl_Esp32/Grbl_Esp32.ino is the Arduino entrypoint.
- Core runtime orchestration lives in src/Grbl.cpp and the supporting modules around it (System, Protocol, Settings, Report, Exec).
- The project is configured through platformio.ini, but the codebase is structured for Arduino/ESP32 compilation.
3. Command ingress paths
- The firmware accepts commands from multiple front doors: USB/serial, Bluetooth serial, Wi‑Fi web UI, telnet, and SD card jobs.
- Those inputs converge into the same command-processing path via Protocol, Serial, WebUI/Commands, and related input buffering code.
- This means the architecture has a single motion/control core with several transport adapters.
4. Parsing, execution, and reporting pipeline
- G-code and real-time commands are parsed in GCode, with execution handled by Exec and coordinated by Protocol.
- Status, alarms, error text, and machine-state reporting are split into Report and Error.
- Settings, SettingsDefinitions, and ProcessSettings provide the configuration layer that feeds the runtime before motion is executed.
5. Motion control core
- Motion is staged through Planner and then emitted through Stepper/MotionControl.
- Jog handles interactive jogging, while Limits and Probe cover homing, limit switches, and probing.
- I2SOut indicates the step generation/output path is abstracted so the ESP32 can produce high-rate step signals without relying on the main control loop timing alone.
6. Hardware abstraction and machine profiles
- Pin mapping and board-specific behavior are separated into CPUMap, Pins, and Machine/MachineCommon.
- The src/Machines directory contains many predefined machine profiles, showing that “machine definition” is a first-class boundary in this firmware.
- The Custom directory and CustomCode.cpp support project-specific extensions without editing the core engine.
7. Motor subsystem
- Motors are modeled separately from axes, which is important because the firmware supports multiple motors per axis and dynamic remapping.
- src/Motors contains implementations for standard steppers, unipolar motors, servos, RC servos, null motors, Dynamixel, and Trinamic-based drivers.
- This layer is the bridge between the motion planner and the physical driver electronics.
8. Spindle and tool output subsystem
- Spindle/control output is abstracted behind Spindle with concrete implementations for PWM, relay, DAC/0-10V, VFDs, Huanyang, Teco, laser mode, and BESC-based brushless control.
- CoolantControl and UserOutput handle other machine outputs like coolant and auxiliary signals.
- This separation lets the same motion core drive both cutting spindles and nontraditional tools like lasers.
9. Connectivity and remote management
- The WebUI subtree is a substantial subsystem: it includes the HTTP server, authentication, configuration pages, JSON encoding, input buffering, notifications, Wi‑Fi services/config, telnet, and serial-to-socket bridging.
- WebServer, TelnetServer, Serial2Socket, WifiConfig, WifiServices, and NotificationsService form the network boundary.
- The embedded frontend assets are packaged in embedded/ and Grbl_Esp32/data, including compressed HTML/JS content served by the firmware.
10. Persistent state and job storage
- Machine settings are persisted through the Settings layer, while SD card support is isolated in SDCard.
- The firmware can run jobs from SD or via streamed commands, so storage is treated as an input source rather than a full filesystem application.
- The data/ and embedded/ assets support the on-device UI, while src/tests provides sample G-code and parser/spindle test inputs.
11. Safety and machine feedback
- Limits, Probe, Exec, System, and CoolantControl together implement the runtime safety behavior: homing, limit handling, feed hold/resume, door/probe interactions, and abort states.
- The architecture clearly separates time-sensitive motion from asynchronous safety/IO monitoring, which is important for diagramming control boundaries.
12. External/library boundaries
- The repo vendors its key dependencies under libraries/, notably arduinoWebSockets and ESP32SSDP, which support the network/web UI features.
- This is not a generic app with many third-party services; the important external dependency boundary is mainly the ESP32 Arduino runtime plus these embedded networking libraries.
13. Customization and extension points
- The Custom folder and src/user_io.md/custom machine headers show explicit extension hooks for machine-specific behavior, custom kinematics, macros, and startup/shutdown sequences.
- Architecturally, these are plug-in style modules sitting beside the core rather than inside it, which is why the repo contains many named machine profiles and custom examples.
14. Build/test/tooling
- The repository includes scripting for builds and machine conversion (build-all.*, build-machine.py, configure-features.py, GitHub workflows).
- Docs and scripts under doc/ and the test G-code files under src/tests indicate the project is validated through firmware compilation plus command/G-code behavior checks, not through a separate application test harness.
Main entry points: Exec.cpp Exec · Protocol.cpp Protocol · Grbl.cpp Grbl · Planner.cpp Planner
Components 29
Core Runtime
Startup, command processing, settings, reporting, and execution flow.
- Entry · Arduino firmware entrypoint.
Grbl_Esp32/Grbl_Esp32.ino - Grbl · Top-level firmware runtime coordination.
Grbl_Esp32/src/Grbl.cpp - Protocol · Routes incoming commands and real-time events.
Grbl_Esp32/src/Protocol.cpp - Exec · Executes machine actions and state transitions.
Grbl_Esp32/src/Exec.cpp - Settings · Persistent machine configuration and runtime settings.
Grbl_Esp32/src/Settings.cpp - Report · Machine status, alarms, and messages.
Grbl_Esp32/src/Report.cpp - Error · Error text and fault reporting helpers.
Grbl_Esp32/src/Error.cpp - GCode · Parses G-code and realtime commands.
Grbl_Esp32/src/GCode.cpp - Process Settings · Applies defaults and machine settings at startup.
Grbl_Esp32/src/ProcessSettings.cpp
Motion Stack
Planning, step generation, jogging, probing, and safety limits.
- Planner · Buffers and plans coordinated motion.
Grbl_Esp32/src/Planner.cpp - Stepper · Generates step timing and motion stepping.
Grbl_Esp32/src/Stepper.cpp - Motion Control · Coordinates motion pipeline and timing-sensitive control.
Grbl_Esp32/src/MotionControl.cpp - I2S Out · High-rate step output backend.
Grbl_Esp32/src/I2SOut.cpp - Limits · Homing and limit switch handling.
Grbl_Esp32/src/Limits.cpp - Probe · Probing and probe-trigger logic.
Grbl_Esp32/src/Probe.cpp - Jog · Interactive jogging support.
Grbl_Esp32/src/Jog.cpp
Hardware Abstraction
Machine profiles, pins, motors, spindles, and outputs.
- CPU Map · Board-specific pin and CPU mapping.
Grbl_Esp32/src/CPUMap.h - Machines · Predefined machine profiles and kinematics.
Grbl_Esp32/src/Machines - Pins · Pin assignment and hardware signal mapping.
Grbl_Esp32/src/Pins.cpp - Motors · Motor abstractions and driver implementations.
Grbl_Esp32/src/Motors/Motors.cpp - Spindle · Spindle, laser, and VFD output control.
Grbl_Esp32/src/Spindles/Spindle.cpp - Aux Outputs · Coolant and user-defined auxiliary outputs.
Grbl_Esp32/src/CoolantControl.cpp - Custom Code · Project-specific behavior and machine extensions.
Grbl_Esp32/src/CustomCode.cpp
Connectivity
Web UI, network services, and command ingress adapters.
- WebUI · HTTP and web control subsystem.
Grbl_Esp32/src/WebUI/WebServer.cpp - Telnet · Telnet command ingress and session handling.
Grbl_Esp32/src/WebUI/TelnetServer.cpp - Serial · USB/serial transport and streaming.
Grbl_Esp32/src/Serial.cpp - Wi-Fi · Wi-Fi configuration and network services.
Grbl_Esp32/src/WebUI/WifiServices.cpp
Storage & Assets
Persistent settings, SD jobs, and embedded UI assets.
- SD Card · SD-based job input and storage access.
Grbl_Esp32/src/SDCard.cpp - Embedded UI · Compressed frontend assets served by firmware.
Grbl_Esp32/data/index.html.gz
Connections 29
- Entry → Grbl: starts · Sketch entry initializes the firmware runtime.
- Grbl → Protocol: drives · Main runtime hands command handling to Protocol.
- Grbl → Settings: loads · Runtime reads persistent machine settings.
- Grbl → Report: reports · Runtime emits state and status reports.
- Grbl → Exec: coordinates · Core runtime coordinates execution and state changes.
- Process Settings → Settings: applies · Startup processing applies settings and defaults.
- Protocol → GCode: parses · Protocol routes incoming text to the parser.
- GCode → Exec: executes · Parsed commands become machine actions.
- Protocol → Serial: ingress · Serial is one of the command front doors.
- Protocol → WebUI: ingress · Web UI submits commands into the same path.
- Protocol → Telnet: ingress · Telnet sessions feed commands to Protocol.
- Protocol → SD Card: jobs · SD card jobs enter the command stream.
- Protocol → Error: errors · Protocol surfaces parse and runtime errors.
- Exec → Planner: queues · Execution stages motion into the planner.
- Planner → Stepper: feeds · Planned segments are consumed by stepping.
- Stepper → I2S Out: outputs · Stepper uses high-rate step output backend.
- Exec → Limits: checks · Execution monitors limit and homing safety.
- Exec → Probe: checks · Execution coordinates probing operations.
- Exec → Jog: supports · Interactive jogging is handled through execution.
- Motion Control → Planner: manages · Motion control manages planning flow.
- Motion Control → Stepper: manages · Motion control manages step generation.
- Machines → Pins: defines · Machine profiles bind hardware pin mapping.
- CPU Map → Pins: supports · CPU map feeds board-specific pin behavior.
- Motors → Planner: driven by · Motor drivers are commanded by motion planning.
- Spindle → Exec: tooling · Spindle and tool output are controlled during execution.
- Aux Outputs → Exec: aux io · Coolant and user outputs follow machine state.
- Custom Code → Grbl: extends · Custom code hooks into core runtime behavior.
- WebUI → Wi-Fi: uses · Web UI depends on Wi-Fi services and config.
- WebUI → Embedded UI: serves · Embedded frontend assets are delivered by the web server.