ESP32 Projects
Start a build
Markdown

G Code Offline Controller ESP32

An ESP32 display project involving TFT display, SD card.

ESP32Arduino, PlatformIOUnrated
Parts and source

Before you start

Check the exact TFT display, SD card configuration against the upstream wiring or parts list.

Upstream README

G-code Offline Controller (ESP32)

ESP32 PlatformIO C++ Arduino Grbl License PCBWay Sponsored
Standalone touch controller for Grbl-controlled CNC machines, based on ESP32 + ILI9341 display.


This project allows you to load, preview, and execute G-code files without a connected computer. It offers manual machine control (jog, homing, work zero), remote web monitoring, and a robust automatic job recovery system after a power outage.

πŸ“‘ Table of Contents


✨ Key Features

πŸ–₯️ Display & UI
  • Full Touch Interface: Fluid design featuring a navigation sidebar and a persistent status header.
  • Home: 2D G-code toolpath preview with auto-scaling, real-time tool cursor, X/Y/Z coordinates, feed rate, spindle/laser power, job progress, and Play/Pause/Stop/Framing controls.
  • Files: SD/USB file explorer with folder navigation, momentum scrolling, and automatic G-code file filtering.
  • Jog: Manual axis control with configurable steps, homing, work zero setting per axis, and touch probe (Probe Z).
  • Tools: Create various tool profilesβ€”such as laser or spindle typesβ€”specifying bit or laser diameter and setting power levels for activation; assign tools to specific jobs to track usage time (e.g., for a specific bit diameter) and better manage your tooling and operational time. (NOTE: Assigning diameter or power settings does not affect the job itself; these parameters are determined by your file. The controller does not calculate or modify your G-code lines; it simply helps track and log the usage time of the tool in question.)
  • Settings: Device info, Wi-Fi configuration, native editing of Grbl parameters ($$) using specific controls (toggle/enum/numeric), and general app settings (speeds, language, sound, screen sleep, job recovery).
  • Multilingual: Native support for English, Spanish, Italian and German.
βš™οΈ Machine Control
  • G-code Streaming: UART communication with Grbl, featuring a custom parser that tracks the full modal state (position, units, plane, coordinate system, feed, spindle).
  • Live Reading & Editing: Direct modification of Grbl $$ parameters on the fly.
  • Power-Loss Job Recovery: If a power outage occurs, the system detects the interrupted job upon reboot, performs a safe homing cycle, restores the modal state, and resumes from the exact line where it left off (requires the USB/SD memory to remain connected).
  • Framing: Perimeter bounding box run to verify material positioning before starting the job.
πŸ’Ύ Storage
  • Dual Interchangeable Sources: microSD card and USB drive (via CH376S chip), accessible as independent tabs.
  • Full Management: Browse, load, rename, and delete files or folders from both sources directly on the screen.
🌐 Connectivity
  • Smart Wi-Fi: Auto-reconnection and a fallback Access Point (AP) mode if the known network fails.
  • Remote Web Monitor: Browser-based dashboard showing real-time status, jog control, file manager (SD/USB) with remote upload, and an interactive live G-code console.

πŸ“Έ Interfaces

🏠 Home (Preview) πŸ“‚ Files (SD/USB) πŸ•ΉοΈ Jog (Manual Control)
Home Screen File Explorer Jog Control
πŸ› οΈ Tools (Spindle/Laser) βš™οΈ Settings (Configuration) 🌐 Web Monitor
Tools Control Settings Web Interface

🀝🏼 Hardware Sponsorship

The dedicated PCB for this project was designed from scratch to ensure high reliability, optimal signal integrity for the ESP32, and an easy manual assembly process.

We are proud to announce that the professional prototyping of these boards has been fully sponsored by PCBWay. Thanks to their high-precision manufacturing services, we achieved:

  • Flawless Trace Definition: Perfect routing compliance for the SMD components and level shifters.
  • Superior Silkscreen Quality: Clean, highly readable text labels and diagrams across both sides of the board.
  • Industrial Finish: Robust solder mask application that facilitates clean hand-soldering for makers.

Whether you are looking to build this G-code controller or need rapid, professional manufacturing for your own custom electronics, we highly recommend checking out PCBWay's PCB Prototype and Assembly Services. Their technical review and manufacturing speed have been instrumental in moving this open-source project forward.


πŸ”Œ Hardware

Controller Wiring Guides

This schematic illustrates the correct wiring configuration required for the controller to function properly with the firmware.

Controller Schematic

⚠️ Notes

  • Some components are only available in SMD format, which makes them difficult to use without a dedicated PCB.

  • Fortunately, ready-to-wire modules are available for these components, simplifying integration.

  • Communication with Grbl is done via UART. This project acts as a G-code streamer and master controller; it does not control stepper motors directly.

Component Availability & Alternatives
Component Format Notes
ESP32 Dev Kit Through Hole This version uses the 30-pin ESP32 dev kit.
ILI9341 Touch Display Through Hole The 240x320 TFT-ILI9341 display with a microSD card reader is used.
USB-A Famale SMD / Through Hole USB-A female connector.
IDC Header 2x4 SMD / Through Hole 90-degree 8-pin (2x4) IDC header connector
CH376S SMD Only Module version exists. For reading USB drives
AMS1117-3.3 SMD Only Available as a module. Any 3.3V regulator can also be used.
BSS138 SMD Only Modules using this MOSFET work equally well as level shifters.
Component Availability & Alternatives

I have designed a dedicated PCB in KiCad. Using the Gerber files provided in this repository, you can have it manufactured or even make it yourself, as I ensured that the pin pads do not require soldering from the top side.

PÇBView

NOTE: To mount the display, you must solder on female headers to provide enough clearance for the components located underneath it.


πŸ’» Firmware

This project is built with PlatformIO on top of the Arduino framework for ESP32.

Main Libraries:

  • TFT_eSPI β€” Highly optimized display driver.
  • Ch376msc β€” Support for USB drive communication.
Compile and Upload
  1. Clone the repository.
  2. Open the project in VS Code with PlatformIO.
  3. Navigate to the .pio and libdeps folders to modify the TFT_eSPI library.
  4. Open the User_Setup_Select.h file and comment out line #27:
// #include <User_Setup.h>
  1. Uncomment line #76:
#include <User_Setups/Setup42_ILI9341_ESP32.h>
  1. In the library's User_Setups folder, locate the Setup42_ILI9341_ESP32.h file and uncomment line #14 to enable the touchscreen:
#define TOUCH_CS 5 // Chip select pin (T_CS) of touch screen
  1. Configure your hardware pins according to the provided schematic, or adjust the include/pins.h file to match your custom wiring.
  2. Run the build/upload command:
pio run -t upload
pio run -t uploadfs

πŸ—οΈ Architecture

To guarantee fluidity and maximize the performance of the ESP32, the project does not rely on heavy external GUI libraries (like LVGL). Instead, it implements a custom widget architecture:

src/
β”œβ”€β”€ app/            # Main application logic
β”œβ”€β”€ display/        # Display driver abstraction (driver/interface pattern)
β”œβ”€β”€ touch/          # Touch event handling (Pressed/Move/Released with debounce)
β”œβ”€β”€ gui/            # Native graphic system
β”‚   β”œβ”€β”€ core/       # Base Widget, ScreenManager, Header, Sidebar, scroll containers
β”‚   β”œβ”€β”€ widgets/    # Buttons, sliders, toggles, lists, etc.
β”‚   └── screens/    # App screens (Home, Files, Jog, Tools, Settings)
β”œβ”€β”€ gcode/          # G-code parser, file analysis, and 2D simulator
β”œβ”€β”€ machine/        # UART communication with Grbl, job execution, and recovery
β”œβ”€β”€ storage/        # Storage abstraction layer (unified SD / USB)
β”œβ”€β”€ network/        # Wi-Fi management, OTA, and embedded web server
└── i18n/           # Internationalization and translation system

Performance: Each widget manages its own redraw state (dirty flag), preventing screen flickering and minimizing the rendering load. This is critical since the UI and G-code streaming share the same resources on the ESP32.

πŸ’‘ Motivation

This project was built piece by piece, iterating over the real daily needs of working in a CNC workshop. It started as a basic UI to avoid bringing a laptop to the machine, and evolved to include industrial-grade features like power-loss job recovery (saving expensive materials and machining hours). It remains in active development.

πŸ“„ License

This project is distributed under the Apache 2.0 license. See the LICENSE file for more details.