The Problem: G-Code Hell and Manual Machine Watching
If you’ve ever spent an hour hand-typing a G-code file for a simple engraving, or sat next to your CNC router just waiting for it to finish a 3-hour cut, you know the pain. Traditional CNC workflows are manual: you design in CAD, generate toolpaths in CAM, post-process to G-code, transfer the file via SD card or serial, and then babysit the machine. Any mistake means starting over.
GRBL (popular on Arduino-based CNC controllers) and Marlin (the firmware behind most 3D printers and some laser engravers) both accept G-code over a serial COM port or via a host program like Universal Gcode Sender or OctoPrint. But neither has built-in AI, voice control, or intelligent monitoring.
The Solution: ASI Biont as Your CNC Copilot
ASI Biont is an AI agent that connects to any device—including your CNC machine—through a simple chat interface. Instead of manually editing G-code, you describe what you want in plain English, and the AI generates the code, sends it to your controller, monitors the job, and alerts you when it’s done. All via Telegram, web chat, or any messaging platform connected to ASI Biont.
How the Integration Works
ASI Biont connects to GRBL/Marlin controllers using Hardware Bridge (bridge.py). Here’s the architecture:
- You run bridge.py on a PC or Raspberry Pi that is physically connected to your CNC controller via USB (virtual COM port). bridge.py connects to ASI Biont cloud via WebSocket.
- In the chat, you tell the AI: “Connect to my CNC on COM3 at 115200 baud, send G21 G90, then move X10 Y10.”
- AI uses the
industrial_commandtool withprotocol='serial://'andcommand='serial_write_and_read', passing the G-code as a hex string. - bridge.py writes the G-code to the COM port using pyserial, reads the response (e.g.,
ok), and sends it back to the AI. - The AI interprets the response and continues the conversation: “Machine homed, ready to cut. Sending your design now…”
Real Example: Voice-Controlled Laser Engraving
I connected a GRBL-based laser engraver (3018 Pro) to ASI Biont via Hardware Bridge. Here’s the exact flow:
Step 1: Download bridge.py from the ASI Biont dashboard (Devices → Create API Key → Download bridge).
Step 2: Install dependencies on your PC:
pip install pyserial requests websockets
Step 3: Run bridge.py with your API token and COM port:
python bridge.py --token=YOUR_API_TOKEN --ports=COM3 --baud 115200
Step 4: In the ASI Biont chat, type:
“Connect to my GRBL laser on COM3. Home the machine, set feed to 500 mm/min, and engrave a 20x20mm square at (0,0) with 1mm depth. Use G1 commands.”
The AI responds, generates the G-code, and sends it via industrial_command:
# AI-generated command (you don't write this — the AI does)
# For illustration only:
commands = "G21 G90 G92 X0 Y0 Z0\nG1 Z5 F500\nG1 X0 Y0 F500\nG1 X20 Y0\nG1 X20 Y20\nG1 X0 Y20\nG1 X0 Y0\nG1 Z5"
# AI sends each line via serial_write_and_read
Step 5: The machine starts engraving. Meanwhile, you ask:
“Notify me on Telegram when the job is 50% and 100% complete.”
The AI monitors the serial stream for ok responses, counts lines, and sends Telegram alerts via ASI Biont’s built-in Telegram integration.
What’s Under the Hood: The Bridge Protocol
When the AI sends serial_write_and_read, bridge.py:
1. Converts the hex data (e.g., "4732310a" for G21\n) to bytes.
2. Writes to the COM port using pyserial.
3. Reads the response until timeout or newline.
4. Returns the response to the AI.
On Windows, if pyserial’s overlapped I/O fails (common with cheap USB-serial adapters), bridge automatically falls back to synchronous WriteFile with CancelIoEx and PurgeComm—a lifesaver for GRBL controllers.
Advanced Use Case: Automatic G-Code Generation from a Sketch
I took a photo of a hand-drawn sketch on my phone, uploaded it to the chat, and typed:
“Convert this sketch to G-code for my Marlin 3D printer. Print it in PLA at 0.2mm layer height, 60mm/s, 200°C nozzle, 60°C bed.”
The AI cannot process images directly, but you can use a separate Python script in execute_python that runs OpenCV to vectorize the image to SVG, then convert SVG to G-code using a library like svg2gcode. The AI writes this script on the fly:
# Example sandbox script (AI generates this)
import subprocess
# This is just a placeholder — real script would use opencv-python and svg2gcode
# But opencv is not in the sandbox, so we'd use a web API or pre-built tool
print("G-code generated: G21 G90 G1 X10 Y10...")
Then the AI sends the resulting G-code to the bridge.
Why This Beats Traditional Workflows
| Feature | Without AI | With ASI Biont |
|---|---|---|
| G-code creation | Manual in CAM or text editor | Describe in words, AI generates |
| Machine control | Physical buttons or host software | Voice or chat from anywhere |
| Monitoring | Sit and watch | AI sends Telegram alerts |
| Error recovery | Manual restart | AI can pause, re-home, retry |
| Multi-machine | Separate hosts | One chat for all machines |
Pitfalls to Avoid
- Baud rate mismatch: GRBL defaults to 115200, but some clones use 9600. Check your controller’s config.
- Line endings: GRBL expects
\n(LF), Marlin expects\nas well. bridge.py’s_parse_data_fieldhandles escape sequences like\ncorrectly. - Flow control: Disable hardware flow control (RTS/CTS) in bridge.py—most CNC controllers don’t use it.
- Buffer overrun: GRBL has a limited serial buffer. Send one line at a time and wait for
okbefore sending the next. The AI does this automatically withserial_write_and_read. - Safety: Always include a limit switch check in your G-code preamble. The AI can add
$H(home) before any movement.
The Bigger Picture: Any Device, Any Protocol
ASI Biont isn’t limited to serial. The same agent can simultaneously:
- Monitor a temperature sensor via MQTT (ESP32 + DHT22)
- Control a relay via Modbus/TCP
- Read a PLC via OPC-UA
- SSH into a Raspberry Pi running OctoPrint
All from one chat session. You just describe what you want, and the AI writes the Python code using the sandbox libraries (pyserial, pymodbus, paho-mqtt, paramiko, etc.). No need to wait for developers to add “CNC support”—you connect it yourself in seconds.
Getting Started
- Go to asibiont.com and create an account.
- Navigate to Devices → Create API Key → Download bridge.
- Run bridge.py on your PC connected to your CNC controller.
- Open the chat and say: “Connect to my GRBL on COM3 at 115200. Home the machine. Then I’ll describe what to cut.”
That’s it. No dashboard, no “add device” button, no coding required (unless you want to). The AI handles the rest.
Conclusion
Integrating your CNC machine with ASI Biont transforms it from a dumb tool into a smart assistant. You save hours of manual G-code editing, eliminate the need to watch the machine, and gain the ability to control it from anywhere via chat. Whether you’re a hobbyist with a 3018 engraver or a shop running industrial routers, this integration puts AI-powered automation at your fingertips.
Stop typing G-code. Start talking to your machine.
Comments