Introduction
Imagine controlling an SPI temperature sensor, writing data to an SD card, or updating an OLED display — all through natural language commands in a chat. With ASI Biont, this is not a futuristic dream but a practical reality. SPI (Serial Peripheral Interface) is one of the most widely used synchronous serial communication protocols in embedded systems. It connects microcontrollers to sensors (temperature, pressure, accelerometers), displays (OLED, TFT), memory cards (SD/MMC), and other peripherals. However, integrating SPI devices with an AI agent traditionally required custom firmware, middleware, and manual coding. ASI Biont eliminates that barrier by allowing you to connect any SPI device through its Hardware Bridge or direct MQTT/SSH methods — and the AI agent writes the integration code for you in seconds.
Why Connect SPI Devices to an AI Agent?
SPI devices are ubiquitous in IoT, industrial automation, and hobbyist projects. A typical scenario: you have an ESP32 with an SPI temperature sensor (MAX31855) and an OLED display. You want the AI to read temperature data, log it to a cloud database, and send alerts via Telegram when thresholds are exceeded. Without an AI agent, you would need to write Python or MicroPython code, set up a web server, implement MQTT, and handle error cases. With ASI Biont, you simply describe your setup in the chat: "Connect to my ESP32 via MQTT, read temperature from the MAX31855 sensor via SPI, display it on the OLED, and send me a Telegram message if it exceeds 50°C." The AI generates the complete code, executes it, and maintains the connection.
Which Connection Method Does ASI Biont Use for SPI Devices?
SPI itself is a low-level protocol that operates over physical wires (MOSI, MISO, SCLK, CS). To connect an SPI device to ASI Biont, you need a bridge — a microcontroller or single-board computer that talks SPI locally and communicates with the AI agent over the internet. ASI Biont supports four primary methods for such scenarios:
| Method | Best For | How It Works |
|---|---|---|
| Hardware Bridge (bridge.py) | Windows/Linux PC with USB-connected microcontroller (Arduino, ESP32) | User runs bridge.py on their PC. AI sends commands via industrial_command(protocol='serial://') to the bridge, which writes/reads to the COM port. The microcontroller runs firmware that translates serial commands to SPI transactions. |
| MQTT | ESP32/ESP8266 with Wi-Fi | Microcontroller publishes sensor data or subscribes to commands via MQTT broker. AI uses execute_python with paho-mqtt to subscribe/publish. SPI operations happen on the microcontroller firmware. |
| SSH | Raspberry Pi, Orange Pi, BeagleBone | AI connects via SSH (paramiko inside execute_python) to the SBC, runs Python scripts that use spidev or RPi.GPIO to control SPI devices directly. |
| execute_python (universal) | Any device with an API or network stack | AI writes a Python script that runs in the cloud sandbox and communicates with the device via MQTT, HTTP, or SSH. The script can include spidev calls only if executed on the device itself (via SSH). |
For most SPI integrations, the Hardware Bridge (for USB-connected microcontrollers) or SSH (for single-board computers) are the most practical. Let's examine a concrete example.
Concrete Use Case: ESP32 + SPI Temperature Sensor + OLED Display + ASI Biont
Scenario
You have an ESP32 development board with:
- MAX31855 thermocouple amplifier (SPI interface) connected to VSPI (GPIO 18/19/23/5)
- SSD1306 128x64 OLED display (SPI interface) connected to HSPI (GPIO 13/14/15/2)
- MicroSD card module (SPI) connected to the same VSPI bus with a different CS pin
The ESP32 runs MicroPython firmware that exposes MQTT topics:
- esp32/temperature — publishes temperature in °C every 10 seconds
- esp32/oled — subscribes to display text commands
- esp32/sd — subscribes to file write/read commands
Step 1: User Describes the Task in Chat
The user writes:
"Connect to my ESP32 via MQTT broker at 192.168.1.100:1883. Subscribe to topic esp32/temperature. Every time temperature exceeds 50°C, send me a Telegram alert and also publish a command to esp32/oled to display 'HIGH TEMP ALERT'. Also log the temperature to a local CSV file via the SD card."
Step 2: AI Generates the Integration Code
ASI Biont's AI agent analyzes the request and writes a Python script using execute_python with paho-mqtt. The script runs in the cloud sandbox (30-second timeout per execution, but can be scheduled or kept alive with a subscription loop). Here's the generated code:
import paho.mqtt.client as mqtt
import json
import csv
import io
from datetime import datetime
# Configuration
BROKER = "192.168.1.100"
PORT = 1883
TEMP_TOPIC = "esp32/temperature"
OLED_TOPIC = "esp32/oled"
SD_TOPIC = "esp32/sd_write"
TELEGRAM_BOT_TOKEN = "YOUR_BOT_TOKEN"
TELEGRAM_CHAT_ID = "YOUR_CHAT_ID"
ALERT_THRESHOLD = 50.0
# Store recent temperatures
temp_history = []
def on_connect(client, userdata, flags, rc):
print(f"Connected to MQTT broker with result code {rc}")
client.subscribe(TEMP_TOPIC)
def on_message(client, userdata, msg):
global temp_history
try:
payload = json.loads(msg.payload.decode())
temperature = payload.get("temperature")
if temperature is None:
return
print(f"Received temperature: {temperature}°C")
timestamp = datetime.now().isoformat()
temp_history.append((timestamp, temperature))
# Log to SD card via MQTT command
log_line = f"{timestamp},{temperature}\n"
client.publish(SD_TOPIC, f"append,data/temp_log.csv,{log_line}")
# Check threshold
if temperature > ALERT_THRESHOLD:
# Send Telegram alert (using requests library)
import requests
telegram_url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage"
requests.post(telegram_url, json={
"chat_id": TELEGRAM_CHAT_ID,
"text": f"⚠️ HIGH TEMP ALERT: {temperature}°C at {timestamp}"
})
# Display on OLED
client.publish(OLED_TOPIC, "HIGHTEMP")
except Exception as e:
print(f"Error processing message: {e}")
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect(BROKER, PORT, 60)
client.loop_start() # Non-blocking loop
# Keep the script alive for 30 seconds to receive messages
import time
time.sleep(25)
# Print summary
print(f"Collected {len(temp_history)} temperature readings.")
# Optionally save to cloud storage: use requests to POST to a webhook
Step 3: ESP32 MicroPython Firmware (Provided by User or Generated)
The user may also ask the AI to generate the ESP32 firmware. The AI can produce a MicroPython script that initializes SPI, reads MAX31855, drives the OLED, and handles SD card writes:
# ESP32 MicroPython code (simplified)
import machine
import time
import ujson
from umqtt.simple import MQTTClient
# SPI for MAX31855 (VSPI)
spi_temp = machine.SPI(2, baudrate=1000000, polarity=0, phase=0)
cs_temp = machine.Pin(5, machine.Pin.OUT)
# SPI for OLED (HSPI)
spi_oled = machine.SPI(1, baudrate=8000000, polarity=0, phase=0)
cs_oled = machine.Pin(2, machine.Pin.OUT)
dc_oled = machine.Pin(15, machine.Pin.OUT)
rst_oled = machine.Pin(14, machine.Pin.OUT)
# MQTT setup
client = MQTTClient("esp32_temp", "192.168.1.100")
client.connect()
while True:
# Read temperature
cs_temp.value(0)
data = spi_temp.read(4)
cs_temp.value(1)
temp_c = ((data[0] << 8 | data[1]) >> 2) * 0.25
# Publish
client.publish(b"esp32/temperature", ujson.dumps({"temperature": temp_c}))
time.sleep(10)
How the Integration Works End-to-End
- User runs bridge.py on their PC (if using Hardware Bridge) or configures the ESP32 MQTT broker address.
- User describes the integration in the ASI Biont chat: device type, connection parameters, desired actions.
- AI generates the Python code using
execute_pythonwith paho-mqtt (or paramiko for SSH). The code runs in the cloud sandbox, subscribing to MQTT topics or reading from the bridge. - AI maintains the connection: For long-running integrations, the AI can schedule periodic execution (every 30 seconds) or use a persistent MQTT subscription loop that restarts on timeout.
- User interacts via chat: "What's the current temperature?" or "Display 'Hello World' on the OLED" — the AI sends appropriate commands.
Why This Approach Is Revolutionary
- Zero manual coding: The AI writes, tests, and debugs the integration code. You don't need to learn pyserial, spidev, or MQTT details.
- Universal connectivity: Whether your SPI device is behind a USB-to-serial adapter, on a Raspberry Pi GPIO, or on an ESP32 with Wi-Fi, ASI Biont can reach it.
- Natural language control: Once connected, you control the device by typing commands like "Read the temperature" or "Write 'Hello' to the OLED."
- Automation scenarios: Combine SPI data with other sources. For example: "If temperature > 50°C, send an email, log to Google Sheets, and turn on a fan via Modbus."
Alternative Approaches Compared
| Method | Pros | Cons | Best Use Case |
|---|---|---|---|
| Hardware Bridge | Simple, works with any microcontroller | Requires PC running bridge.py | USB-connected Arduino/ESP32 with SPI devices |
| MQTT | Wireless, scalable, cloud-native | Requires Wi-Fi on microcontroller | ESP32/ESP8266 with SPI sensors |
| SSH | Direct GPIO control, powerful | Requires Linux SBC | Raspberry Pi with multiple SPI peripherals |
| execute_python | Universal, no extra hardware | 30-second timeout, cloud-only | Data processing, logging, alerts |
Conclusion
SPI integration with ASI Biont opens a world of possibilities: from industrial temperature monitoring to smart displays and data loggers — all controllable through a chat interface. The AI agent handles the complexity: it writes the Python code, connects to your device via MQTT, SSH, or Hardware Bridge, and executes automation logic based on your natural language instructions. No more hours spent debugging SPI timing or writing boilerplate code. Just describe what you want, and ASI Biont makes it happen.
Ready to connect your SPI device to an AI agent? Try it now at asibiont.com — describe your device in the chat, and let the AI do the integration in seconds.
Comments