UART (any MCU) + ASI Biont: Zero-Code AI Integration for Microcontrollers via COM Port

Introduction

Microcontrollers (MCUs) like Arduino, ESP32, STM32, and Raspberry Pi Pico communicate with the outside world primarily via UART (Universal Asynchronous Receiver-Transmitter). Developers often write custom Python or C scripts to read sensor data, parse responses, and trigger actions. This manual process is time-consuming, error-prone, and requires constant monitoring. ASI Biont eliminates this bottleneck by letting an AI agent connect directly to any MCU through a COM port (RS-232/RS-485) using a Hardware Bridge. Instead of writing glue code, you simply describe your device and desired behavior in natural language — the AI handles parsing, logging, notifications, and automation.

How ASI Biont Connects to UART Devices

ASI Biont uses a Hardware Bridge (bridge.py) that runs on your local PC (Windows, Linux, macOS). The bridge connects to the ASI Biont cloud via WebSocket — the only communication channel. When you ask the AI to interact with your MCU, it sends commands through the industrial_command tool with the serial:// protocol. The bridge receives the command, writes data to the COM port via pyserial, reads the response, and sends it back to the AI.

Key connection parameters:
- COM port (e.g., COM3, /dev/ttyUSB0)
- Baud rate (9600, 115200, 57600, etc.)
- Data format: hex string (e.g., "48454c500a" for HELP\n) or escape sequences (e.g., "BLUE_ON\n")
- Atomic operation: serial_write_and_read(data=hex_string) — write then immediate read

Bridge reliability on Windows: When a write fails (written: 0 bytes), the bridge automatically applies CancelIoEx (cancel pending overlapped operations), PurgeComm (clear buffers), and fallback to synchronous WriteFile without overlapped I/O.

Real Use Case: Arduino Uno + DHT22 Temperature/Humidity Sensor

Scenario

Connect an Arduino Uno to ASI Biont via COM port (COM3, 115200 baud). The Arduino reads a DHT22 sensor every 5 seconds and prints the data as a JSON string over serial. The AI agent parses the data, logs it to a database, and sends a Telegram alert if temperature exceeds 30°C.

Arduino Code (already flashed on MCU)

#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.print("{\"temp\":");
    Serial.print(t);
    Serial.print(",\"hum\":");
    Serial.print(h);
    Serial.println("}");
  }
  delay(5000);
}

Connecting via ASI Biont (User Chat)

User: "Connect to Arduino on COM3 at 115200 baud. Read the serial data every 10 seconds. If temperature > 30°C, send me a Telegram alert. Log all readings to a CSV file."

ASI Biont AI: The AI generates the integration script using execute_python and the industrial_command tool. It uses the Hardware Bridge to perform periodic reads.

Step-by-step AI actions:
1. Verifies connection by sending HELP (HELP protocol) — device responds with supported commands.
2. Sets up a loop (within sandbox 30-second limit) to read data via serial_write_and_read(data="") — empty write triggers a read.
3. Parses the JSON response.
4. Compares temperature with threshold.
5. Sends Telegram message via requests (using a bot token you provide).
6. Appends data to a CSV file stored on the ASI Biont cloud.

Example AI-generated code snippet (simplified):

import json
import csv
import requests
from datetime import datetime

# Assume bridge is connected, AI uses industrial_command internally
# This code runs in execute_python sandbox

def parse_and_alert(raw_line):
    data = json.loads(raw_line)
    temp = data['temp']
    hum = data['hum']
    timestamp = datetime.now().isoformat()

    # Log to CSV
    with open('/tmp/sensor_log.csv', 'a') as f:
        writer = csv.writer(f)
        writer.writerow([timestamp, temp, hum])

    # Alert if threshold exceeded
    if temp > 30.0:
        bot_token = "YOUR_BOT_TOKEN"
        chat_id = "YOUR_CHAT_ID"
        msg = f"⚠️ Temperature alert: {temp}°C at {timestamp}"
        requests.post(f"https://api.telegram.org/bot{bot_token}/sendMessage",
                      json={"chat_id": chat_id, "text": msg})

    return f"Logged: {temp}°C, {hum}%"

Comparison of Integration Methods

Method Latency Complexity Best For
Hardware Bridge (COM) ~50-200ms Low (plug & play) Local MCUs with serial output
MQTT ~100-500ms Medium (need broker) IoT devices with network stack
SSH ~200ms-1s Low (if device supports SSH) Single-board computers (RPi)
Modbus/TCP ~10-50ms Medium (protocol knowledge) Industrial PLCs
HTTP API ~100-500ms Low (REST) Smart plugs, cameras
execute_python (cloud-only) N/A for COM High (no local hardware access) Cloud APIs, databases

Why This Matters

  • Zero-code: No need to write Python scripts for serial parsing, logging, or alerting. The AI does it in seconds.
  • Instant reaction: AI monitors data continuously (within sandbox limits) and triggers actions immediately.
  • Flexibility: Connect any MCU — Arduino, ESP32, STM32, Raspberry Pi Pico — without waiting for platform support.
  • Cost savings: Eliminate hours of manual debugging and maintenance.

How to Get Started

  1. Download bridge.py from the ASI Biont dashboard (Devices → Create API Key → Download bridge).
  2. Run: python bridge.py --token=YOUR_TOKEN --ports=COM3 --baud 115200
  3. Open the ASI Biont chat and describe your device and automation needs.
  4. The AI connects, parses data, and executes your workflow.

Conclusion

Integrating UART-based microcontrollers with an AI agent is no longer a development project — it's a conversation. ASI Biont bridges the gap between hardware and intelligence, letting you focus on what matters: building smarter systems. Try it today at asibiont.com.

← All posts

Comments