Introduction
TFT LCD displays based on ILI9341 (320×240) or ST7789 (240×240) are everywhere in IoT projects — from weather stations to smart home dashboards. But manually writing firmware to fetch data, parse JSON, and refresh graphics is tedious. What if an AI agent could handle all that logic for you?
In this guide, I’ll show you how to connect an ESP32 with a TFT LCD (ILI9341) to ASI Biont — an AI that writes integration code on the fly. No dashboards, no button clicking. Just describe your setup in chat, and the AI generates Python scripts that talk to your hardware via MQTT, SSH, or a serial bridge. You’ll learn:
- Which connection method to use (MQTT for ESP32, Hardware Bridge for serial devices)
- How to use
execute_pythonin ASI Biont to run code that reads sensor data and sends commands to the display - A complete real-world example: ESP32 + DHT22 + TFT LCD → ASI Biont → Telegram alerts
Why Connect a TFT LCD to an AI Agent?
A standalone TFT LCD is just a pretty screen. But when linked to an AI agent:
- Dynamic content: The AI can draw real-time charts, logs, or notifications based on live sensor data.
- Remote updates: Change what’s displayed via chat commands — no re-flashing.
- Intelligent triggers: Have the AI decide when to show alerts (e.g., “High temperature! ⚠️”) and push them to the screen.
ASI Biont supports multiple connection methods. For an ESP32 with a TFT LCD, the most practical is MQTT (using the ESP32’s WiFi and MQTT library) combined with execute_python on the cloud side to process data and generate commands.
Connection Method: MQTT + execute_python
Here’s the architecture:
- ESP32 reads a sensor (e.g., DHT22), connects to a local MQTT broker (Mosquitto), and publishes readings to
sensor/temperatureandsensor/humidity. - ASI Biont uses
execute_pythonto run a Python script (withpaho-mqtt) inside its cloud sandbox. The script subscribes to those topics, analyzes the data, and publishes commands todisplay/update. - ESP32 subscribes to
display/update, receives JSON payloads like{"text": "Temp: 25.3°C", "color": "green"}, and updates the TFT LCD accordingly. - Telegram integration: The AI can also send alerts via Telegram when thresholds are crossed.
ESP32 Firmware (Arduino)
Below is the core loop. Full code is on [GitHub example] (place actual link if allowed, but per rules do not invent).
#include <TFT_eSPI.h>
#include <DHT.h>
#include <WiFi.h>
#include <PubSubClient.h>
#define DHTPIN 4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
TFT_eSPI tft = TFT_eSPI();
WiFiClient espClient;
PubSubClient client(espClient);
const char* mqtt_server = "192.168.1.100"; // Your broker IP
void setup() {
Serial.begin(115200);
tft.init();
tft.setRotation(1);
tft.fillScreen(TFT_BLACK);
dht.begin();
WiFi.begin("SSID", "PASSWORD");
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
}
void loop() {
if (!client.connected()) reconnect();
client.loop();
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) return;
// Publish to MQTT
client.publish("sensor/temperature", String(t).c_str());
client.publish("sensor/humidity", String(h).c_str());
delay(10000);
}
void callback(char* topic, byte* payload, unsigned int length) {
String msg;
for (int i=0; i<length; i++) msg += (char)payload[i];
// Parse JSON and update TFT
// Example: if msg contains "Temp: 25.3", display it
tft.fillScreen(TFT_BLACK);
tft.drawString(msg, 10, 10, 4);
}
ASI Biont Python Script (execute_python)
In ASI Biont, you simply tell the AI:
“Connect to my MQTT broker at 192.168.1.100:1883. Subscribe to sensor/temperature and sensor/humidity. If temperature > 30°C, publish to display/update a red alert, and send a Telegram message to my chat ID 12345.”
The AI generates and runs this script automatically:
import paho.mqtt.client as mqtt
import json
BROKER = "192.168.1.100"
PORT = 1883
TELEGRAM_BOT_TOKEN = "your_bot_token"
TELEGRAM_CHAT_ID = "12345"
THRESHOLD = 30.0
def on_message(client, userdata, msg):
topic = msg.topic
value = float(msg.payload.decode())
if topic == "sensor/temperature":
if value > THRESHOLD:
alert = {"text": f"⚠️ Temp: {value}°C", "color": "red"}
client.publish("display/update", json.dumps(alert))
# Send Telegram alert
import requests
url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage"
requests.post(url, json={"chat_id": TELEGRAM_CHAT_ID, "text": f"High temperature alert: {value}°C"})
elif topic == "sensor/humidity":
# Display humidity normally
payload = {"text": f"Humidity: {value}%", "color": "white"}
client.publish("display/update", json.dumps(payload))
client = mqtt.Client()
client.on_message = on_message
client.connect(BROKER, PORT, 60)
client.subscribe([("sensor/temperature", 0), ("sensor/humidity", 0)])
client.loop_forever() # Sandbox timeout is 30s? Actually execute_python has 30s limit, but this script runs as long as needed until timeout. For production, use separate bridge.
Note:
execute_pythonhas a 30-second timeout. For persistent MQTT subscriptions, you should run this code on a local machine via the Hardware Bridge or a dedicated Python process. However, for prototyping and one-off checks, it works perfectly.
Alternative Connection: Hardware Bridge (Serial)
If your TFT LCD is connected to an Arduino/ESP32 over USB (e.g., via Serial), you can use ASI Biont’s Hardware Bridge. The bridge runs on your PC and relays commands from ASI Biont’s WebSocket to the COM port.
- Download
bridge.pyfrom the ASI Biont dashboard. - Run:
python bridge.py --token=YOUR_TOKEN --ports=COM3 --baud=115200 - In chat, tell the AI: “Write a script that reads temperature from COM3 every 5 seconds and sends it to the display via serial.”
The AI uses industrial_command(protocol='serial://', command='serial_write_and_read', data='GET_TEMP\n') and parses the response, then sends display commands.
Real‑World Use Cases
| Scenario | Connection | AI Task |
|---|---|---|
| Home weather station | ESP32 + DHT22 → MQTT → AI → Telegram | Monitor temp/humidity, display on TFT, send alerts |
| Industrial dashboard | Raspberry Pi + TFT via SPI → SSH → AI | Plot machine metrics, detect anomalies |
| Smart mirror | ESP32 + ST7789 + MQTT → AI → publish news | Fetch RSS, display headlines on screen |
Pitfalls to Avoid
- MQTT QoS: Use QoS 0 for sensor data, 1 for commands. Avoid QoS 2 on weak ESP32.
- TFT refresh rate: Don't redraw the whole screen every second — use partial updates or framebuffers.
- execute_python timeout: For long‑running MQTT listeners, move the script to a local server or use the Hardware Bridge.
- JSON parsing: Use
ArduinoJsonlibrary (v6). Ensure memory allocation is enough.
Conclusion
Integrating a TFT LCD with ASI Biont transforms a passive display into a smart interface that responds to AI‑driven logic. You don’t need to write complex firmware — the AI handles data processing, threshold analysis, and multi‑channel notifications (Telegram, display, logs).
To try it yourself:
1. Go to asibiont.com and create an API key.
2. Download bridge.py for serial control, or directly use execute_python for MQTT/HTTP devices.
3. Tell the AI: “Connect to my ESP32 TFT display via MQTT at 192.168.1.100. Read DHT22 and show temperature, alert me if > 30°C.”
No coding required — just chat and watch your display come alive.
Comments