Introduction
The Serial Peripheral Interface (SPI) is the workhorse of embedded systems. From high-speed temperature sensors (MAX31855) and 128×64 OLED displays to ADCs and SD card modules, SPI moves data at up to 80 MHz over four wires. Yet for all its speed, SPI has a dirty secret: it's a local bus. Your Raspberry Pi or ESP32 can talk to an SPI barometer just fine, but getting that data into a cloud AI agent usually requires a tangled mess of MQTT brokers, HTTP endpoints, or custom serial protocols.
Enter ASI Biont. This AI agent doesn't need a custom firmware flash or a dedicated cloud dashboard. Instead, it connects to your SPI-equipped microcontroller through a Hardware Bridge — a lightweight Python script that runs on your PC (Windows, Linux, or macOS) and communicates with ASI Biont via a single WebSocket tunnel. You describe your SPI device in the chat, the AI writes the integration code on the fly, and within seconds you're reading sensor data or controlling actuators from the cloud.
This article is not a review of SPI — it's a practical integration guide. We'll cover:
- Why SPI needs a bridge and how ASI Biont's architecture solves the distance problem.
- A real-world use case (reading a MAX6675 thermocouple from an ESP32 via SPI, then forwarding the data through a COM port).
- Step-by-step code for both the microcontroller (MicroPython) and the AI agent (Python + bridge).
- Comparison with other serial interfaces (I²C, UART, 1-Wire) so you know when SPI is the right tool.
By the end, you'll be able to connect any SPI device to ASI Biont in under 10 minutes — no cloud dashboard configuration, no waiting for developer support.
The Problem: SPI is Fast but Local
SPI operates as a master-slave bus. A typical connection uses four lines:
| Signal | Function |
|---|---|
| SCLK | Serial Clock (generated by master) |
| MOSI | Master Out, Slave In |
| MISO | Master In, Slave Out |
| CS | Chip Select (one per slave) |
Data transfer is synchronous and full-duplex. Speeds range from 1 MHz to 80 MHz, making SPI 10-100× faster than I²C (standard 100/400 kHz). However, SPI has two major limitations:
- Short distance — SPI is designed for on-PCB or short cable runs (< 1 meter). Beyond that, signal integrity degrades.
- No built-in addressing — each slave needs a dedicated CS line, eating up GPIO pins.
To get SPI data into an AI agent, you typically need a gateway device (ESP32, Raspberry Pi) that reads the SPI bus and then forwards the data via Wi-Fi/Ethernet using MQTT, HTTP, or serial-over-IP. That's what ASI Biont's Hardware Bridge does — but without the middleware complexity.
How ASI Biont Connects to SPI Devices
ASI Biont does not natively speak SPI. Instead, it uses a two-hop architecture:
- Microcontroller (e.g., ESP32) ↔ PC via USB/COM port — The ESP32 reads an SPI sensor (e.g., MAX6675 thermocouple) and sends formatted data over its UART-to-USB serial port.
- PC ↔ ASI Biont cloud via WebSocket — The user runs
bridge.pyon their PC. This script opens a WebSocket connection to the ASI Biont server, and also opens a local COM port (e.g.,COM3at 115200 baud). When the AI agent sends aserial_write_and_readcommand, the bridge writes a hex-encoded request to the COM port and returns the response.
Why not connect the ESP32 directly to the cloud? You could — the ESP32 has Wi-Fi. But many industrial scenarios use isolated USB-to-serial connections for security or legacy reasons. The bridge approach works with any microcontroller that exposes a COM port.
Supported Communication Methods (from ASI Biont's real API)
| Interface | Tool/Protocol | Use Case |
|---|---|---|
| COM port (RS-232/RS-485) | industrial_command → serial_write_and_read |
Direct serial connection to microcontrollers |
| SSH | execute_python (paramiko) |
Raspberry Pi / Linux boards with GPIO |
| MQTT | execute_python (paho-mqtt) |
Smart home / IoT sensors |
| Modbus/TCP | industrial_command → read_registers |
Industrial PLCs |
| BACnet | industrial_command → read_property |
Building automation |
| EtherNet/IP | industrial_command → read_tag |
Allen-Bradley controllers |
| CAN bus | industrial_command → send_frame |
Vehicles, robots |
| HTTP API | execute_python (aiohttp) |
Cameras, smart plugs |
| OPC UA | industrial_command → read_variable |
Factory sensors |
For SPI devices, the COM port (Hardware Bridge) is the most straightforward path.
Real-World Use Case: Industrial Furnace Temperature Monitoring
Scenario: A small foundry uses a MAX6675 thermocouple amplifier (SPI interface) to monitor furnace temperatures. The MAX6675 connects to an ESP32 running MicroPython. The ESP32 reads temperature every 5 seconds and sends it over USB serial to a Windows PC. The PC runs bridge.py, connected to ASI Biont. The AI agent logs temperatures, alerts if the furnace exceeds 1200°C, and generates a daily report.
Step 1: Microcontroller Firmware (ESP32 + MAX6675)
The MAX6675 communicates over SPI. MicroPython's machine.SPI class handles the protocol.
# ESP32 MicroPython code — reads MAX6675 over SPI, sends via UART
from machine import Pin, SPI, UART
import time
# SPI setup (ESP32: sck=18, miso=19, mosi=23, cs=5)
spi = SPI(1, baudrate=1000000, polarity=0, phase=0)
cs = Pin(5, Pin.OUT)
# UART setup (USB serial)
uart = UART(0, baudrate=115200)
def read_max6675():
cs.value(0)
data = spi.read(2, 0xFF) # read 2 bytes
cs.value(1)
# MAX6675 returns 12-bit temperature in 0.25°C increments
temp_raw = (data[0] << 8) | data[1]
if temp_raw & 0x04: # open thermocouple check
return None
temp_c = (temp_raw >> 3) * 0.25
return temp_c
while True:
temp = read_max6675()
if temp is not None:
# Send as simple ASCII: "TEMP=123.50"
uart.write(f"TEMP={temp:.2f}\n")
else:
uart.write("ERROR=OPEN\n")
time.sleep(5)
Step 2: PC Bridge Setup
On the Windows PC, the user downloads bridge.py from the ASI Biont dashboard (Devices → Create API Key → Download bridge). They run it:
pip install pyserial requests websockets
python bridge.py --token=YOUR_API_KEY --ports=COM3 --baud 115200
The bridge connects to ASI Biont's cloud via WebSocket and opens COM3 at 115200 baud.
Step 3: AI Agent Integration (via Chat)
The user describes the task in the ASI Biont chat:
"Connect to my ESP32 via COM3 at 115200 baud. It sends temperature readings like 'TEMP=123.50' every 5 seconds. Read the data, log it, and send me a Telegram alert if the temperature exceeds 1200°C. Also generate a daily CSV report."
ASI Biont's AI agent then writes and executes the following Python code using the execute_python sandbox:
import asyncio
import csv
from datetime import datetime
# The AI uses industrial_command to send serial_write_and_read
# This is a simplified illustration — the actual call goes through the tool
async def monitor_temperature():
alerts = []
log = []
for _ in range(720): # 1 hour at 5-second intervals
# Send a dummy request to trigger a read (ESP32 sends continuously)
response = await industrial_command(
protocol='serial://',
command='serial_write_and_read',
data='524541440a' # "READ" in hex
)
# Parse response: e.g., "TEMP=123.50"
if response.startswith("TEMP="):
temp = float(response.split("=")[1])
log.append((datetime.now(), temp))
if temp > 1200:
alerts.append(f"ALERT: Furnace at {temp}°C")
await send_telegram(f"🔥 Furnace temperature critical: {temp}°C")
await asyncio.sleep(5)
# Generate daily report
with open("temperature_log.csv", "w", newline="") as f:
writer = csv.writer(f)
writer.writerow(["Timestamp", "Temperature_C"])
writer.writerows(log)
return {"alerts": alerts, "log_entries": len(log)}
# The AI runs this code in the sandbox and returns results to the user
Result: The user receives a Telegram alert within seconds of a dangerous temperature spike, plus a CSV file at the end of the day.
Why This Matters: No Manual Integration Coding
Traditional approach:
1. Write a Python script to poll the COM port.
2. Set up a local database or cloud logging service.
3. Configure Telegram bot API.
4. Write CSV generation logic.
5. Deploy as a cron job or systemd service.
With ASI Biont: The user just describes the requirements in natural language. The AI agent writes the entire integration, handles error cases, and runs it — all within the chat. The user doesn't need to touch Python, pyserial, or Telegram APIs.
Comparison: SPI vs. Other Serial Interfaces
It's important to know when to use SPI vs. I²C, UART, or 1-Wire. Here's a quick comparison:
| Parameter | SPI | I²C | UART (RS-232) | 1-Wire |
|---|---|---|---|---|
| Speed | 1-80 MHz | 100 kHz-3.4 MHz | Up to 1 Mbps (typical 115200) | 16 kbps |
| Lines | 4 (SCLK, MOSI, MISO, CS) | 2 (SCL, SDA) | 2 (TX, RX) | 1 (data + power) |
| Max distance | < 1 m | < 1 m | 15 m (RS-232) / 1200 m (RS-485) | 100 m |
| Addressing | Per-slave CS | 7/10-bit address | Point-to-point | 64-bit ROM ID |
| Complexity | Medium (CS management) | Low | Very low | Medium |
| Best for | High-speed sensors (ADC, display, thermocouple) | Low-speed multi-sensor (temp, humidity) | Long-distance, simple protocol | Temperature, iButton |
| ASI Biont integration | Via COM bridge + µC | Same as SPI | Direct COM bridge | Same as SPI |
Bottom line: Use SPI when you need speed and have a short bus. For long-distance or multi-drop, prefer RS-485 (Modbus RTU) or 1-Wire.
Additional Scenarios
1. SPI OLED Display (SSD1306) — Remote Dashboard
Connect a 128×64 OLED to an ESP32 via SPI. The AI agent can send text or simple graphics commands through the bridge. For example, display the current Bitcoin price or server uptime on a physical screen in your office.
MicroPython snippet:
# SSD1306 SPI initialization
from machine import Pin, SPI
import ssd1306
spi = SPI(1, baudrate=8000000, polarity=0, phase=0)
dc = Pin(4, Pin.OUT)
rst = Pin(16, Pin.OUT)
cs = Pin(5, Pin.OUT)
oled = ssd1306.SSD1306_SPI(128, 64, spi, dc, rst, cs)
def show_text(text):
oled.fill(0)
oled.text(text, 0, 0)
oled.show()
2. SPI ADC (MCP3008) — Analog Sensor Monitoring
The MCP3008 is an 8-channel 10-bit ADC using SPI. Connect potentiometers, light sensors, or pressure transducers. The AI agent can read analog values and trigger events.
MicroPython:
# Read channel 0 from MCP3008
import machine
cs = machine.Pin(5, machine.Pin.OUT)
spi = machine.SPI(1, baudrate=1350000, polarity=0, phase=0)
def read_adc(channel):
cmd = 0x18 | channel # start bit + single-ended + channel
cs.value(0)
spi.write(bytes([cmd, 0x00]))
data = spi.read(2)
cs.value(1)
return ((data[0] & 0x03) << 8) | data[1]
Conclusion
SPI is fast, deterministic, and widely supported — but it's a local bus. ASI Biont bridges that gap by letting you funnel SPI data through a COM port into its AI agent, without writing a single line of server-side code. The AI handles parsing, logging, alerting, and reporting based on your natural language instructions.
Ready to connect your SPI device?
Go to asibiont.com, create an account, and download the Hardware Bridge from the Devices page. Plug in your microcontroller, start the bridge, and tell the AI: "Read temperature from COM3 every 5 seconds and alert me if it exceeds 1000°C." The integration happens in seconds — no cloud dashboards, no firmware updates, no waiting.
Your SPI sensors are about to get a lot smarter.
Comments