Introduction
The Arduino Due is no ordinary microcontroller. With a 32-bit ARM Cortex-M3 processor running at 84 MHz, 512 KB flash, and 96 KB SRAM, it packs serious punch for real-time control, data acquisition, and even basic signal processing. But what if you could give it an AI brain? That’s exactly what ASI Biont’s AI agent does. Instead of hardcoding every decision logic on the Due, you connect it via a Hardware Bridge and let the AI handle complex analytics, logging, and decision-making. Whether you’re building a smart lab instrument, a robotics controller, or an industrial monitor, this integration turns your Due into a remotely commanded smart peripheral.
Why Connect Arduino Due to an AI Agent?
Traditionally, programming an Arduino means writing C++ sketches, flashing, and debugging. If you want to change behaviour, you reflash. With ASI Biont, the Due becomes a simple I/O gateway: it reads sensors and executes commands, while the AI runs in the cloud (or on your server) and makes high-level decisions. You can ask the AI to “monitor the temperature every 5 seconds and alert me if it exceeds 40°C” without ever opening the Arduino IDE. The AI writes the Python glue code, connects to the Due via a COM port bridge, and handles everything from data parsing to notifications.
How ASI Biont Connects to Arduino Due
The primary method is COM port (RS-232 over USB) via Hardware Bridge. The Due presents a virtual COM port when plugged in (on Windows, Linux, or macOS). You run a small Python application called bridge.py on your PC, which connects to ASI Biont’s cloud via WebSocket. The AI then uses the industrial_command tool with the serial:// protocol to send and receive data. Here’s the flow:
- Plug your Arduino Due into your computer. Identify the COM port (e.g.,
COM3on Windows,/dev/ttyACM0on Linux). - Download
bridge.pyfrom the ASI Biont dashboard (Devices → Create API Key → Download bridge). - Run the bridge with your API token and port:
python bridge.py --token=YOUR_TOKEN --ports=COM3 --baud 115200 - The bridge establishes a WebSocket connection to the ASI Biont cloud. Now the AI can send commands via
industrial_command(protocol='serial', command='serial_write_and_read', data='...'). - The microcontroller’s response is returned to the AI, which can then process it.
Important: The bridge does NOT host any HTTP server. All communication happens through the cloud WebSocket. Never try to send HTTP requests to localhost:8080 – that will not work.
Real‑World Example: Temperature Logger with Telegram Alerts
Let’s build a practical scenario: we’ll connect an LM35 temperature sensor to the Due, read the analog voltage, convert to Celsius, and stream it to the AI. The AI will check the value every 10 seconds and send a Telegram message if the temperature exceeds a threshold.
Arduino Due Sketch
Upload this sketch to your Due. It listens for commands like READ_TEMP and returns the temperature, or LED_ON to turn on the built‑in LED.
void setup() {
Serial.begin(115200);
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
}
void loop() {
if (Serial.available() > 0) {
String cmd = Serial.readStringUntil('\n');
cmd.trim();
if (cmd == "READ_TEMP") {
int raw = analogRead(A0); // LM35 on A0, 10mV/°C, 5V reference
float temp = (raw * 5.0 / 1024.0) * 100.0;
Serial.println(temp, 1); // e.g., "24.5"
} else if (cmd == "LED_ON") {
digitalWrite(13, HIGH);
Serial.println("OK");
} else if (cmd == "LED_OFF") {
digitalWrite(13, LOW);
Serial.println("OK");
} else {
Serial.println("UNKNOWN");
}
}
}
Pitfall: The Due’s ADC is 12‑bit (0–4095), but the above uses 1024 for simplicity. Adjust according to your reference voltage. Also, the LM35 output is linear: 10 mV per °C. At 5V reference, max readable temperature is about 150°C.
ASI Biont AI Agent Integration
Once the bridge is running, you can start a chat with the AI and give instructions like:
“Connect to Arduino Due on COM3, baud 115200. Send command READ_TEMP every 10 seconds. If temperature exceeds 35°C, send a Telegram alert to chat ID 123456789.”
The AI will automatically write the following Python code (it runs in a secure sandbox using execute_python or uses the industrial_command tool):
import time
import requests
from typing import Optional
TELEGRAM_TOKEN = "your_bot_token"
TELEGRAM_CHAT_ID = "123456789"
THRESHOLD = 35.0
def send_telegram(text: str):
url = f"https://api.telegram.org/bot{TELEGRAM_TOKEN}/sendMessage"
data = {"chat_id": TELEGRAM_CHAT_ID, "text": text}
requests.post(url, data=data)
# The AI will actually use the industrial_command tool to write/read the serial port.
# But for demonstration, here's how the bridge translates:
# Simulated read via serial_write_and_read
result = serial_write_and_read(data="524541445f54454d500a") # hex for "READ_TEMP\n"
temp_str = result # e.g., "24.5"
try:
temp = float(temp_str)
if temp > THRESHOLD:
send_telegram(f"⚠️ Temperature exceeded! Current: {temp}°C")
except ValueError:
pass
How it actually works: The AI uses industrial_command(protocol='serial', command='serial_write_and_read', data='524541445f54454d500a') and receives the reply "24.5". Then it compares the value and, if above threshold, can call a Telegram API via execute_python (the sandbox has requests). This way, no permanent script is needed – the AI orchestrates everything on demand.
Automating Repeated Data Collection
Instead of polling manually, you can ask the AI to create a scheduled task: “Monitor temperature every minute for the next 24 hours and log to a CSV file.” The AI will write a script that runs inside the sandbox (in a loop, but careful – while True will be killed after 30 seconds). For long‑running polling, you’d use the bridge’s built‑in polling feature (specify --rate=10 on bridge launch), or use an external scheduler. The AI can also leverage the execute_python environment to store data in a database (like PostgreSQL) that is available in the sandbox.
Pitfalls to Avoid
- Baud rate mismatch: Both sketch and bridge must use the same baud rate. The Due’s native USB (programming port) runs at 115200 by default.
- Newline handling: The
serial_readStringUntil('\n')expects a newline at the end. When sending via hex, be sure to append0A(newline). The bridge’s_parse_data_fieldaccepts both hex and escape sequences – you can send"READ_TEMP\n"directly in thedatafield. - Windows overlapped I/O: On Windows, pyserial’s write can sometimes return 0 bytes written due to overlapped I/O. The bridge automatically handles this by calling
CancelIoExandPurgeCommbefore retrying synchronously. If you see “written: 0” errors, update the bridge to the latest version. - Command collisions: If multiple scripts try to write to the same COM port simultaneously, data can corrupt. The bridge uses a rate limiter (
--rate) to slow commands, but it’s still single‑threaded. Avoid concurrent requests. - Power supply: The Due requires 7–12V on the power jack or 5V on the USB port. If you power it via USB from the same computer, be aware that some USB ports supply only 500 mA – not enough for many shields.
Other Connection Methods for Arduino Due
While COM port is the most straightforward, you can also use:
- MQTT – if you add an Ethernet shield (WIZnet) or WiFi module (ESP8266 via AT commands). Upload a sketch that publishes sensor data to an MQTT broker. Then ASI Biont’s AI can subscribe to that topic using
industrial_command(protocol='mqtt', command='subscribe', topic='sensors/temp'). This is useful when the Due is far from the PC. - SSH – if the Due is attached to a Raspberry Pi that acts as a gateway, you can SSH into the Pi and control the Due via serial forwarded over SSH. ASI Biont can connect via SSH using
paramikoinexecute_python.
Because ASI Biont supports execute_python with a rich set of libraries (pyserial, paho-mqtt, paramiko, pymodbus, etc.), you can connect the Due to any software interface you can write code for. You are not limited to the built‑in tools – describe your setup in chat, and the AI will generate the appropriate integration script.
Why This Beats Traditional Development
- No coding of AI logic on the microcontroller – you keep the Due’s firmware simple and robust.
- Instant reconfiguration – change thresholds, add alerts, or switch data logging targets by simply talking to the AI.
- Zero infrastructure setup – the bridge runs on commodity hardware (laptop, desktop) and the AI lives in the cloud.
- Extensible – want to combine data from multiple Arduino Dues? Run multiple bridge instances, each with a different COM port. The AI can handle them all.
Getting Started
- Create an account on asibiont.com.
- Go to the dashboard → Devices → Generate API key → Download bridge.py.
- Connect your Arduino Due and run the bridge with your token and port.
- Open the AI chat and say: “Read temperature from Due every 10 seconds. If above 30°C, turn on the LED and send me a Telegram message.”
The AI will instantly generate and execute the necessary code. No manual coding, no waiting for SDKs. Try it now and transform your Due into an AI‑powered measurement station.
Experienced a pitfall? Share in the comments below – the community thrives on real‑world insights.
Comments