UART Meets AI: How to Connect Any MCU (Arduino, ESP32, STM32) to ASI Biont via COM Port

Introduction

For years, the serial port has been the unsung hero of embedded development. From Arduino hobbyists blinking an LED to factory engineers reading Modbus RTU sensors, UART (Universal Asynchronous Receiver-Transmitter) remains the simplest and most universal way to talk to microcontrollers. But what if you could connect that same $2 ESP32 or a $5 Arduino Nano directly to an AI agent — and have it not just read data, but analyze trends, send alerts, and control your hardware — all without writing a single line of integration code yourself?

That's exactly what ASI Biont enables. In this guide, I'll walk through how ASI Biont's AI agent connects to any microcontroller via UART (COM port) using the Hardware Bridge, with real code examples, a complete use case, and the architectural choices that make it work. No dashboards, no plugins — just chat.

Why UART? Why Now?

UART is the lowest common denominator in embedded systems. Every MCU — Arduino Uno, ESP32, STM32, Raspberry Pi Pico, PIC, AVR — exposes at least one serial interface. According to datasheets from Microchip, STMicroelectronics, and Espressif, over 90% of microcontrollers manufactured in 2025 support UART natively. It's also the backbone of industrial protocols like RS-232, RS-485, and Modbus RTU.

Connecting UART to an AI agent unlocks immediate value:
- Read sensor data (temperature, humidity, pressure, gas, motion) without cloud middlemen.
- Control actuators (servos, relays, LEDs, motors) in real time.
- Log and analyze historical readings for predictive maintenance.
- Trigger alerts when thresholds are exceeded — via Telegram, email, or webhook.

ASI Biont connects to UART devices through the Hardware Bridge — a lightweight Python application (bridge.py) that runs on your local PC (Windows, Linux, or macOS). The bridge connects to the ASI Biont cloud via WebSocket (the only communication channel), and the AI agent sends commands through the industrial_command tool, which are routed back to your bridge. The bridge then writes to and reads from your COM port using the pyserial library. Data is exchanged in hex format, but the bridge also accepts escape sequences like LED_ON\.

How the Hardware Bridge Works

The bridge architecture is deliberately simple to avoid security holes and configuration nightmares:

Component Role
bridge.py Local application on your PC
WebSocket Single encrypted channel to ASI Biont cloud
pyserial Reads/writes to COM port (e.g., COM3, /dev/ttyUSB0)
industrial_command Tool AI uses to send serial_write_and_read commands

The AI sends a command like:

industrial_command(
    protocol='serial',
    command='serial_write_and_read',
    data='48454c500a',  # HEX for "HELP\
"
    port='COM3',
    baud=115200
)

The bridge receives it, writes HELP\ to the port, reads the response, and sends it back to the AI. The _parse_data_field() function in bridge.py handles both hex strings and plain escape sequences.

Important: On Windows, when pyserial fails to write (returning 0 bytes written), the bridge automatically applies CancelIoEx (cancels pending overlapped operations), PurgeComm (clears buffers), and retries with synchronous WriteFile. This ensures reliability even with flaky USB-to-serial adapters.

Real Use Case: ESP32 + DHT22 Temperature/Humidity Sensor

Let's take a concrete example: an ESP32 with a DHT22 sensor connected to your PC via USB-UART (FTDI or CP2102). The ESP32 firmware reads temperature and humidity every 2 seconds and prints them as JSON over serial: {"temp":23.5,"hum":62.1}.

Step 1: Set Up the Hardware

  1. Connect DHT22 data pin to GPIO4 on ESP32.
  2. Power ESP32 via USB (5V).
  3. Flash the following firmware using Arduino IDE or PlatformIO:

```cpp

include

define DHTPIN 4

define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(115200);
dht.begin();
}

void loop() {
float t = dht.readTemperature();
float h = dht.readHumidity();
if (!isnan(t) && !isnan(h)) {
Serial.print("{\\

← All posts

Comments