Introduction
In the world of embedded systems, UART (Universal Asynchronous Receiver-Transmitter) is the most ubiquitous serial communication protocol. From Arduino Uno to ESP32, from STM32 to Raspberry Pi Pico, virtually every microcontroller on the market exposes one or more UART pins. This makes UART the universal "duct tape" for connecting sensors, actuators, GPS modules, and industrial controllers to a host computer. But what if you could connect that same serial stream directly to an AI agent — one that can parse data, make decisions, and send commands back in real time?
That's exactly what ASI Biont does. Instead of writing custom middleware or building a dashboard, you simply describe your setup in a chat conversation. The AI agent writes the integration code on the fly, using the Hardware Bridge to tunnel UART data from your PC to the cloud. This article shows you how to connect any MCU via its UART to ASI Biont, with working code examples and real-world scenarios.
Why UART + AI Agent?
UART is simple, reliable, and found everywhere. But its main limitation is that the processing logic is typically locked inside the microcontroller's firmware. If you want to change behavior — adjust thresholds, log data to a cloud database, or trigger a Telegram alert — you usually need to reflash the MCU or write a companion script on the PC. ASI Biont eliminates this bottleneck by acting as a smart bridge: it reads serial data from the MCU, interprets it with AI, and can respond with commands that the MCU executes.
Typical use cases include:
- Reading temperature/humidity from an Arduino with DHT22 and having the AI agent analyze trends and send alerts.
- Controlling servo motors or relays on an ESP32 based on natural language requests (e.g., "turn on the pump if temperature exceeds 30°C").
- Parsing NMEA sentences from a GPS module and plotting routes on a map without writing a single line of Python beforehand.
How ASI Biont Connects to UART Devices
ASI Biont connects to UART devices through a local bridge application (bridge.py) that the user runs on their Windows, Linux, or macOS machine. The bridge establishes a WebSocket connection to the ASI Biont cloud (with automatic fallback to HTTP short-polling), and the AI agent sends commands through the industrial_command tool. The bridge then reads/writes to the COM port using pyserial.
Step-by-Step Setup
- Download bridge.py — Get it from the ASI Biont dashboard (Devices → Create API Key → Download bridge).
- Run the bridge with your API token and COM port parameters:
bash python bridge.py --token=YOUR_TOKEN --ports=COM3 --default-baud=115200 - Connect your MCU — Plug your Arduino, ESP32, or any UART device into your PC via USB-to-serial adapter.
- Tell the AI agent — In the ASI Biont chat, describe what you want: "Connect to COM3 at 115200 baud, read the temperature every 10 seconds, and send me an alert if it goes above 30°C."
The AI agent then generates and executes the appropriate code using industrial_command with the serial:// protocol. No manual coding required.
Practical Example: Arduino with DHT22 Temperature Sensor
Hardware Setup
| Component | Connection |
|---|---|
| Arduino Uno | USB to PC (COM3) |
| DHT22 sensor | VCC → 5V, GND → GND, Data → Digital Pin 2 |
| Optional: LED | Anode → Pin 13, Cathode → GND |
Arduino Firmware (Upload once)
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200);
dht.begin();
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("ERROR");
return;
}
Serial.print("TEMP:");
Serial.print(t);
Serial.print(",HUM:");
Serial.println(h);
delay(5000);
}
AI Agent Integration (via Chat)
In the ASI Biont chat, you type:
"Read from COM3 at 115200 baud. The device sends lines like 'TEMP:25.3,HUM:60.1' every 5 seconds. Parse the data, log it to a CSV file on my desktop, and if temperature exceeds 30°C, send me a Telegram alert."
The AI agent responds with the following code (which it executes in its sandbox):
import serial
import time
import csv
import requests
from datetime import datetime
# Configuration
PORT = "COM3"
BAUD = 115200
TELEGRAM_BOT_TOKEN = "YOUR_BOT_TOKEN"
TELEGRAM_CHAT_ID = "YOUR_CHAT_ID"
CSV_PATH = r"C:\Users\YourName\Desktop\sensor_log.csv"
# Open serial port
ser = serial.Serial(PORT, BAUD, timeout=1)
time.sleep(2) # Wait for Arduino reset
# Initialize CSV file with headers
with open(CSV_PATH, mode='a', newline='') as file:
writer = csv.writer(file)
writer.writerow(["timestamp", "temperature", "humidity"])
def send_telegram(message):
url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage"
payload = {"chat_id": TELEGRAM_CHAT_ID, "text": message}
requests.post(url, json=payload)
# Main loop (runs for 30 seconds due to sandbox timeout)
start_time = time.time()
while time.time() - start_time < 30:
line = ser.readline().decode('utf-8').strip()
if line.startswith("TEMP:"):
try:
parts = line.split(',')
temp = float(parts[0].split(':')[1])
hum = float(parts[1].split(':')[1])
timestamp = datetime.now().isoformat()
# Log to CSV
with open(CSV_PATH, mode='a', newline='') as file:
writer = csv.writer(file)
writer.writerow([timestamp, temp, hum])
print(f"Logged: {temp}°C, {hum}%")
# Alert if temperature > 30°C
if temp > 30.0:
send_telegram(f"⚠️ High temperature alert: {temp}°C at {timestamp}")
print("Telegram alert sent!")
except Exception as e:
print(f"Parse error: {e}")
ser.close()
print("Session complete. Data logged to CSV.")
Note: The sandbox timeout is 30 seconds, so this script runs for a single monitoring session. For continuous operation, you would set up a scheduled task on your PC that runs the bridge with a longer loop — but the AI can guide you through that too.
Advanced Scenario: Controlling an LED via Chat
Want to turn an LED on and off by just talking to the AI? The same setup works in reverse. The AI agent sends a command to the bridge, which writes a character to the COM port. Your Arduino firmware interprets it:
void loop() {
if (Serial.available() > 0) {
char cmd = Serial.read();
if (cmd == '1') digitalWrite(13, HIGH);
else if (cmd == '0') digitalWrite(13, LOW);
}
}
In the chat, you say: "Turn on the LED connected to pin 13." The AI agent calls:
industrial_command(
protocol='serial',
command='write',
port='COM3',
baud=115200,
data='1'
)
The bridge writes 1 to the serial port, and the LED lights up. No reflashing, no manual serial monitor.
Connecting Any Device via execute_python
If your device doesn't use UART but communicates over MQTT, HTTP, Modbus, or any other protocol, ASI Biont handles that too through execute_python. The AI agent has access to a rich sandbox with libraries for:
- MQTT (paho-mqtt) — for ESP32 or smart home devices
- Modbus/TCP (pymodbus) — for industrial PLCs
- SSH (paramiko) — for Raspberry Pi and single-board computers
- OPC UA (opcua-asyncio) — for factory automation servers
- HTTP/WebSocket (aiohttp, requests, websockets) — for any REST API device
You just describe your setup in natural language. For example:
"Connect to my Raspberry Pi at 192.168.1.100 via SSH. Run a Python script that reads the CPU temperature every minute and logs it to a PostgreSQL database."
The AI writes the paramiko script, executes it in the sandbox, and the data starts flowing. No dashboard configuration, no plugin installation.
Real-World Scenario: Predictive Maintenance with GPS Tracker
A logistics company uses a GPS tracker that outputs NMEA sentences over UART. Instead of writing a custom parser and database connector, they connect the tracker to a PC running bridge.py. In the ASI Biont chat, they describe:
"Read from COM4 at 9600 baud. Parse GGA sentences for latitude, longitude, and altitude. Store coordinates in a MongoDB collection. If the tracker leaves a geofence (within 1 km of lat=48.8566, lon=2.3522), send an email alert."
The AI agent generates the full integration in seconds, including the geofencing logic and email notification via SendGrid. The company now has real-time tracking without hiring a developer.
Why This Approach Matters
Traditional integration requires:
- Writing a Python script with pyserial
- Handling errors and reconnection
- Parsing protocols
- Connecting to databases or messaging services
- Deploying and monitoring the script
With ASI Biont, the AI agent does all of this automatically. You skip the coding phase and go straight to results. And because the agent is conversational, you can iterate in real time: "Add a 5-second delay between reads" or "Also log to InfluxDB." The AI adapts instantly.
Conclusion
UART remains the most accessible interface for hobbyists and professionals alike. By bridging it to ASI Biont, you unlock the full power of an AI agent that can monitor, analyze, and control your hardware — all through natural language. Whether you're building a smart greenhouse, a predictive maintenance system, or just want to log sensor data without writing boilerplate code, the combination of UART and ASI Biont is a game-changer.
Ready to connect your MCU to an AI agent?
Go to asibiont.com, create an API key, download bridge.py, and start a chat. Tell the AI what you want to do — and watch it write the integration code for you in seconds.
Comments