Why Connect Your CNC Machine to an AI Agent?
If you run a CNC router, laser engraver, or 3D printer with GRBL or Marlin firmware, you know the pain of manual G-code tweaking, pausing mid-job to adjust feed rates, or losing a part because the spindle overheated. An AI agent like ASI Biont can monitor your machine in real time, send G-code commands via serial, and even trigger alerts when something goes wrong — all from a Telegram chat. No need to stand over the machine with a laptop.
How ASI Biont Connects to GRBL/Marlin
ASI Biont connects to CNC machines through the Hardware Bridge — a lightweight Python application (bridge.py) that runs on your PC (Windows/Linux/macOS). The bridge opens a WebSocket connection to the ASI Biont cloud, and the AI agent sends commands via the industrial_command tool. For serial devices, the bridge uses serial_write_and_read(data=hex_string) — an atomic write+read operation that sends your G-code and immediately returns the response.
| Parameter | Typical Value |
|---|---|
| Port | COM3 (Windows) or /dev/ttyUSB0 (Linux) |
| Baud rate | 115200 (GRBL default) |
| Data format | Hex string (e.g., "4731300a" for G10\n) |
| Protocol | serial:// |
Step-by-Step: ESP32 + Temperature Sensor + CNC Monitoring via Telegram
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
Launch the bridge with your API token and COM port:
python bridge.py --token=YOUR_TOKEN --ports=COM3 --baud 115200
2. Connect GRBL via Chat
In the ASI Biont chat, simply type:
"Connect to my GRBL CNC on COM3 at 115200 baud. Send G-code $G to verify connection."
The AI agent will run the following command behind the scenes:
# This is what the AI executes via industrial_command
command = industrial_command(
protocol='serial://',
command='serial_write_and_read',
data='24470a' # hex for "$G\n"
)
The bridge sends $G to the CNC, GRBL replies with current G-code state (e.g., [G0 G54 G17 G21 G90 G94 M5 M9 T0 F0 S0]), and the AI returns the response to you.
3. Real-Time Monitoring Use Case
Let's say your CNC has an ESP32 with a DHT22 temperature sensor connected via UART. You want the AI to:
- Read spindle temperature every 30 seconds
- If temp > 60°C, send M5 (stop spindle) and alert via Telegram
You describe this in chat:
"Read spindle temp from DHT22 on ESP32, if above 60°C send M5 to CNC and notify me on Telegram."
The AI will:
1. Write a Python script for the ESP32 (using MicroPython) that reads DHT22 and prints temperature.
2. Use the bridge to send M105 periodically (Marlin temperature query) or read from the ESP32 serial.
3. If threshold exceeded, send M5 via bridge and call Telegram API.
Here's a simplified version of what the AI generates for the ESP32 side:
# ESP32 MicroPython code (generated by AI)
import machine, dht, time
sensor = dht.DHT22(machine.Pin(4))
while True:
sensor.measure()
temp = sensor.temperature()
print(f"TEMP:{temp}") # bridge reads this via serial
if temp > 60:
print("ALERT:OVERHEAT")
time.sleep(30)
On the ASI Biont side, the AI runs a sandbox script that parses TEMP:xx lines and triggers commands:
# Sandbox script (executed by AI, NOT on your PC)
import requests
# This is a simulation — real bridge command goes through industrial_command
if "ALERT:OVERHEAT" in last_response:
industrial_command(protocol='serial://', command='serial_write_and_read', data='4d350a') # "M5\n"
requests.post("https://api.telegram.org/botTOKEN/sendMessage", json={"chat_id":"123","text":"Spindle stopped due to overheat!"})
4. Common Pitfalls and How to Avoid Them
| Pitfall | Solution |
|---|---|
| Bridge fails to write on Windows | The bridge automatically calls CancelIoEx + PurgeComm + synchronous WriteFile. If you see "written: 0", check that no other program (Candle, UGS) has the port open. |
| G-code with newlines not working | Use hex encoding: "4d335c6e" for M3\n. The bridge's _parse_data_field() handles both hex strings and escape sequences like "M3\r\n". |
| AI script times out in sandbox | Avoid while True loops. Use time.sleep() with a finite number of iterations or implement a callback pattern. |
| ESP32 serial output garbled | Match baud rates exactly: 115200 on both GRBL and ESP32. Use ` |
| ` line endings. |
Why This Beats Manual Coding
Traditionally, you'd write a Python script with pyserial, set up a loop, handle exceptions, and integrate Telegram manually. With ASI Biont, you describe the task in plain English — the AI writes the code, tests it, and runs it. Want to change the threshold from 60°C to 50°C? Just say "Change overheat threshold to 50°C". No re-deploy, no git push.
Try It Yourself
Ready to give your CNC machine a brain? Go to asibiont.com, create an API key, download the bridge, and plug in your GRBL or Marlin device. Describe your setup in chat — the AI will handle the rest. No coding required, unless you want to tweak the generated code.
Pro tip: Start with a simple G-code query like $G to confirm the connection works, then add monitoring and alerts one step at a time.
Comments