What you will build
A desk companion whose face is a 64 × 32 RGB LED matrix. Built in three milestones, each working on its own:
- Animated face: eyes that blink and look around, with six expressions: Idle, Listening, Thinking, Speaking, Happy, Error.
- Chat: a Python app on your computer sends your typed messages to an AI service, shows Thinking while waiting, then scrolls the reply across the matrix while the face speaks.
- Voice (optional): push-to-talk microphone on the computer, spoken replies through its speakers.
How it works
The panel is a HUB75 matrix: rows of RGB LEDs that the ESP32-S3 refreshes hundreds of times a second using DMA (hardware that moves pixel data without the CPU). The firmware has a small state controller: it receives one-line JSON commands over USB serial and picks an animation. All AI work happens on the computer, never on the ESP32, and the API key stays there.
{"state":"thinking"}
{"state":"speaking","text":"Hello! Nice to meet you."}
{"brightness":40}
| Layer | Runs on | Job |
|---|---|---|
| Matrix firmware + animations | ESP32-S3 | Draw face, accept state commands |
| Companion backend (Python) | Your computer | Chat, AI requests, optional speech |
| Face editor / preview | Browser | Design expressions without hardware |
Parts
| Part | Qty | Purpose | Required |
|---|---|---|---|
| ESP32-S3-DevKitC-1 (N8R8 or N16R8) | 1 | Matrix driver | Yes |
| 64 × 32 RGB LED matrix, HUB75, P3 or P4, 1/16 scan | 1 | The face | Yes |
| HUB75 ribbon cable + panel power lead (usually included) | 1 | Connections | Yes |
| 5 V 4 A regulated power supply + DC barrel adapter | 1 | Panel power | Yes |
| 16 female-to-male jumpers (or a HUB75 adapter board) | 1 set | Data wiring | Yes |
| Smoked acrylic diffuser + stand | 1 | Looks | Optional |
| Push button | 1 | Mute / mode | Optional |
Panels vary. Before buying, confirm: resolution, HUB75 interface, scan rate (1/16 for 64 × 32), and driver chip. Record the exact model on the page.
Build steps
Identify the panel: read the label on the back (e.g.
P3-64x32-16S). Note the driver chip if printed.Data wiring (HUB75 input connector → ESP32-S3):
HUB75 R1 G1 B1 R2 G2 B2 A B C D CLK LAT OE GND GPIO 4 5 6 7 15 16 18 8 9 10 11 12 13 GND These pins avoid the S3's strapping, USB and PSRAM pins. Verify them against your exact board before powering.
Power: panel power lead → 5 V 4 A supply. Never power the panel from the ESP32's 5V pin. Join the supply GND to ESP32 GND.
Install ESP32 HUB75 LED MATRIX PANEL DMA Display (mrcodetastic) and ArduinoJson. Board: ESP32S3 Dev Module, PSRAM enabled.
Upload the firmware. Checkpoint: the boot test shows red, green, blue bars, then the Idle face. If colours or halves are wrong, see Troubleshooting before going on.
Open the Serial Monitor (115200, newline) and type
{"state":"happy"}. The face changes.Milestone 2: on your computer install Python 3.10+, then
pip install pyserial openai. SetOPENAI_API_KEYandOPENAI_MODELin your environment. Runcompanion.py, type a message, watch Thinking → Speaking.Milestone 3 (optional): add speech-to-text and text-to-speech in
companion.pywith a push-to-talk key. Show Listening only while recording.
Try it in the browser
Interactive Preview — Face Editor. A 64 × 32 virtual matrix shows each expression and transition. Users can change eye shape, colour and blink speed, preview a scrolling message, and export the expression as code for the firmware. You can send supported face states to your ESP32-S3 with a compatible Web Serial browser. No AI is called from the browser.
Code
ESP32-S3 matrix firmware.
Download ai-pixel-companion.ino
// AI Pixel Companion — firmware — XBOTNOW
// Board: ESP32-S3-DevKitC-1 · Core: esp32 v3.x
// Libraries: ESP32 HUB75 LED MATRIX PANEL DMA Display, Adafruit GFX, ArduinoJson 7
#include <ESP32-HUB75-MatrixPanel-I2S-DMA.h>
#include <ArduinoJson.h>
const int W = 64, H = 32;
MatrixPanel_I2S_DMA* panel;
enum State { IDLE, LISTENING, THINKING, SPEAKING, HAPPY, ERROR_ };
State state = IDLE;
String message = "";
int scrollX = W;
unsigned long nextBlink = 3000, stateSince = 0;
uint16_t col(uint8_t r, uint8_t g, uint8_t b) { return panel->color565(r, g, b); }
void drawEyes(int lookX, int openPct, uint16_t c) {
int h = max(2, 12 * openPct / 100);
for (int cx : {20, 44}) panel->fillRoundRect(cx - 6 + lookX, 12 - h / 2, 12, h, 3, c);
}
void drawFace() {
panel->clearScreen();
unsigned long t = millis();
bool blinking = t > nextBlink && t < nextBlink + 120;
if (t > nextBlink + 120) nextBlink = t + random(2500, 6000);
int open = blinking ? 10 : 100;
switch (state) {
case IDLE: drawEyes((t / 2000) % 3 - 1, open, col(0, 180, 255)); break;
case LISTENING: drawEyes(0, open, col(0, 255, 120));
panel->drawCircle(32, 26, 2 + (t / 150) % 3, col(0, 255, 120)); break;
case THINKING: drawEyes(3, 60, col(150, 90, 255));
for (int i = 0; i < 3; i++) if ((t / 300) % 4 > i) panel->fillCircle(26 + i * 6, 27, 1, col(150, 90, 255)); break;
case SPEAKING: drawEyes(0, open, col(0, 180, 255));
panel->fillRoundRect(26, 24, 12, 2 + (t / 90) % 4, 1, col(255, 255, 255)); break;
case HAPPY: for (int cx : {20, 44}) panel->drawCircleHelper(cx, 14, 6, 1 | 2, col(255, 200, 0)); break;
case ERROR_: for (int cx : {20, 44}) { panel->drawLine(cx - 4, 8, cx + 4, 16, col(255, 40, 40));
panel->drawLine(cx + 4, 8, cx - 4, 16, col(255, 40, 40)); } break;
}
if (state == SPEAKING && message.length()) { // scroll reply along the bottom
panel->setTextColor(col(255, 255, 255));
panel->setCursor(scrollX, 24); panel->print(message);
if (--scrollX < -(int)message.length() * 6) { scrollX = W; state = IDLE; message = ""; }
}
}
void handleLine(const String& line) {
JsonDocument doc;
if (deserializeJson(doc, line)) return; // ignore invalid JSON
if (doc["brightness"].is<int>()) panel->setBrightness8(constrain((int)doc["brightness"], 5, 120));
const char* s = doc["state"] | "";
if (!strcmp(s, "idle")) state = IDLE;
else if (!strcmp(s, "listening")) state = LISTENING;
else if (!strcmp(s, "thinking")) state = THINKING;
else if (!strcmp(s, "speaking")) state = SPEAKING;
else if (!strcmp(s, "happy")) state = HAPPY;
else if (!strcmp(s, "error")) state = ERROR_;
if (doc["text"].is<const char*>()) { message = String((const char*)doc["text"]).substring(0, 120); scrollX = W; state = SPEAKING; }
stateSince = millis();
}
void setup() {
Serial.begin(115200);
HUB75_I2S_CFG::i2s_pins pins = {4, 5, 6, 7, 15, 16, 18, 8, 9, 10, -1 /*E*/, 12, 13, 11};
HUB75_I2S_CFG cfg(W, H, 1, pins);
panel = new MatrixPanel_I2S_DMA(cfg);
panel->begin();
panel->setBrightness8(40); // start low
uint16_t bars[] = {col(255, 0, 0), col(0, 255, 0), col(0, 0, 255)};
for (int i = 0; i < 3; i++) { panel->fillScreen(bars[i]); delay(400); } // colour test
}
void loop() {
static String buf;
while (Serial.available()) {
char c = Serial.read();
if (c == '\n') { handleLine(buf); buf = ""; } else if (buf.length() < 300) buf += c;
}
if (state != IDLE && state != SPEAKING && millis() - stateSince > 30000) state = IDLE; // timeout
drawFace();
delay(30);
}
Companion backend (milestone 2, text chat).
# companion.py — XBOTNOW. Runs on your computer, never in the browser.
# pip install pyserial openai
# Set OPENAI_API_KEY and OPENAI_MODEL in your environment before running.
import json
import os
import sys
import serial
from openai import OpenAI
model = os.environ.get("OPENAI_MODEL")
if not model or not os.environ.get("OPENAI_API_KEY"):
sys.exit("Set OPENAI_MODEL and OPENAI_API_KEY before running.")
client = OpenAI(timeout=20.0)
PORT = sys.argv[1] if len(sys.argv) > 1 else "/dev/ttyACM0" # e.g. COM5 on Windows
esp = serial.Serial(PORT, 115200, timeout=1)
def face(**msg):
esp.write((json.dumps(msg) + "\n").encode())
SYSTEM = ("You are Pixel, a cheerful desk companion. "
"Reply in at most 2 short sentences, plain text, no emoji.")
def ask_ai(history):
"""Send typed chat messages from the computer to the OpenAI API."""
response = client.responses.create(
model=model,
input=history,
max_output_tokens=240,
store=False,
)
return response.output_text.strip() or "I don't have a reply yet."
history = []
face(state="idle")
print("Type a message (Ctrl+C to quit).")
while True:
text = input("> ").strip()
if not text:
continue
history.append({"role": "user", "content": text})
face(state="thinking")
try:
reply = ask_ai([{"role": "system", "content": SYSTEM}] + history[-10:])
history.append({"role": "assistant", "content": reply})
print("Pixel:", reply)
face(state="speaking", text=reply[:120])
except Exception as e:
print("AI request failed:", type(e).__name__)
face(state="error")
This Python example uses the OpenAI Responses API. Set OPENAI_API_KEY and OPENAI_MODEL on your computer. Only the text you type into the Python app is sent to the API.
Troubleshooting
| Symptom | Likely cause | Check |
|---|---|---|
| Only top or bottom half lights | Scan rate / E pin | 64 × 32 1/16 needs no E; 1/32 panels need E wired |
| Colours swapped (red shows blue) | Panel RGB order | Swap R/B pin numbers in pins |
| Flicker, random pixels | Long or loose jumpers | Keep data wires < 20 cm; use an adapter board |
| ESP32 resets at high brightness | Supply too weak / shared ground missing | 5 V 4 A supply, GNDs joined, brightness ≤ 120 |
| Backend says port busy | Serial Monitor open | Close it before running companion.py |
Safety and limitations
RGB matrices can draw several amps at full white. Use a regulated 5 V supply of at least 4 A, proper power leads and secure connectors; start at low brightness and check that connectors stay cool. Never power the panel from the ESP32. If you add a microphone, show Listening only while recording, provide a mute control, and tell users that audio and text are sent to an external AI service. Keep API keys in environment variables on the computer. This is an experimental companion, not a safety, medical or emergency device.
Checklist
Next project
Real-Time Brainwave Visualizer: from AI signals to signals from the brain.
