Introduction
CNC machines running GRBL or Marlin firmware are the workhorses of modern prototyping, small-scale manufacturing, and hobbyist workshops. From desktop routers to 3D printers repurposed for PCB milling, these machines execute precise G-code commands to cut, engrave, and shape materials. However, managing a CNC workflow often involves manual intervention: starting jobs, monitoring tool wear, adjusting feeds, and handling errors. What if an AI agent could take over these tasks, communicate with your machine in real time, and make intelligent decisions based on sensor data?
ASI Biont connects to CNC machines via COM port using the Hardware Bridge or SSH for Raspberry Pi–based controllers, enabling AI-driven automation without custom dashboard panels or complex middleware. This article explains how to connect a GRBL/Marlin machine to ASI Biont, automate milling tasks with Python code, and unlock a new level of shop-floor intelligence.
Why Connect a CNC Machine to an AI Agent?
Traditional CNC operation requires an operator to:
- Load G-code files manually
- Monitor spindle load and temperature
- Pause or stop when a tool breaks or material shifts
- Adjust feed rates based on material or bit condition
An AI agent can:
- Send G-code commands directly via serial
- Read machine status (position, feed rate, spindle RPM) from GRBL/Marlin status reports
- Analyze data from external sensors (vibration, temperature, acoustic emission) connected to an ESP32 or Arduino
- Automatically pause, retract, or adjust parameters when anomalies are detected
- Log every job for later analysis
This transforms a dumb milling machine into a semi-autonomous production station.
Connection Method: COM Port via Hardware Bridge
ASI Biont uses the Hardware Bridge—a lightweight bridge.py script running on your local PC—to access COM ports. The bridge connects to the ASI Biont cloud via HTTP long polling. You start it once, and the AI agent can send and receive serial data through the industrial_command tool.
Step 1: Start the Hardware Bridge
Open a terminal on the computer connected to your CNC controller (via USB). Run:
python bridge.py --token=YOUR_ASI_BIONT_API_TOKEN --ports=COM3 --default-baud=115200
Replace COM3 with your actual port (e.g., /dev/ttyUSB0 on Linux). GRBL typically uses 115200 baud; Marlin often uses 250000. Adjust accordingly.
Step 2: Connect the Machine in Chat
In the ASI Biont chat, describe your setup:
"Connect to GRBL controller on COM3 at 115200 baud. Send a G-code command G91 to enable relative positioning, then G1 X10 F100 to move 10mm in X."
The AI will respond by executing:
# The AI uses industrial_command(protocol='serial://', command='write', ...) internally
# But you only see the result in chat.
Step 3: Real-Time Status Reading
GRBL sends real-time status when you send ? over serial. The AI can poll this every second:
# AI generates this script and runs it via execute_python with pyserial
import serial
import time
ser = serial.Serial('COM3', 115200, timeout=1)
try:
for _ in range(10):
ser.write(b'?')
time.sleep(0.1)
response = ser.readline().decode().strip()
print(f"Status: {response}")
finally:
ser.close()
Important: This script runs in the ASI Biont sandbox, which has no direct COM access. That's why we use the Hardware Bridge. The actual command is sent via industrial_command(protocol='serial://', command='write', data='?', ...). The AI handles this transparently.
Practical Use Case: AI-Powered Tool Wear Detection
Imagine you're milling aluminum with a 3mm end mill. Tool wear increases cutting force, which can be detected by a vibration sensor (e.g., ADXL335) connected to an ESP32. The ESP32 publishes vibration data via MQTT. ASI Biont subscribes to that topic, and if vibration exceeds a threshold, the AI pauses the CNC and alerts you.
Hardware Setup
| Component | Connection |
|---|---|
| CNC (GRBL) | USB → PC → Hardware Bridge → ASI Biont |
| ESP32 + ADXL335 | WiFi → MQTT broker → ASI Biont |
ESP32 MicroPython Code (for vibration sensor)
import network
import time
from machine import Pin, ADC
from umqtt.simple import MQTTClient
# WiFi setup
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect('SSID', 'PASSWORD')
# MQTT setup
client = MQTTClient('esp32_cnc', '192.168.1.100', port=1883)
client.connect()
adc = ADC(Pin(34))
adc.atten(ADC.ATTN_11DB)
while True:
value = adc.read()
client.publish('cnc/vibration', str(value))
time.sleep(0.5)
ASI Biont AI Agent Logic
The user tells the AI:
"Subscribe to MQTT topic 'cnc/vibration' on broker 192.168.1.100. If the value exceeds 3000, send a pause command to the CNC via COM3 and notify me on Telegram."
The AI generates and executes:
import paho.mqtt.client as mqtt
import time
# This script runs in execute_python sandbox, uses industrial_command for serial
# The AI will call industrial_command internally when condition is met
def on_message(client, userdata, msg):
value = int(msg.payload)
if value > 3000:
# AI sends pause via industrial_command
# In real execution, the AI would call:
# industrial_command(protocol='serial://', command='write', data='!', ...)
print("Vibration too high! Pausing CNC.")
# The AI also sends a Telegram alert via its own API
client = mqtt.Client()
client.on_message = on_message
client.connect('192.168.1.100', 1883, 60)
client.subscribe('cnc/vibration')
client.loop_start()
time.sleep(30) # Sandbox limit
client.loop_stop()
Result: The CNC stops automatically when vibration spikes, preventing tool breakage and scrapped parts.
Alternative: SSH Control for Raspberry Pi–Based CNC
If your CNC runs on a Raspberry Pi (e.g., using bCNC or cncjs), you can connect via SSH. The AI uses paramiko to execute Python scripts that control the machine.
User: "SSH into my CNC Pi at 192.168.1.50 with user 'pi' and key file. Read the current GRBL status every 5 seconds for 30 seconds."
The AI writes:
import paramiko
import time
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('192.168.1.50', username='pi', key_filename='/home/user/.ssh/id_rsa')
stdin, stdout, stderr = ssh.exec_command("python3 -c \"
import serial
ser = serial.Serial('/dev/ttyAMA0', 115200)
for _ in range(6):
ser.write(b'?')
time.sleep(0.1)
print(ser.readline().decode().strip())
\"")
print(stdout.read().decode())
ssh.close()
This approach is ideal for remote control of a workshop CNC.
Why ASI Biont Beats Manual Scripts
- No coding required: You describe the task in plain English. The AI writes, debugs, and executes the integration.
- Universal connectivity: COM port, MQTT, SSH, Modbus, HTTP API—all in one chat.
- Real-time decision-making: The AI can combine data from multiple sources (CNC status + vibration + temperature) and act instantly.
- Logging and analysis: The AI can store every job's G-code, sensor readings, and outcomes in a database for later review.
Conclusion
Connecting a CNC machine (GRBL or Marlin) to ASI Biont turns a manual milling setup into an AI-assisted smart workshop. Whether you're monitoring tool wear via MQTT, pausing on error via serial, or running remote diagnostics via SSH, the AI agent handles the heavy lifting. No need to wait for developers to add support—just describe your hardware and goals in the chat, and the integration happens in seconds.
Ready to automate your CNC workflow? Try it now at asibiont.com.
Comments