How USB-to-Serial (FTDI, CH340, CP2102) Integrates with AI Agent ASI Biont: Automate COM Port Data Collection Without Code

Introduction

In the world of embedded systems, USB-to-Serial adapters—based on FTDI (FT232RL), CH340, or CP2102 chips—are the unsung heroes that bridge microcontrollers (Arduino, ESP32, STM32) and sensors (DHT22, BMP280, GPS modules) to our computers. Whether you’re a hobbyist logging temperature data or an engineer flashing firmware to a PLC, the COM port (RS-232 via USB) is your gateway to real-time device interaction. But manual data collection is tedious: you open a terminal (like PuTTY or screen), copy-paste logs, and parse them by hand. What if an AI agent could do all that for you—read sensor data, detect anomalies, send alerts, and log to a database—without writing a single line of code?

Enter ASI Biont, an AI agent that connects to any device via a chat interface. For USB-to-Serial devices (FTDI, CH340, CP2102), ASI Biont uses the Hardware Bridge method: a small Python script (bridge.py) runs on your PC, opens the COM port via pyserial, and communicates with the AI in the cloud via HTTP long polling. You simply describe your task in the chat—e.g., “Read temperature from Arduino on COM3 at 115200 baud every 10 seconds and alert if above 30°C”—and the AI writes the integration code, sends commands through the bridge, and collects data. No dashboard, no plugins, no coding.

This article dives deep into the technical integration: how the bridge works, a real use case with an Arduino Uno (CH340) and a DHT22 sensor, code examples (both MicroPython on the device and Python on the bridge), and the metrics you’ll improve.

What Is a USB-to-Serial (FTDI, CH340, CP2102) and Why Connect It to an AI Agent?

A USB-to-Serial adapter converts USB signals to serial UART (RS-232 logic levels). The three most common chips are:

Chip Typical Baud Rate Common Devices Notes
FTDI FT232RL Up to 3 Mbps Arduino clones, FTDI breakout boards Industry standard, reliable, expensive
CH340G Up to 2 Mbps Cheap Arduino Nano clones, ESP8266 dev boards Very common in budget boards, driver issues on macOS
CP2102 Up to 1 Mbps Silicon Labs-based adapters, some GPS modules Good balance of cost and reliability

These adapters expose a virtual COM port on your OS (e.g., COM3 on Windows, /dev/ttyUSB0 on Linux). The device sends data as ASCII text or binary frames—for instance, an Arduino might print "Temperature: 25.4°C\n" every second.

The problem: Without an AI agent, you must manually read the port, parse each line, and act on it. With ASI Biont, the AI automates the entire pipeline: read → parse → analyze → alert → log. The AI can also write commands back to the device (e.g., turn on an LED when temperature drops).

How ASI Biont Connects to USB-to-Serial Devices: Hardware Bridge

ASI Biont does not run locally—it lives in the cloud. To access your local COM port, you run the Hardware Bridge (bridge.py) on your PC. Here’s the flow:

  1. User starts bridge.py with your token and port configuration:
    bash python bridge.py --token=YOUR_API_TOKEN --ports=COM3 --default-baud=115200
    The bridge opens COM3 at 115200 baud via pyserial and connects to ASI Biont’s cloud server via HTTP long polling.

  2. User describes the task in chat with the AI agent, e.g.:

    “Connect to COM3 at 115200 baud, read lines from an Arduino that sends temperature and humidity data in JSON format like {"temp":25.4,"hum":60}, log to a CSV file, and send me a Telegram alert if temperature exceeds 30°C.”

  3. AI uses the industrial_command tool to send commands to the bridge. The tool supports:

  4. protocol='serial://' with command='read' to read data
  5. protocol='serial://' with command='write' to send data to the device
  6. protocol='arduino://' (same as serial, but wrapper for convenience)

The AI does not write the bridge code—the bridge is already running. The AI just orchestrates commands.

  1. AI processes data using execute_python (sandboxed Python environment on the server) to parse JSON, compute averages, and send alerts via Telegram API (using requests library, which is allowed in the sandbox).

Important: The bridge does NOT have an HTTP API accessible from the cloud. All communication is via the industrial_command tool in the chat, which routes through ASI Biont’s infrastructure to the user’s bridge. You cannot send requests.get("http://localhost:8080")—that’s not how it works.

Real Use Case: Arduino + DHT22 → ASI Biont (CH340)

Let’s walk through a concrete scenario. You have an Arduino Uno with a CH340 chip, connected to a DHT22 temperature/humidity sensor. The Arduino is programmed (in MicroPython or Arduino C++) to send JSON over serial every 5 seconds.

Step 1: Device Code (MicroPython on Arduino)

# MicroPython on Arduino (or similar)
import machine
import dht
import utime
import json

sensor = dht.DHT22(machine.Pin(4))  # DHT22 on GPIO4
uart = machine.UART(0, baudrate=115200)  # Serial over USB

while True:
    sensor.measure()
    data = {
        "temp": sensor.temperature(),
        "hum": sensor.humidity()
    }
    uart.write(json.dumps(data) + "\n")
    utime.sleep(5)

This sends lines like {"temp":25.4,"hum":60.2} every 5 seconds.

Step 2: Run the Bridge

On your Windows PC (or Linux/macOS), you run:

pip install pyserial requests
python bridge.py --token=abc123 --ports=COM3 --default-baud=115200

The bridge connects to ASI Biont. You’ll see output: Connected to cloud. Listening for commands...

Step 3: Configure the AI Agent in Chat

You open the ASI Biont chat and type:

“I have a bridge running with COM3 at 115200 baud. An Arduino sends JSON lines with temperature and humidity. Read 10 lines, compute average temperature and humidity, log to a CSV file called sensor_log.csv on my local machine, and if average temperature > 28°C, send me a Telegram alert to @myuser. My Telegram bot token is 123456:ABC-DEF.”

Step 4: What the AI Does

The AI uses industrial_command to read lines:

# This is what the AI generates and executes (simplified)
import json
import csv
from datetime import datetime

# Step 1: Read 10 lines from bridge
lines = []
for _ in range(10):
    result = industrial_command(
        protocol='serial://',
        command='read',
        port='COM3',
        baud=115200,
        timeout=10  # wait up to 10 seconds for a line
    )
    lines.append(result['data'])

# Step 2: Parse JSON
temps = []
hums = []
for line in lines:
    try:
        data = json.loads(line.strip())
        temps.append(data['temp'])
        hums.append(data['hum'])
    except:
        pass

avg_temp = sum(temps) / len(temps) if temps else None
avg_hum = sum(hums) / len(hums) if hums else None

# Step 3: Write to CSV (via bridge write command? No—bridge cannot write files locally.
# Instead, AI uses execute_python to write to a file in the cloud sandbox,
# which is temporary. For persistent local storage, you'd use a cloud DB or
# ask the AI to send data via HTTP to a webhook.)
# For simplicity, we'll log to a cloud CSV (accessible via download):
with open('/tmp/sensor_log.csv', 'a', newline='') as f:
    writer = csv.writer(f)
    writer.writerow([datetime.now().isoformat(), avg_temp, avg_hum])

# Step 4: Send Telegram alert if needed
if avg_temp and avg_temp > 28:
    import requests
    bot_token = "123456:ABC-DEF"
    chat_id = "@myuser"
    msg = f"⚠️ High temperature alert! Average: {avg_temp:.1f}°C"
    requests.post(f"https://api.telegram.org/bot{bot_token}/sendMessage",
                  json={"chat_id": chat_id, "text": msg})

The AI then replies in chat:

✅ Read 10 lines. Average temperature: 27.3°C, average humidity: 58.1%. Logged to /tmp/sensor_log.csv. No alert needed (below 28°C).

If you want to write commands back to the Arduino (e.g., turn on an LED), the AI can use:

industrial_command(
    protocol='serial://',
    command='write',
    port='COM3',
    baud=115200,
    data='LED_ON\n'
)

The Arduino must have code to parse incoming commands.

Why This Integration Is Revolutionary

  • Zero coding required: You just describe the task in English. The AI writes the Python code, uses pyserial under the hood, and executes it in the sandbox. If you need to change the logic (e.g., log to InfluxDB instead of CSV), just ask.
  • Works with any chip: FTDI, CH340, CP2102—all appear as COM ports. The bridge abstracts the hardware.
  • Real-time automation: The AI can set up a repeating task (via a cron-like scheduler inside the chat) to read data every minute, compute statistics, and send reports.
  • Extendable: Combine with other protocols. For example, read sensor data via COM port, then publish to MQTT (using paho-mqtt in execute_python) for a smart home dashboard.

Measurable Results

Imagine a scenario: a small greenhouse with an Arduino reading temperature and humidity via CH340. Before ASI Biont:
- Manual: 20 minutes per day to check logs, 5 minutes to parse, 10 minutes to email report. Total: 35 minutes/day.
- With AI agent: 0 minutes manual. AI reads every 10 minutes, logs to Google Sheets (via HTTP API), and sends SMS alerts on anomalies.

Metrics improved:

Metric Before After
Daily time spent 35 min 0 min
Alert latency 1-2 hours (if checked manually) <1 minute
Data loss (missed logs) ~5% (human error) 0% (automated)
Report generation 10 min manual Instant (AI writes summary)

Conclusion

Integrating a USB-to-Serial device (FTDI, CH340, CP2102) with ASI Biont transforms a manual, error-prone process into a fully automated pipeline. The Hardware Bridge connects your local COM port to the AI cloud, and the AI agent handles everything—reading, parsing, alerting, logging—through a simple chat conversation. You don’t need to be a programmer; just describe what you want. The AI writes the code, uses pyserial and other libraries, and executes it in seconds.

Ready to automate your serial device? Try it now at asibiont.com. Connect your Arduino, ESP32, or any USB-to-Serial device, and let the AI do the work.

← All posts

Comments