So you’ve got an OLED display — maybe the ubiquitous 128×64 SSD1306 or the slightly larger SH1106 — sitting on your desk, waiting for a purpose. You could flash a static sketch, maybe show the time or a temperature. But what if your display could talk to an AI? What if it could show live alerts from your smart home, status updates from a Telegram bot, or sensor data from a remote IoT device — all without you writing a single line of firmware? That’s exactly what the ASI Biont AI agent lets you do.
In this guide, I’ll walk you through how to integrate an OLED (SSD1306, SH1106) with ASI Biont using the most practical method: MQTT. We’ll use an ESP32 (or any microcontroller that speaks MQTT) as the bridge, and the AI agent will handle all the logic, formatting, and command generation. By the end, you’ll have a smart display that updates automatically when the AI detects a condition — like a temperature spike, a finished task, or a new email.
Why Connect an OLED to an AI Agent?
OLEDs are cheap, low-power, and crisp. But their real power is in showing relevant information. Instead of hardcoding what to display, the AI agent can:
- Fetch live data from any source (sensors, APIs, databases)
- Decide what to show based on context (e.g., show weather in the morning, task list at work hours)
- Push notifications without polling
ASI Biont supports dozens of protocols, but for a display that needs to receive updates from an AI, MQTT is the most natural fit: lightweight, pub/sub, and works over Wi-Fi with any ESP32.
Which Connection Method & Why?
For OLED displays, MQTT is the recommended method. Here’s why:
- Real-time push: The AI publishes messages to an MQTT topic; the ESP32 subscribes and updates the display instantly.
- Low overhead: OLEDs and ESP32s handle MQTT easily (minimal RAM/CPU).
- No cloud lock-in: You can run Mosquitto on a Raspberry Pi, or use a free public broker.
- Simple firmware: The ESP32 only needs to subscribe and write to I2C — no AI logic on the device.
Alternative methods that also work (but are more complex for this use case):
- Hardware Bridge (COM port): If your display is connected to a PC via USB (e.g., Arduino Uno with OLED), the AI can send serial commands via bridge.py. But then the PC must always be on.
- SSH: If the OLED is on a Raspberry Pi, the AI can SSH in and run a script to update the display. Works, but adds latency.
- HTTP API: If your ESP32 runs a tiny web server, the AI can POST new content. But MQTT is simpler for continuous updates.
Concrete Use Case: ESP32 + OLED + DHT22 → Telegram Alerts
Here’s the scenario: You have an ESP32 with a DHT22 temperature/humidity sensor and a 128×64 OLED (SSD1306). You want the AI to:
1. Read sensor data every 30 seconds.
2. Display current temp and humidity on the OLED.
3. Send a Telegram alert if temp exceeds 30°C.
4. Also show a scrolling message (e.g., “System OK” or “ALERT: High temp”).
Step 1: Flash the ESP32 Firmware
You need a simple Arduino sketch that:
- Connects to Wi-Fi
- Connects to an MQTT broker (e.g., broker.hivemq.com)
- Subscribes to a topic like display/oled/text
- Publishes sensor data to sensor/esp32/temp
- Updates the OLED when a message arrives
Here’s a minimal example (I’ll assume you have the Adafruit SSD1306 and DHT sensor libraries):
#include <WiFi.h>
#include <PubSubClient.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DHT.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define DHTPIN 4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
const char* ssid = "your-ssid";
const char* password = "your-password";
const char* mqtt_server = "broker.hivemq.com";
WiFiClient espClient;
PubSubClient client(espClient);
void setup() {
Serial.begin(115200);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
dht.begin();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) delay(500);
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
}
void callback(char* topic, byte* payload, unsigned int length) {
String msg = "";
for (int i=0; i<length; i++) msg += (char)payload[i];
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0);
display.println(msg);
display.display();
}
void loop() {
if (!client.connected()) reconnect();
client.loop();
static unsigned long lastRead = 0;
if (millis() - lastRead > 30000) {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (!isnan(h) && !isnan(t)) {
String payload = "{\"temp\":" + String(t) + ",\"hum\":" + String(h) + "}";
client.publish("sensor/esp32/temp", payload.c_str());
}
lastRead = millis();
}
}
void reconnect() {
while (!client.connected()) {
if (client.connect("ESP32OLED")) {
client.subscribe("display/oled/text");
} else delay(5000);
}
}
Upload this to your ESP32. The OLED will show whatever string is published to display/oled/text.
Step 2: Connect ASI Biont via MQTT
Now, in the ASI Biont chat, you simply describe what you want. For example:
"Connect to MQTT broker at broker.hivemq.com:1883. Subscribe to sensor/esp32/temp. Every 30 seconds, check the temperature. If temp > 30, publish '⚠️ HIGH TEMP: 31.2°C — take action!' to display/oled/text and also send a Telegram alert to my chat ID 123456789."
The AI agent will write and execute a Python script using the paho-mqtt library (available in the sandbox). Here’s what the AI generates (you won’t see it unless you ask, but conceptually):
import paho.mqtt.client as mqtt
import time
import json
# Configuration
BROKER = "broker.hivemq.com"
PORT = 1883
TOPIC_SENSOR = "sensor/esp32/temp"
TOPIC_DISPLAY = "display/oled/text"
TELEGRAM_BOT_TOKEN = "your_bot_token"
TELEGRAM_CHAT_ID = "123456789"
def on_message(client, userdata, msg):
data = json.loads(msg.payload.decode())
temp = data['temp']
hum = data['hum']
if temp > 30:
alert = f"⚠️ HIGH TEMP: {temp}°C — take action!"
# Send to OLED
mqtt_client.publish(TOPIC_DISPLAY, alert)
# Send Telegram alert (using requests)
import requests
url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage"
requests.post(url, json={"chat_id": TELEGRAM_CHAT_ID, "text": alert})
else:
normal = f"Temp: {temp}°C, Hum: {hum}% — All good"
mqtt_client.publish(TOPIC_DISPLAY, normal)
mqtt_client = mqtt.Client()
# Note: No username/password for public broker
mqtt_client.on_message = on_message
mqtt_client.connect(BROKER, PORT, 60)
mqtt_client.subscribe(TOPIC_SENSOR)
mqtt_client.loop_forever() # Runs until stopped
The AI will ask you for your Telegram bot token and chat ID (if you want alerts). It then runs the script on the cloud sandbox. The script subscribes to the sensor topic, and every time the ESP32 publishes data, the AI processes it and publishes to the display topic. The OLED updates instantly.
Step 3: Watch It Work
You’ll see the OLED change from “Temp: 24.5°C, Hum: 60% — All good” to a red alert message when the temperature spikes. The AI also sends you a Telegram message. All without you writing the MQTT logic — just a description in chat.
Advanced: Scrolling Text, Icons, and Multi-Page Display
You can extend this further. For example, publish JSON with a type field:
{"type": "scroll", "text": "System OK - CPU load 12%"}
And modify the ESP32 callback to parse JSON and scroll text. The AI can generate both the new firmware snippet and the MQTT commands.
Why This Approach Rocks
- No firmware coding: The ESP32 sketch is the only code you write (and it’s generic — you can reuse it for any MQTT display). All logic lives in the AI.
- Instant changes: Want to show a different metric? Just tell the AI. It publishes a new topic format, and the display updates.
- Works with any OLED: SSD1306 or SH1106 — both use I2C and the same Adafruit library.
- No dashboard: No “add device” buttons. You describe, AI does.
Potential Pitfalls & How to Avoid Them
- MQTT broker reliability: Public brokers (like HiveMQ) can be slow or drop connections. For production, run your own Mosquitto on a Raspberry Pi or use a cloud broker like AWS IoT Core.
- OLED I2C address: SSD1306 usually at 0x3C, SH1106 often at 0x3C or 0x3D. Use an I2C scanner sketch to confirm.
- ESP32 power: If using battery, put ESP32 into deep sleep between readings. But then MQTT won’t work in real time — use a wake-up timer.
- Message size: Keep OLED text short (128×64 pixels, 8-10 lines of 21 characters each). The AI can truncate automatically.
- Telegram bot security: Never hardcode your bot token in the ESP32 firmware. Store it only in the AI chat (the sandbox script retrieves it from environment variables if needed).
Other Integration Ideas for OLED with ASI Biont
- Task status: AI watches your Trello board and pushes “3 tasks due today” to the OLED.
- Crypto price: AI fetches BTC price via CoinGecko API and updates the display every minute.
- Server monitoring: AI SSHes into your VPS, checks disk usage, and shows “Disk 85% full” on the OLED.
- Countdown timer: AI calculates time until a deadline and displays a live countdown.
Conclusion
Integrating an OLED display (SSD1306 or SH1106) with the ASI Biont AI agent is straightforward: you flash a generic MQTT firmware on an ESP32, then describe your desired behavior in the chat. The AI handles all the data processing, formatting, and command routing — whether it’s temperature alerts, task reminders, or real-time sensor dashboards. No code to write for the AI side, no complex dashboards to configure. Just a conversation.
Ready to make your display smart? Head over to asibiont.com, create an account, and start your first integration. Connect your ESP32, tell the AI what to show, and watch the magic happen.
Comments