SPI Meets AI: How to Connect SPI Devices (Sensors, Displays, ADCs) to ASI Biont for Voice-Controlled Automation

Introduction

If you‘ve ever wired up an SPI device — a temperature sensor, an OLED display, or an ADC — you know the drill: write a sketch, flash it, stare at serial output, and maybe wire a button to change modes. But what if you could talk to that SPI device through a chat interface, ask it questions, and have it react to your voice commands? That’s exactly what ASI Biont’s AI agent does. In this guide, I’ll show you how to connect SPI devices (like the MAX31855 thermocouple amp or an ILI9341 TFT display) to ASI Biont using an ESP32 or Raspberry Pi, so you can monitor temperature, display AI-generated messages, or trigger actions — all via chat or Telegram.

Why Connect SPI Devices to an AI Agent?

SPI is fast and deterministic — perfect for real-time sensor reads and display updates. But traditionally, you need to write custom firmware for every new scenario. With ASI Biont, you describe what you want in plain English (e.g., “Read the SPI temperature sensor every 5 minutes and alert me if it goes above 80°C”), and the AI writes the integration code on the fly. No dashboard, no “add device” button — just a conversation.

How ASI Biont Connects to SPI Devices

ASI Biont doesn’t have a dedicated “SPI plugin.” Instead, it uses execute_python — a sandboxed Python environment that can run any script using real libraries. The AI generates a Python script that uses one of these connection methods to reach your SPI device:

Connection Method When to Use Libraries Used
MQTT (paho-mqtt) ESP32 publishes SPI data via MQTT to a broker paho-mqtt
SSH (paramiko) Raspberry Pi runs SPI Python scripts and AI controls it remotely paramiko, spidev
Hardware Bridge (bridge.py) ESP32/Arduino connected via COM port, AI reads/writes serial pyserial (on bridge) + industrial_command
HTTP API (aiohttp) ESP32 serves SPI data via a simple HTTP endpoint aiohttp

Important: The AI script runs in the cloud (Railway), so it cannot directly access your SPI bus. You must use one of the above methods as a bridge.

Concrete Use Case: ESP32 + MAX31855 (Thermocouple) → ASI Biont → Telegram Alerts

Step 1: Hardware Setup

  • ESP32 Dev Board (e.g., ESP32-WROOM-32)
  • MAX31855 thermocouple amplifier connected via SPI:
  • VCC → 3.3V
  • GND → GND
  • SCK → GPIO 18
  • CS → GPIO 5
  • SO (MISO) → GPIO 19
  • Breadboard and wires

Step 2: ESP32 Firmware (Publishes SPI Data via MQTT)

I used the Adafruit MAX31855 library and PubSubClient for MQTT. The ESP32 reads temperature every 10 seconds and publishes it to a topic like spi/temperature.

#include <WiFi.h>
#include <PubSubClient.h>
#include <Adafruit_MAX31855.h>

// WiFi & MQTT
const char* ssid = "YourSSID";
const char* password = "YourPassword";
const char* mqtt_server = "test.mosquitto.org";

WiFiClient espClient;
PubSubClient client(espClient);

// SPI Pins
#define MAXDO   19
#define MAXCS   5
#define MAXCLK  18
Adafruit_MAX31855 thermocouple(MAXCLK, MAXCS, MAXDO);

void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) delay(500);
  client.setServer(mqtt_server, 1883);
  if (!thermocouple.begin()) Serial.println("MAX31855 error");
}

void loop() {
  if (!client.connected()) client.connect("ESP32_SPI");
  client.loop();
  double temp = thermocouple.readCelsius();
  if (!isnan(temp)) {
    char msg[10];
    dtostrf(temp, 1, 2, msg);
    client.publish("spi/temperature", msg);
  }
  delay(10000);
}

Step 3: AI Integration in ASI Biont

Now, in ASI Biont chat, I tell the AI: “Connect to MQTT broker test.mosquitto.org, subscribe to spi/temperature, and if the value exceeds 80°C, send me a Telegram alert.”

ASI Biont’s AI uses execute_python to generate and run this script:

import paho.mqtt.client as mqtt
import time

BROKER = "test.mosquitto.org"
TOPIC = "spi/temperature"
THRESHOLD = 80.0

def on_message(client, userdata, msg):
    try:
        temp = float(msg.payload.decode())
        if temp > THRESHOLD:
            # AI sends Telegram message via ASI Biont’s Telegram tool
            print(f"ALERT: Temperature {temp}°C exceeds {THRESHOLD}°C")
            # In real scenario, AI would call send_telegram_message()
    except ValueError:
        pass

mqtt_client = mqtt.Client()
mqtt_client.on_message = on_message
mqtt_client.connect(BROKER, 1883, 60)
mqtt_client.subscribe(TOPIC)
mqtt_client.loop_start()
time.sleep(30)  # Sandbox timeout is 30 seconds
mqtt_client.loop_stop()

The AI runs this script in the sandbox (30-second limit). If an alert triggers, the AI sees the output and can send a Telegram message via its built-in tools.

Step 4: Voice Control via Chat

You can also ask the AI: “What’s the current SPI temperature?” The AI will fire up a new MQTT subscriber, wait for the next published value, and reply with the data. No manual coding — just conversation.

Alternative: Raspberry Pi + SPI Display (ILI9341) via SSH

If you have a Raspberry Pi with an SPI TFT display (e.g., ILI9341), you can ask ASI Biont to display text on it:

  • AI connects via paramiko over SSH
  • Runs a Python script that uses spidev and RPi.GPIO to send text to the display
  • You say: “Show ‘Hello from AI’ on the SPI screen”
  • AI writes the script, sends it via SCP, and executes it

Example AI-generated script (runs on Pi via SSH):

import spidev
import RPi.GPIO as GPIO

def display_text(text):
    # Initialize SPI
    spi = spidev.SpiDev()
    spi.open(0, 0)
    spi.max_speed_hz = 32000000
    # Send commands to ILI9341 (simplified)
    # ... display initialization and text rendering ...
    print(f"Displayed: {text}")

display_text("Hello from AI")

Why This Matters: No-Code Automation for Any SPI Device

The real power is that you don’t need to write integration code yourself. ASI Biont’s AI writes it for you, tailored to your exact device and scenario. Whether you’re using an ESP32, Raspberry Pi, or an Arduino via Hardware Bridge, the process is the same: describe your device and what you want, and the AI handles the rest.

Pitfalls to Avoid

  1. Don’t run infinite loops in execute_python — sandbox timeout is 30 seconds. Use MQTT subscriptions or short-lived polls.
  2. Don’t try to access SPI directly from the cloud — it won’t work. Always use a bridge (MQTT, SSH, Hardware Bridge).
  3. Secure your MQTT broker — if you use a public broker like test.mosquitto.org, anyone can see your data. Use a local broker (Mosquitto) or one with authentication.
  4. Check SPI voltage levels — ESP32 is 3.3V, but some SPI devices (like older displays) may need 5V. Use level shifters.

Conclusion

SPI devices are fast and reliable, but connecting them to an AI agent opens up a world of possibilities: voice-controlled displays, automated sensor alerts, and real-time data analysis — all without writing a single line of integration code. ASI Biont’s AI does the heavy lifting, generating Python scripts that bridge SPI hardware to cloud intelligence.

Ready to make your SPI device talk to AI? Head over to asibiont.com and start a chat. Describe your SPI setup, and let the AI agent handle the rest. No dashboard, no plugins — just pure conversation-driven automation.

← All posts

Comments