CNC Machines (GRBL, Marlin) + ASI Biont: AI-Powered G-Code Generation, Monitoring, and Chat Control

TL;DR

Connecting a CNC machine with GRBL or Marlin firmware to the ASI Biont AI agent lets you supervise your mill, router, or laser cutter from a chat window, generate G-code from plain-English commands, and automatically log job status. No custom dashboard is needed — the AI agent writes the integration code on the fly and talks to the machine over a serial port, network API, or MQTT.

Why Connect a CNC Machine to an AI Agent?

If you've ever spent 20 minutes debugging a G-code file exported from CAM, you know the pain of manual programming. GRBL and Marlin are open-source motion control firmwares used in thousands of DIY and prosumer machines, but their user interfaces are primitive or limited to a simple serial console. Adding an AI agent like ASI Biont acts as a translator between human intent and machine language. Instead of typing G-code or using a pendant, you can say: “Machine a simple leather coaster 80 mm in diameter, with a 20 mm hole in the center” — and the AI writes and sends the G-code for you.

How ASI Biont Connects to GRBL/Marlin

GRBL machines usually connect over a USB COM port (e.g., COM3 on Windows, /dev/ttyUSB0 on Linux) with a default baud rate of 115200. Marlin offers the same serial interface, but many setups also run OctoPrint on a Raspberry Pi, exposing a REST API and WebSocket at http://octopi.local.

ASI Biont's AI Integration Builder looks at your chat message and picks the right communication channel. You don't need to configure anything beforehand. The table below shows the typical options:

Communication channel When to use Python libraries used by AI
COM port via Hardware Bridge Direct connection to GRBL/Marlin over USB pyserial (handled by bridge.py)
MQTT Marlin + OctoPrint or custom ESP32 interface paho-mqtt
HTTP API / WebSocket OctoPrint's REST API for job upload and printer state aiohttp / requests
SSH Raspberry Pi running OctoPrint or Linux CNC paramiko
Modbus/TCP Industrial CNC controllers with Modbus interface pymodbus
execute_python Any custom protocol, one-off commands pyserial, paramiko, paho-mqtt, etc.

Whatever interface you choose, the fallback is always execute_python: the AI writes a small Python script that runs in a sandbox and talks directly to the device. It might import pyserial, paramiko, paho-mqtt, pymodbus, or aiohttp depending on your problem. You only describe the port, IP, baud rate, or API key in the chat — no need to wait for a pre-built integration.

In most GRBL setups, the simplest and most reliable path is the Hardware Bridge for COM ports. You download bridge.py from the ASI Biont dashboard (from your account, not GitHub), and launch it on the computer connected to the CNC:

python bridge.py --token=YOUR_TOKEN --ports=COM3 --baud 115200 --rate=10

The bridge opens the serial port, reads packets from GRBL, and sends them to the AI agent in the cloud. You do not need a public IP or port forwarding.

Step-by-Step: A Real GRBL Setup

1. Connect the Machine

Plug your GRBL controller (e.g., an STM32 board running GRBL 1.1) via USB to a Windows or Raspberry Pi PC. Open a terminal and check the port with ls /dev/ttyUSB* or Device Manager. Leave the baud at 115200 — GRBL default.

2. Launch the Hardware Bridge

From the ASI Biont dashboard, download bridge.py for your platform, then run the command above. The bridge will send status updates every 100 ms (rate=10 means 10 Hz). You can verify with a terminal program, but the bridge does that for you.

3. Ask the AI Agent to Read Machine Status

In your chat with ASI Biont, type:

“Check whether the GRBL machine is homed and report its current position.”

The AI identifies the bridge connection and calls industrial_command(protocol='serial', command='?'). GRBL replies with something like `<Idle

|MPos:0.000,0.000,0.000|FS:0,0>`. The AI parses that and gives you a human-readable answer.

4. Generate and Send G-Code

But the real magic is generative: tell the AI what you want to make, and it will write the G-code for you.

“Cut a 40x60 mm rectangle from 3 mm plywood using a 3 mm endmill, depth 2 mm, starting at origin.”

The AI might generate this:

; Generated by ASI Biont
G21 ; mm mode
G90 ; absolute distance
M3 S1000 ; spindle on
G0 X0 Y0
G1 F300
G1 Z-2
G1 X40
G1 Y60
G1 X0
G1 Y0
G0 Z5
M5 ; spindle off

Then the AI sends each line via industrial_command(protocol='serial', command='G21\rG90\rM3 S1000\r...'). It waits for ok responses and can abort if an error code like error:18 appears.

Reading Sensor Data and Auto-Logging

Marlin controllers often have temperature sensors for the hotend or spindle. If your GRBL machine has an external thermocouple connected to an ESP32 that publishes MQTT messages, ASI Biont can subscribe to those topics and watch for overheating.

For example, the AI can create a small MQTT bridge and poll telemetry/temp every second. If the temperature crosses a threshold, the AI can send a Telegram message via requests.post('https://api.telegram.org/botXXX/sendMessage', data={...}). I've seen a simple setup where a coolant pump was stopped automatically because the AI detected a thermal runaway before a nozzle burnt the workpiece.

When I connected a Marlin-based 3D printer to ASI Biont, I asked the AI to check the hotend temperature. It executed industrial_command(protocol='serial', command='M105') and parsed the T:190.3 /200.0 response. This worked even through the same bridge, because Marlin uses the same COM port protocol.

Pitfalls I Learned the Hard Way

  1. Do not stream all G-code at once. GRBL has a limited serial buffer. If the AI sends 500 lines instantly, the machine will miss commands and throw alarms. Ask the AI to send line-by-line and wait for ok.
  2. Mind the DTR line. Many GRBL boards auto-reset when you open the serial port. The bridge handles this, but if you write your own pyserial code, you may need to disable DTR on connection.
  3. Line endings are critical. GRBL expects \r, not \n. Marlin also accepts \r in most versions.
  4. Don't use while True loops in execute_python. ASI Biont's sandbox has a 30-second timeout. If you need continuous monitoring, use the bridge with --rate or a cron job.
  5. Coordinate systems. Always call $H (homing cycle) before a critical job. I once watched the AI move a router table to X=0, Y=0 without homing, and the tool rammed the end stop — a mechanical fuse saved us.

Why This Changed My Workflow

After integrating ASI Biont with my CNC router, I stopped reaching for the laptop on the shop floor. I can check job progress from my phone while drinking coffee, ask the AI to pause and resume, and even generate a custom engraving G-code directly in the chat. The most time-saving feature is that the AI handles protocol details: I don't need to remember whether to send $X after a kill alarm; I just ask “why did the machine stop?” and the AI reads the GRBL error code and explains it.

What About More Exotic Controllers?

If you have an industrial CNC with a Modbus/TCP interface, ASI Biont will happily use pymodbus to read registers and write setpoints. If you have Marlin running on a Klipper host, you can SSH into it via paramiko and run commands. The beauty is that you don't need to implement anything in a web dashboard — you just describe the device in the chat, and the AI writes the Python glue code right then.

For example, I once connected a laser engraver that spoke a custom binary protocol. I pasted a snippet of the firmware source code into the ASI Biont chat and asked it to implement a driver. The AI generated a working script using pyserial and struct.pack in about twenty seconds. It's not a pre-built driver, so it requires understanding, but it's a massive leap from waiting for vendors to release an official SDK.

Conclusion

Integrating CNC machines with ASI Biont turns a “dumb” motion controller into a context-aware manufacturing cell. Whether you're using GRBL with a 3D printer or Marlin on a desktop mill, the AI agent takes over the routine work: status monitoring, G-code generation, error handling, and even emergency actions. You can try it yourself on asibiont.com — create the AI agent, download the bridge, and connect your machine. No need to wait for “official integrations” because ASI Biont writes them as you ask.

Further Reading

  • GRBL wiki: https://github.com/grbl/grbl/wiki
  • Marlin G-code documentation: https://marlinfw.org/docs/gcode/000-introduction.html
  • pyserial docs: https://pyserial.readthedocs.io/
  • ASI Biont: https://asibiont.com
← All posts

Comments