Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Read by thought-leaders and decision-makers around the world. Phone Number: +1-650-246-9381 Email: pub@towardsai.net
228 Park Avenue South New York, NY 10003 United States
Website: Publisher: https://towardsai.net/#publisher Diversity Policy: https://towardsai.net/about Ethics Policy: https://towardsai.net/about Masthead: https://towardsai.net/about
Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Founders: Roberto Iriondo, , Job Title: Co-founder and Advisor Works for: Towards AI, Inc. Follow Roberto: X, LinkedIn, GitHub, Google Scholar, Towards AI Profile, Medium, ML@CMU, FreeCodeCamp, Crunchbase, Bloomberg, Roberto Iriondo, Generative AI Lab, Generative AI Lab VeloxTrend Ultrarix Capital Partners Denis Piffaretti, Job Title: Co-founder Works for: Towards AI, Inc. Louie Peters, Job Title: Co-founder Works for: Towards AI, Inc. Louis-François Bouchard, Job Title: Co-founder Works for: Towards AI, Inc. Cover:
Towards AI Cover
Logo:
Towards AI Logo
Areas Served: Worldwide Alternate Name: Towards AI, Inc. Alternate Name: Towards AI Co. Alternate Name: towards ai Alternate Name: towardsai Alternate Name: towards.ai Alternate Name: tai Alternate Name: toward ai Alternate Name: toward.ai Alternate Name: Towards AI, Inc. Alternate Name: towardsai.net Alternate Name: pub.towardsai.net
5 stars – based on 497 reviews

Frequently Used, Contextual References

TODO: Remember to copy unique IDs whenever it needs used. i.e., URL: 304b2e42315e

Resources

Free: 6-day Agentic AI Engineering Email Guide.
Learnings from Towards AI's hands-on work with real clients.
AI-Driven Machining: Building a Closed-Loop CNC System with IIoT Feedback (Building the CNC)
Artificial Intelligence   Latest   Machine Learning

AI-Driven Machining: Building a Closed-Loop CNC System with IIoT Feedback (Building the CNC)

Last Updated on October 28, 2025 by Editorial Team

Author(s): R Rajesh Swamy

Originally published on Towards AI.

Building the CNC

With the AI brain ready to make machining decisions, it was time to give it a body — the CNC machine itself.
This phase focused on creating a fully functional three-axis dental CNC prototype, capable of interpreting AI-generated toolpaths and executing them precisely.

The goal was clear:

Build a stable, compact, and intelligent CNC system that could cut, measure, and learn — all under local control.

CNC Hardware Overview

The CNC was built from the ground up as a prototype — from mechanical frame to firmware.

Mechanical Design

  • Axes: 3-axis gantry system (X, Y, Z) using linear rails and ball-screws.
  • Work Envelope: 800 mm × 1800 mm × 300 mm — large enough for dental frameworks and precision prototypes.
  • Spindle: ER20-collet, 24 000 RPM, 2.2 kW high-speed spindle, air-cooled, ideal for fine dental machining.
  • Drive System: DM860H stepper drivers with NEMA 34 motors, micro-stepping configured for smooth motion.
  • Frame: Rigid aluminum-extrusion structure for vibration stability and dimensional accuracy.
  • Sensors: Limit switches on all axes, emergency stop, spindle-current sensor, and IMU vibration sensor for tool-health telemetry.

Electronics and Control

  • Controller: Arduino-based GRBL v1.1 firmware on ATmega 328P.
  • Power Electronics: 48 V supply for motors, 24 V for control logic and relays.
  • Interface: USB serial (115 200 bps) connected to a host PC running the GRBL streamer.
  • Telemetry Sensors:
  • Spindle-RPM feedback (Hall sensor)
  • Current feedback (Hall-effect transducer)
  • 3-axis IMU vibration data
AI-Driven Machining: Building a Closed-Loop CNC System with IIoT Feedback (Building the CNC)

GRBL Firmware and Motion Control

At the heart of motion control lies GRBL v1.1, an open-source, lightweight G-code interpreter.

Why GRBL:

  • Runs on inexpensive 8-bit hardware.
  • Offers precise motion planning with acceleration control.
  • Supports PWM-based spindle control and probing.
  • Integrates easily with Python streaming libraries.

Configured parameters for our 3-axis setup:

$100=160.000 (X steps/mm)
$101=160.000 (Y steps/mm)
$102=200.000 (Z steps/mm)
$110=3000.000 (X max rate)
$111=3000.000 (Y max rate)
$112=1000.000 (Z max rate)
$120=100.000 (X accel)
$121=100.000 (Y accel)
$122=50.000 (Z accel)
$30=24000 (Max spindle RPM)
$32=0 (Laser mode off)

GRBL Streaming and Control Pipeline

For automated job execution, the AI-generated G-code must be transmitted line-by-line to GRBL.
We evaluated several open-source streamers:

Tool Selection for G-Code Streaming and Control

During development, we explored several tools to handle G-code streaming and CNC communication — each serving a different purpose in our workflow.

We began with bCNC and OpenCNCPilot.
OpenCNCPilot was especially useful in the early R&D stages. It offered visual feedback, height probing, and toolpath simulation — all of which helped us debug motion and surface consistency issues.
bCNC, on the other hand, proved valuable for interactive testing and calibration. Its macro system and probing support were essential when verifying tool offsets and machine accuracy.

For the production pipeline, we selected grbl-streamer — a lightweight Python-based streamer that integrates perfectly with our AI inference workflow. It allows G-code files to be sent directly from the Python automation layer to GRBL, handling commands line-by-line with precise synchronization and error handling.

This approach lets the AI generate the toolpath and send it straight to the CNC without human involvement — effectively closing the gap between prediction, execution, and feedback.

import serial, time

def stream_gcode(port, filename):
with serial.Serial(port, 115200, timeout=1) as cnc:
time.sleep(2)
cnc.write(b"\r\n\r\n") # wake up GRBL
cnc.flushInput()
for line in open(filename):
cmd = line.strip()
if cmd:
cnc.write((cmd + "\n").encode())
resp = cnc.readline().decode().strip()
print(f"{cmd} -> {resp}")
cnc.write(b"M30\n") # program end

# Example
stream_gcode("/dev/ttyUSB0", "rough_pass.gcode")

This Python script handles queuing, flow control, and real-time status reporting.
G-code files are produced automatically from FreeCAD CLI using the machining meta predicted by the AI.

Integration of AI and GRBL Control

The control pipeline links the AI Decision Engine with the CNC Execution System:

  1. AI Output: Machining meta (phase, tool, feed, step, plunge).
  2. CAM Generation: FreeCAD CLI builds toolpaths.
  3. Execution: G-code streamed via Python to GRBL.
  4. Monitoring: RPM, vibration, and current streamed through MQTT for feedback.
  5. Completion: Finished workpiece sent for 3-D scanning and inspection.

This forms the real-time closed loop — the machine executes while learning from its own telemetry.

Summary

The 2.2 kW ER20 spindle-based CNC prototype brings the AI system’s decisions to life, turning predicted machining parameters into motion.
This physical embodiment closes the gap between data and material — allowing the machine to act, sense, and feed information back to improve subsequent cycles.

Next, we move to Implementation, where every component — AI, CAM, GRBL, and 3-D inspection — connects into a single automated workflow.

Join thousands of data leaders on the AI newsletter. Join over 80,000 subscribers and keep up to date with the latest developments in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming a sponsor.

Published via Towards AI


Towards AI Academy

We Build Enterprise-Grade AI. We'll Teach You to Master It Too.

15 engineers. 100,000+ students. Towards AI Academy teaches what actually survives production.

Start free — no commitment:

6-Day Agentic AI Engineering Email Guide — one practical lesson per day

Agents Architecture Cheatsheet — 3 years of architecture decisions in 6 pages

Our courses:

AI Engineering Certification — 90+ lessons from project selection to deployed product. The most comprehensive practical LLM course out there.

Agent Engineering Course — Hands on with production agent architectures, memory, routing, and eval frameworks — built from real enterprise engagements.

AI for Work — Understand, evaluate, and apply AI for complex work tasks.

Note: Article content contains the views of the contributing authors and not Towards AI.