UART (Any MCU) Meets AI: How to Control Any Microcontroller via COM Port with ASI Biont
You’ve got an Arduino, an STM32, or an ESP32 sitting on your desk, blinking an LED or reading a sensor. Now imagine telling your AI agent, “Log the temperature every 5 minutes and send me an alert if it goes above 30°C,” and it just works — without you writing a single line of Python code. That’s exactly what ASI Biont delivers through its UART/COM-port integration.
Why Bother with UART and AI?
UART is the universal serial interface that almost every microcontroller speaks. It’s simple, reliable, and supported by everything from a $2 Arduino Nano to a $200 industrial PLC. Connecting it to an AI agent means:
- Remote monitoring — read sensor data from anywhere via Telegram or Slack.
- Automated control — let the AI decide when to switch a relay or adjust a motor.
- Zero coding — describe what you need in plain English, and ASI Biont writes the integration code on the fly.
How ASI Biont Connects to UART Devices
ASI Biont doesn’t have a magical “plug and play” button for COM ports. Instead, it uses a Hardware Bridge — a tiny Python script (bridge.py) that runs on your local PC (Windows, Linux, or macOS) and connects to the ASI Biont cloud via WebSocket. The bridge opens the COM port using the pyserial library, and the AI agent sends commands through the industrial_command tool.
Connection flow:
1. You download and run bridge.py with your API token and COM port settings.
2. In the ASI Biont chat, you tell the AI: “Connect to COM3 at 115200 baud, read the temperature sensor, and log it every minute.”
3. The AI sends an industrial_command(protocol='serial://', command='read_temp') to the bridge.
4. The bridge reads the serial data and returns it to the AI, which processes and stores it.
Real Example: ESP32 + Temperature Sensor → Telegram Alerts
Let’s make it concrete. You have an ESP32 with a DHT22 sensor connected via UART (USB-to-serial). The ESP32 firmware sends a JSON line every second: {"temp": 25.3, "hum": 60.1}.
Step 1: Run the Hardware Bridge
On your PC, open a terminal and run:
python bridge.py --token=YOUR_API_TOKEN --ports=COM3 --default-baud=115200
The bridge connects to ASI Biont and reports that COM3 is available at 115200 baud.
Step 2: Chat with the AI Agent
In the ASI Biont chat, type:
“Read data from COM3 at 115200 baud. Parse JSON lines. If temperature exceeds 30°C, send me a Telegram alert. Log all data every 30 seconds to a CSV file.”
The AI writes a Python script (using execute_python) that:
- Uses pyserial via the bridge to read from COM3.
- Parses the JSON.
- Checks the temperature threshold.
- Sends a Telegram message using telegram-send (or the Telegram API).
- Appends data to a CSV file on the cloud.
Step 3: The AI Executes the Script
Because the AI runs in a sandbox (Railway) with access to libraries like requests, json, and csv, it can execute the script and keep polling the bridge. The script looks something like this (simplified):
import requests
import json
import csv
import time
from datetime import datetime
# Telegram config (from chat context)
TELEGRAM_TOKEN = "your_bot_token"
CHAT_ID = "your_chat_id"
# Bridge endpoint - the AI knows the bridge is active
bridge_url = "ws://localhost:8765" # internal bridge WebSocket
def send_telegram(message):
url = f"https://api.telegram.org/bot{TELEGRAM_TOKEN}/sendMessage"
requests.post(url, json={"chat_id": CHAT_ID, "text": message})
# Read from bridge (pseudo-code)
while True:
data = read_from_bridge("COM3", 115200) # AI handles bridge communication
if data:
temp = data.get("temp")
if temp and temp > 30:
send_telegram(f"⚠️ Temperature high: {temp}°C")
# Log to CSV
with open("sensor_log.csv", "a") as f:
writer = csv.writer(f)
writer.writerow([datetime.now(), temp, data.get("hum")])
time.sleep(30)
Note: The actual script avoids infinite loops (sandbox timeout is 30 seconds), so the AI uses a scheduling mechanism or a single-shot execution with a loop count.
What About Other MCUs?
| MCU Family | Connection | Typical Baud | Notes |
|---|---|---|---|
| Arduino Uno | USB-to-serial | 9600 or 115200 | Use Serial.print() in firmware |
| STM32 (Nucleo) | Virtual COM port | 115200 | Enable USART in CubeMX |
| ESP32 | USB-to-UART or native USB | 115200 | Use Serial.printf() for JSON |
| Raspberry Pi Pico | USB CDC | 115200 | Use stdio over USB |
All of them work the same way: the firmware sends text data, the bridge reads it, and the AI interprets and acts.
No Dashboard, No Buttons — Just Chat
This is the key difference from traditional IoT platforms. You don’t need to click through menus or configure integrations. You simply describe what you want in natural language, and the AI writes the Python code, connects to the bridge, and starts the data flow. Want to switch to an MQTT broker instead? Just say: “Change the connection to MQTT on broker.mosquitto.org:1883.” The AI rewrites the script and re-executes it.
Design Patterns for UART + AI
From my experience integrating dozens of MCUs, here are patterns that work well:
- JSON over UART — send structured data (
{"sensor": "temp", "value": 25.3}) for easy parsing. - Command-response — the MCU waits for a command string (e.g.,
LED_ON) and replies with an acknowledgment. - Batched logging — accumulate data in the MCU’s buffer and send it in one chunk every minute to reduce overhead.
- Error recovery — if the bridge disconnects, the MCU should keep logging locally and retransmit when reconnected.
Pitfalls to Avoid
- Baud rate mismatch — always verify that the bridge and MCU use the same baud rate. Use 115200 as default for modern MCUs.
- Buffer overflow — if the MCU sends data faster than the bridge reads, you’ll lose data. Implement flow control or reduce the send rate.
- Sandbox timeout — the AI’s Python execution environment has a 30-second max runtime. For long-running tasks, use the bridge’s built-in scheduling or have the AI generate a script that runs in chunks.
- No direct COM port access from the cloud — remember,
execute_pythonruns on the server, not on your PC. Always go through the Hardware Bridge for serial communication.
Why This Matters for Automation
By connecting UART devices to ASI Biont, you unlock:
- Predictive maintenance — the AI can analyze temperature trends and predict fan failure.
- Voice control — “Turn on the water pump” becomes a simple Telegram command.
- Cross-platform integration — mix an Arduino sensor with a Modbus PLC and an HTTP API camera in one workflow.
Real-World Impact
I’ve used this setup in a small greenhouse automation project. An ESP32 reads soil moisture and temperature, sends data via UART to a laptop running the bridge, and the AI agent controls irrigation relays based on weather forecasts from a public API. The entire integration took 15 minutes of chatting — no coding, no wiring changes, just describing the logic.
Get Started in 3 Steps
- Flash your MCU to send data over UART (e.g.,
Serial.println("{\"value\": 42}")). - Run the Hardware Bridge on your PC with your token and COM port.
- Open the ASI Biont chat and describe your automation: “Read from COM3, parse JSON, and if value > 50, send me an email.”
That’s it. The AI handles the rest.
Try It Now
Ready to connect your microcontroller to an AI agent? Visit asibiont.com, create an account, and start talking to your hardware. No dashboards, no long tutorials — just you, your MCU, and an AI that writes code for you.
For more details, check the official documentation on UART integration at docs.asibiont.com.
Comments