Introduction
CNC machines running on GRBL or Marlin firmware are the backbone of modern prototyping and small-scale manufacturing. From desktop engravers to 3D printers and milling machines, these devices translate G-code into precise physical movements. However, operating them manually—loading files, monitoring tool wear, adjusting feeds and speeds—is time-consuming and error-prone. Integrating an AI agent like ASI Biont transforms this workflow: the AI connects directly to the CNC controller, reads real-time status, sends G-code commands, and makes intelligent decisions based on sensor feedback. This article explains how to connect GRBL/Marlin-based machines to ASI Biont, presents concrete use cases, and shows the code that makes it all work.
Why Connect a CNC Machine to an AI Agent?
Traditional CNC workflows require an operator to:
- Manually send G-code files (via USB or SD card)
- Monitor spindle load, temperature, and vibration visually
- Stop the machine if something goes wrong
- Optimize cutting parameters through trial and error
With ASI Biont, the AI agent:
- Connects via COM port (Hardware Bridge) to send and receive serial data
- Parses GRBL status reports (`<Idle
|Run|Hold|Door|Home|Alarm>`)
- Detects anomalies (e.g., spindle overload, missed steps) and halts the machine
- Adjusts feed rate or spindle speed based on material and tool data
- Logs every operation for traceability and predictive maintenance
Connection Method: COM Port via Hardware Bridge
GRBL and Marlin communicate over a serial interface (USB-to-UART) at baud rates like 115200. ASI Biont connects to the CNC controller through the Hardware Bridge—a lightweight Python application (bridge.py) that runs on the user's PC. The bridge opens a WebSocket connection to ASI Biont's cloud server. The AI agent sends commands via the industrial_command tool with protocol serial://. The bridge writes the command to the COM port, reads the response, and returns it to the AI.
Why not MQTT or Modbus? GRBL and Marlin do not natively support these protocols. Serial is the universal interface for these controllers. The Hardware Bridge ensures the AI can reach the local COM port without exposing it to the internet.
Step-by-Step: Connecting a GRBL Engraver
1. Set Up the Hardware Bridge
Download bridge.py from the ASI Biont dashboard (Devices → Create API Key → Download bridge). Install dependencies:
pip install pyserial requests websockets
Run the bridge with your API token, specifying the COM port and baud rate:
python bridge.py --token=YOUR_API_TOKEN --ports=COM3 --baud 115200
The bridge connects to ASI Biont via WebSocket and waits for commands.
2. Ask the AI to Connect
In the ASI Biont chat, describe your setup:
"Connect to my GRBL engraver on COM3 at 115200 baud. Send a homing command, then move to X10 Y10."
The AI agent sends industrial_command(protocol='serial://', command='serial_write_and_read', data='243130200a') (hex for $10\n — a GRBL setting) and parses the response.
3. Real-Time Status Monitoring
GRBL sends continuous status reports like:
<Idle
|MPos:0.000,0.000,0.000|Bf:35,127|FS:0,0|WCO:0.000,0.000,0.000>
The AI can request a status update by sending ? (hex 3f0a):
# AI-generated Python code (runs in execute_python)
# Sends ? and parses the status
status = serial_write_and_read(data="3f0a")
# status returns: <Idle
|MPos:10.5,20.3,0.000|Bf:15,127|FS:1200,8000>
Use Case 1: Automated Tool Wear Detection
Problem: An operator runs a batch of 500 aluminum parts. After 300 parts, the end mill wears, causing poor surface finish and potential spindle damage.
Solution with ASI Biont:
- The AI monitors spindle load (via GRBL's FS field — feed rate, spindle speed)
- It tracks the increase in spindle load over time (normalized to material and tool)
- When load exceeds a threshold (e.g., 20% above baseline), the AI:
1. Sends a feed hold (! hex 210a)
2. Logs the event to a database
3. Sends a Telegram alert: "Spindle load 85% — tool may be worn. Replace bit."
4. Optionally adjusts feed rate to finish the current part safely
Code snippet (AI-generated, runs in sandbox):
import time
import json
from datetime import datetime
# Simulated GRBL status parsing
def parse_grbl_status(raw):
# raw example: '<Run
|MPos:10.5,20.3,0.000|Bf:15,127|FS:1200,8000>'
import re
fs_match = re.search(r'FS:(\d+),(\d+)', raw)
if fs_match:
feed = int(fs_match.group(1))
spindle = int(fs_match.group(2))
return {'feed': feed, 'spindle': spindle}
return None
# Baseline from first 10 parts
baseline_spindle = 6500 # example
history = []
# In a real scenario, this loop runs via periodic commands from the AI
for i in range(500):
status_raw = serial_write_and_read(data="3f0a") # send '?'
parsed = parse_grbl_status(status_raw)
if parsed:
spindle_load = parsed['spindle']
history.append(spindle_load)
# Check anomaly
if spindle_load > baseline_spindle * 1.2:
# Send feed hold
serial_write_and_read(data="210a") # '!'
alert = f"⚠️ Spindle load {spindle_load} ({datetime.now()}) — tool might be worn."
# (Telegram integration via another execute_python script)
print(alert)
break
time.sleep(1) # poll every second
Use Case 2: Remote Batch Job Execution with Quality Check
Problem: A workshop has 10 CNC mills. An operator must physically load G-code for each job and monitor progress.
Solution:
1. The AI stores G-code templates (e.g., for a standard bracket) in its memory.
2. The user says: "Run job Bracket-Rev3 on machine #2 (COM5). Use 6061 aluminum, 1/4" end mill."
3. The AI selects the correct G-code, adjusts feeds and speeds based on material data (from a lookup table), and sends it line by line via serial.
4. After each line, the AI waits for an 'ok' response from GRBL before sending the next.
5. Upon completion, the AI reads the final position and verifies it matches the expected coordinates (quality check).
6. The AI logs the job duration, material used, and any errors to a database.
Partial code (AI-generated):
# G-code for a simple pocket (simplified)
gcode_lines = [
"G21 ; mm mode",
"G90 ; absolute positioning",
"G17 ; XY plane",
"G0 Z5 ; retract",
"G0 X0 Y0 ; go to origin",
"G1 Z-1 F100 ; plunge",
"G1 X10 F300 ; cut",
"G1 Y10",
"G1 X0",
"G1 Y0",
"G0 Z5",
"M5 ; spindle off",
"M30 ; program end"
]
for line in gcode_lines:
hex_data = line.encode().hex() + "0a" # append \n
response = serial_write_and_read(data=hex_data)
if 'error' in response:
print(f"Error on line '{line}': {response}")
break
# wait for 'ok'
while 'ok' not in response:
response = serial_write_and_read(data="") # read again
Comparison: ASI Biont vs. Manual Operation
| Aspect | Manual Operation | With ASI Biont |
|---|---|---|
| G-code loading | Copy to SD/USB | AI sends directly via serial |
| Status monitoring | Visual inspection | Real-time parsing of status reports |
| Anomaly detection | Human reaction (seconds) | AI reaction (milliseconds) |
| Feed/speed optimization | Trial and error | AI adjusts based on material DB |
| Logging | Paper or spreadsheet | Automatic database logging |
| Remote control | Requires remote desktop | Chat-based commands via any device |
How to Start
No coding required from your side. Just:
1. Download bridge.py from the ASI Biont dashboard.
2. Run it on the PC connected to your CNC.
3. In the chat, tell the AI: "Connect to my CNC on COM3 at 115200 baud. Send a homing command (G28) and then move to X10 Y10."
The AI agent will generate the Python code, execute it, and control your machine. You can watch the interaction, ask for changes, or set up automated routines.
Conclusion
Integrating CNC machines (GRBL, Marlin) with ASI Biont unlocks a new level of automation: real-time monitoring, predictive maintenance, remote batch execution, and intelligent anomaly response. The Hardware Bridge provides secure, low-latency serial access, while the AI agent handles parsing, decision-making, and logging. No dashboard, no plugins — just a conversation with the AI. Try it today at asibiont.com and turn your CNC into a smart manufacturing cell.
Note: All code examples are AI-generated and run in ASI Biont's sandbox. Actual serial communication requires the Hardware Bridge to be running on the same LAN as the CNC.
Comments