titimoby/StackChan-pilotpublic Fork
⑂ main
Commits
⬇ Clone ▾
git clone https://git.rickub.com/titimoby/StackChan-pilot.git
git clone ssh://git@rickub.com/titimoby/StackChan-pilot.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Download ZIP
switch to english 6c77733 · on main · Thierry Chantier · 32m ago
CLAUDE.md · 49 lines · 4.4 KBmarkdown
Blame HistoryOpen raw

StackChan — firmware and control from Claude

Personal project: firmware and tooling for the M5Stack StackChan (K151) desktop robot — CoreS3 (ESP32-S3) + motorized body (2 Feetech SCS0009 servos, 12 LEDs, head touch, NFC, IR). Repository docs and code are in English; talk to the user in French.

Architecture

Claude sessions ──MCP HTTP 127.0.0.1:8765/mcp──> mcp/ (Python, shared stackchan-mcp server) ──USB serial, JSON-lines──> firmware/ (Arduino, CoreS3)
  • firmware/ — PlatformIO, Arduino framework. src/main.cpp: protocol + gestures; src/face.{h,cpp}: face drawn into a PSRAM sprite.
  • mcp/ — MCP server (mcp SDK 2.x: MCPServer in mcp.server.mcpserver, not FastMCP). robot.py: serial link; sessions.py: control lease and per-session event cursors; server.py: tools.
  • The server is registered at user scope (claude mcp add --transport http --scope user stackchan http://127.0.0.1:8765/mcp), so every session sees it; it is started manually with tools/stackchan-server.sh start|stop|status|logs.
  • tools/serial_cmd.py, tools/serial_read.py — raw serial access for debugging without MCP.
  • docs/hardware-reference.md (hardware, pinout), docs/protocol.md (firmware ↔ server contract, keep it up to date with every new command).

Commands

cd firmware && pio run                                              # build
cd firmware && pio run -t upload --upload-port /dev/cu.usbmodem101 # flash
cd mcp && uv sync                                                   # MCP server dependencies
tools/stackchan-server.sh start                                     # shared MCP server (logs: ~/Library/Logs/stackchan-mcp.log)
~/.local/share/uv/tools/platformio/bin/python -I tools/serial_cmd.py /dev/cu.usbmodem101 3 '{"id":1,"cmd":"status"}'
  • pio is installed with uv tool (~/.local/bin/pio). Platform pioarduino 55.03.313 (Arduino core 3.3.13): the official espressif32 platform is too old for the M5StackChan lib. Do not move to core 4.x without validating M5Unified/M5GFX.
  • USB port: /dev/cu.usbmodem101 (Espressif VID 303A). Flashing works without manual download mode.

Important rules

  • Only one process on the USB port at a time. The shared server keeps it open. To flash: flash_firmware tool; for a manual pio run -t upload or tools/serial_cmd.py: run tools/stackchan-server.sh stop first.
  • Control lease between sessions: a robot command grants control for 10 s (extended by each command); other sessions are refused. get_status, stop and touch stay free. A "robot in use by another session" refusal is expected: wait, or ask the user.
  • If the robot stops answering entirely (even to esptool) while the USB port is listed: ask the user to unplug/replug the USB cable.
  • Opening the port reboots the robot (macOS / USB-Serial-JTAG), even with DTR/RTS low: wait for the {"event":"boot"} event before sending commands. Face and LEDs go back to their initial state.
  • Servo limits (BSP units = 1/10°): yaw −90…+90°, pitch 5…85° (beyond: risk of stalling and breakage, M5Stack recommendation). Clamping is done in the firmware (kYawMin/Max, kPitchMin/Max) — do not loosen it.
  • Verified directions: positive yaw = head turns towards the robot's left; larger pitch = looks up; (0, 0) = calibrated position, screen perpendicular to the base.
  • Zero calibration lives in NVS (namespace servo, keys zero_pos_1/2) and must be redone after a third-party firmware. It requires the user to position the head by hand (torque off) — never call set_home without them.
  • Do not force the head by hand while the motors are powered.
  • Servo bus: UART1 1 Mbaud, TX=G6 / RX=G7. Body I2C (G11/G12): INA226 0x41, NFC 0x50, Si12T 0x68, PY32L020 IO expander 0x6F (servo power + LEDs).
  • The servo moving flag can stay true at rest: judge the end of a move on position stability (see _wait_still in server.py).

Validation

No automated tests. After any change: build, flash, then exercise the affected commands via tools/serial_cmd.py or an MCP client (restart the server after changing mcp/: tools/stackchan-server.sh restart), and ask the user what they see (screen, LEDs, movements) — I cannot observe it.

Validated versions

M5StackChan 1.1.1, M5Unified 0.3.0, M5GFX 0.3.0, ArduinoJson 7.x, mcp 2.3, custom firmware 0.1.0. The original M5Stack firmware (XiaoZhi) has been overwritten; it can be restored with M5Burner.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# StackChan — firmware and control from Claude

Personal project: firmware and tooling for the **M5Stack StackChan (K151)** desktop robot — CoreS3 (ESP32-S3) + motorized body (2 Feetech SCS0009 servos, 12 LEDs, head touch, NFC, IR). Repository docs and code are in English; talk to the user in French.

## Architecture

```
Claude sessions ──MCP HTTP 127.0.0.1:8765/mcp──> mcp/ (Python, shared stackchan-mcp server) ──USB serial, JSON-lines──> firmware/ (Arduino, CoreS3)
```

- `firmware/` — PlatformIO, Arduino framework. `src/main.cpp`: protocol + gestures; `src/face.{h,cpp}`: face drawn into a PSRAM sprite.
- `mcp/` — MCP server (`mcp` SDK **2.x**: `MCPServer` in `mcp.server.mcpserver`, not `FastMCP`). `robot.py`: serial link; `sessions.py`: control lease and per-session event cursors; `server.py`: tools.
- The server is registered at **user** scope (`claude mcp add --transport http --scope user stackchan http://127.0.0.1:8765/mcp`), so every session sees it; it is started **manually** with `tools/stackchan-server.sh start|stop|status|logs`.
- `tools/serial_cmd.py`, `tools/serial_read.py` — raw serial access for debugging without MCP.
- `docs/hardware-reference.md` (hardware, pinout), `docs/protocol.md` (**firmware ↔ server contract**, keep it up to date with every new command).

## Commands

```bash
cd firmware && pio run                                              # build
cd firmware && pio run -t upload --upload-port /dev/cu.usbmodem101 # flash
cd mcp && uv sync                                                   # MCP server dependencies
tools/stackchan-server.sh start                                     # shared MCP server (logs: ~/Library/Logs/stackchan-mcp.log)
~/.local/share/uv/tools/platformio/bin/python -I tools/serial_cmd.py /dev/cu.usbmodem101 3 '{"id":1,"cmd":"status"}'
```

- `pio` is installed with `uv tool` (`~/.local/bin/pio`). Platform **pioarduino 55.03.313** (Arduino core 3.3.13): the official espressif32 platform is too old for the `M5StackChan` lib. Do not move to core 4.x without validating M5Unified/M5GFX.
- USB port: `/dev/cu.usbmodem101` (Espressif VID `303A`). Flashing works without manual download mode.

## Important rules

- **Only one process on the USB port at a time.** The shared server keeps it open. To flash: `flash_firmware` tool; for a manual `pio run -t upload` or `tools/serial_cmd.py`: run `tools/stackchan-server.sh stop` first.
- **Control lease between sessions**: a robot command grants control for 10 s (extended by each command); other sessions are refused. `get_status`, `stop` and touch stay free. A "robot in use by another session" refusal is expected: wait, or ask the user.
- If the robot stops answering entirely (even to `esptool`) while the USB port is listed: ask the user to unplug/replug the USB cable.
- **Opening the port reboots the robot** (macOS / USB-Serial-JTAG), even with DTR/RTS low: wait for the `{"event":"boot"}` event before sending commands. Face and LEDs go back to their initial state.
- **Servo limits** (BSP units = 1/10°): yaw −90…+90°, pitch **5…85°** (beyond: risk of stalling and breakage, M5Stack recommendation). Clamping is done in the firmware (`kYawMin/Max`, `kPitchMin/Max`) — do not loosen it.
- **Verified directions**: positive yaw = head turns towards **the robot's left**; larger pitch = looks up; (0, 0) = calibrated position, screen perpendicular to the base.
- Zero calibration lives in NVS (namespace `servo`, keys `zero_pos_1/2`) and must be redone after a third-party firmware. It requires the user to position the head by hand (torque off) — never call `set_home` without them.
- Do not force the head by hand while the motors are powered.
- Servo bus: UART1 1 Mbaud, TX=G6 / RX=G7. Body I2C (G11/G12): INA226 0x41, NFC 0x50, Si12T 0x68, PY32L020 IO expander 0x6F (servo power + LEDs).
- The servo `moving` flag can stay true at rest: judge the end of a move on position stability (see `_wait_still` in `server.py`).

## Validation

No automated tests. After any change: build, flash, then exercise the affected commands via `tools/serial_cmd.py` or an MCP client (restart the server after changing `mcp/`: `tools/stackchan-server.sh restart`), and ask the user what they see (screen, LEDs, movements) — I cannot observe it.

## Validated versions

M5StackChan 1.1.1, M5Unified 0.3.0, M5GFX 0.3.0, ArduinoJson 7.x, mcp 2.3, custom firmware 0.1.0. The original M5Stack firmware (XiaoZhi) has been overwritten; it can be restored with M5Burner.