Introduction: Why Connect STM32 to an AI Agent?
If you're working with STM32 microcontrollers—whether it's the budget-friendly Blue Pill (STM32F103C8T6) or the more powerful Nucleo boards—you know the drill: writing firmware, debugging UART, setting up communication protocols, and then manually parsing data. It's powerful, but time-consuming. What if you could offload all the integration logic to an AI agent?
ASI Biont is an AI agent that connects to your devices through chat. You describe your setup, provide connection parameters, and the AI writes the Python code to communicate with your STM32 in seconds. No dashboard, no 'add device' button—just a conversation. This article shows you exactly how to integrate STM32 (Blue Pill or Nucleo) with ASI Biont, using real protocols like Serial (COM port), Modbus/TCP, and MQTT. We'll cover a complete use case: reading temperature from a sensor connected to your STM32 and getting Telegram alerts when values exceed a threshold.
How ASI Biont Connects to STM32
ASI Biont doesn't have a built-in 'STM32 driver'. Instead, it uses execute_python—a sandboxed Python environment on the cloud server—to generate custom integration scripts on the fly. The AI can use any of these supported protocols to talk to your STM32:
| Protocol | How ASI Biont Uses It | Best for STM32 |
|---|---|---|
| Serial (COM port) | Via Hardware Bridge (bridge.py on your PC) + pyserial |
Direct UART communication with STM32 firmware |
| Modbus/TCP | Via pymodbus inside execute_python |
Industrial STM32 boards with Ethernet (e.g., Nucleo-F767ZI) |
| MQTT | Via paho-mqtt inside execute_python |
STM32 + ESP8266/ESP32 Wi-Fi module for IoT |
| SSH | Via paramiko inside execute_python |
If STM32 runs Linux (e.g., STM32MP1) |
For most hobby and industrial STM32 projects, Serial (COM port) is the go-to method. Let's dive into a concrete example.
Real-World Use Case: STM32 Blue Pill + DHT22 Temperature Sensor → Telegram Alerts
Hardware setup:
- STM32 Blue Pill (STM32F103C8T6)
- DHT22 temperature/humidity sensor connected to PA0
- USB-to-UART converter (e.g., CH340G) connected to PA9 (TX) and PA10 (RX)
- Your PC running Windows (though macOS/Linux works too)
Goal: Read temperature every 10 seconds from the STM32, send data to ASI Biont, and have the AI send a Telegram message if temperature exceeds 30°C.
Step 1: Flash the STM32 with a Simple UART Firmware
First, your STM32 needs to send sensor data over UART. Here's a minimal Arduino-style sketch (using STM32duino core) that reads DHT22 and prints JSON over serial:
#include <DHT.h>
#define DHTPIN PA0
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial1.begin(115200); // UART1 on PA9/PA10
dht.begin();
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (!isnan(h) && !isnan(t)) {
Serial1.print("{\"temp\":");
Serial1.print(t);
Serial1.print(",\"hum\":");
Serial1.print(h);
Serial1.println("}");
}
delay(10000);
}
Flash it using ST-Link or USB-to-UART (via bootloader).
Step 2: Run the Hardware Bridge on Your PC
ASI Biont's Hardware Bridge is a small Python script (bridge.py) that you run locally. It connects to ASI Biont via WebSocket and gives the AI access to your COM ports. Download it from ASI Biont's GitHub (or ask the AI agent for the link during chat). Run:
python bridge.py --port COM3 --baud 115200
You'll see Connected to ASI Biont. Waiting for commands...
Step 3: Chat with ASI Biont
Now open the chat on asibiont.com. Tell the AI:
"I have an STM32 Blue Pill connected via COM3 at 115200 baud. It sends JSON with temperature and humidity every 10 seconds. Read the data continuously, and if temperature exceeds 30°C, send me a Telegram alert."
ASI Biont will generate a Python script using pyserial (through the bridge) and python-telegram-bot (or a simple HTTP request to Telegram API). The AI runs it in the sandbox and starts monitoring. Here's what the generated code looks like (simplified):
import serial
import requests
import json
import time
# Bridge connects to local COM port
ser = serial.Serial('COM3', 115200, timeout=1)
TELEGRAM_BOT_TOKEN = 'YOUR_BOT_TOKEN' # AI asks you for this
TELEGRAM_CHAT_ID = 'YOUR_CHAT_ID'
def send_telegram(message):
url = f'https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage'
requests.post(url, json={'chat_id': TELEGRAM_CHAT_ID, 'text': message})
while True:
line = ser.readline().decode('utf-8').strip()
if line:
try:
data = json.loads(line)
temp = data['temp']
hum = data['hum']
print(f"Temp: {temp}°C, Humidity: {hum}%")
if temp > 30:
send_telegram(f"⚠️ High temperature alert: {temp}°C!")
except:
pass
time.sleep(1)
The AI will ask you for your Telegram bot token and chat ID (or you can provide them upfront). Once running, every time the temperature spikes, you get an instant alert on your phone.
Alternative: Modbus/TCP with Nucleo
If you're using a Nucleo board with Ethernet (like Nucleo-F767ZI), you can flash a Modbus/TCP slave firmware (e.g., using libmodbus or FreeModbus). Then in ASI Biont chat, say:
"Connect to my Nucleo board at 192.168.1.100 port 502 via Modbus TCP. Read holding register 0 (temperature) every 5 seconds. If value > 30, send an email."
The AI uses pymodbus inside execute_python to poll the register and trigger actions. No local bridge needed—just network access.
Why This Changes Everything
Traditionally, integrating STM32 with cloud services meant writing custom Python scripts, handling errors, and maintaining connections. With ASI Biont:
- No manual coding: Describe your device, and AI writes the integration code.
- Instant flexibility: Change protocols (Serial→MQTT→Modbus) in seconds by just describing it.
- No dashboard overhead: Everything happens through chat—no bloated UI.
- Works with any STM32: As long as it communicates via UART, Ethernet, or Wi-Fi, you're good.
Pitfalls to Avoid
- Baud rate mismatch: Ensure your STM32 firmware and bridge use the same baud rate. Common: 115200 or 9600.
- Bridge must stay running: If you close
bridge.py, the connection drops. Run it in a background terminal or as a service. - Firewall/port blocking: For Modbus/TCP, ensure port 502 is open. For MQTT, use 1883 or 8883 (TLS).
- Telegram bot limits: Free bots have rate limits (~30 messages/sec). For high-frequency alerts, use batching.
Conclusion
Integrating STM32 (Blue Pill, Nucleo) with ASI Biont is straightforward: flash a UART firmware, run the bridge, and chat with the AI. The AI handles all the Python code—from parsing serial data to sending Telegram alerts. Whether you're monitoring a greenhouse, controlling a motor, or logging industrial data, ASI Biont turns your microcontroller into a smart, AI-driven edge device.
Ready to try it? Go to asibiont.com, open the chat, and describe your STM32 setup. The AI will connect and control it in minutes. No coding required—just conversation.
Comments