M5STICKC PLUS2 · ESP32 · MISTRAL-7B
Personal AI Project — 2024

POCKET
AI

A pocket-sized personal AI assistant.
Voice in → LLM → answer on screen.

M5StickC Plus2
Mistral-7B Finetuned
FastAPI
PlatformIO / C++
01 / 07
Inspiration
Where it came from
01 / MARVEL

J.A.R.V.I.S

Iron Man's AI. The gold standard of personal assistants — sarcastic, instant, always on.

02 / DC

Mother Box

DC's sentient supercomputer. A pocketable device with cosmic intelligence.

02 / 07
Architecture
The Loop
01

Record

Hold button
16kHz PCM
PSRAM buffer

02

STT

POST /stt
Bearer JWT
→ text

03

LLM

POST /chat
Mistral-7B
inference

04

Render

TFT display
word-wrap
dialog saved

05

Repeat

Ring buffer
10 dialogs
oldest shifts

SAMPLE RATE 16 kHz MAX BUFFER 500 KB AUTH Bearer JWT TRANSPORT HTTP / Wi-Fi
03 / 07
Stack
System Design
Hardware
M5StickC Plus2ESP32
Built-in micINPUT
1.14" TFTOUTPUT
500 KB PSRAMBUFFER
Wi-Fi 802.11NETWORK
Firmware
PlatformIOBUILD
C++ / ArduinoLANG
M5UnifiedSDK
ArduinoJsonJSON
WiFiManagerNET
Backend
FastAPISERVER
Mistral-7BLLM
HuggingFaceBASE
Google ColabTRAIN
PostgreSQLDB
Infra
Self-hostedCLOUD
Cloudflare ZTTUNNEL
Bearer JWTAUTH
ExpressJSWEB
Electron + ReactDESKTOP
04 / 07
Implementation
Key Code
config.cpp
// Audio buffer (PSRAM)
int16_t* record_buffer = nullptr;
size_t record_size = 0;
const size_t MAX_REC = 1024 * 500;
const int SAMPLE_RATE = 16000;

// JWT + endpoint
const char* API_KEY = "JWT_API_KEY";
const char* API_END_POINT
  = "http://localhost:8000";

// Dialog ring buffer
struct Dialog {
  String userText;
  String aiResponse;
  unsigned long ts;
};
const int MAX_DIALOGS = 10;
Dialog history[MAX_DIALOGS];
int dialogCount = 0;
int currentView = 0;
stt.cpp
String sttRequest() {
  HTTPClient http;
  String url =
    String(API_END_POINT) + "/stt";
  http.begin(url);
  http.addHeader(
    "Authorization",
    String("Bearer ") + API_KEY);
  http.addHeader(
    "Content-Type",
    "application/octet-stream");

  int code = http.POST(
    (uint8_t*)record_buffer,
    record_size);

  if (code == HTTP_CODE_OK) {
    String res = http.getString();
    JsonDocument doc;
    deserializeJson(doc, res);
    http.end();
    if (!doc["text"].isNull())
      return doc["text"];
  }
  http.end();
  return "";
}
chat.cpp
String chatRequest(String input) {
  HTTPClient http;
  String url =
    String(API_END_POINT) + "/chat";
  http.begin(url);
  http.addHeader("Authorization",
    String("Bearer ") + API_KEY);
  http.addHeader(
    "Content-Type",
    "application/json");

  JsonDocument req;
  req["text"] = input;
  String payload;
  serializeJson(req, payload);

  int code = http.POST(payload);
  if (code == HTTP_CODE_OK) {
    JsonDocument doc;
    deserializeJson(doc,
      http.getString());
    http.end();
    return doc["response"];
  }
  http.end();
  return "Error.";
}
dialog.cpp
void addDialog(
  String userText,
  String aiResponse) {

  if (dialogCount < MAX_DIALOGS) {
    history[dialogCount]
      .userText = userText;
    history[dialogCount]
      .aiResponse = aiResponse;
    history[dialogCount]
      .ts = millis();
    dialogCount++;
  } else {
    // shift oldest out
    for (int i=0;
         i<MAX_DIALOGS-1; i++) {
      history[i]
        = history[i+1];
    }
    history[MAX_DIALOGS-1]
      .userText = userText;
  }
  currentView = dialogCount-1;
}
platformio.ini
[env:m5stick-c]
platform = espressif32
board = m5stick-c
framework = arduino
board_build.f_cpu = 240000000L
board_upload.flash_size = 8MB
board_build.partitions
  = default_8MB.csv

build_flags =
  -DBOARD_HAS_PSRAM
  -mfix-esp32-psram-cache-issue

lib_deps =
  m5stack/M5Unified@^0.1.14
  tzapu/WiFiManager
  bblanchon/ArduinoJson@^7.0.4
  earlephilhower/ESP8266Audio
  bitbank2/AnimatedGIF@^2.0.1
05 / 07
POCKET AI YOU: What time is it? AI: I don't have real- time data, but I can help with lots of other things! YOU: Tell me a joke
Result

Push to talk.
Get answer.
That simple.

01Hold button → Record voice
02Release → STT transcription
03Auto → LLM inference
04Instant → Screen render
7BModel
16KSample Hz
10Dialogs
1–2hTraining
06 / 07

BUILD
YOUR
OWN
JARVIS

M5StickC Plus2 × Mistral-7B × FastAPI
──────────────────────────────────────────
Next: Model training · Backend API · Desktop client
#ESP32 #LLM #STT #PlatformIO #PocketAI #M5Stack #JARVIS
07 / 07
01 / 07