PocketTrainer
PocketTrainer is a pocket device that hosts a Pokémon sent from Crystal. You walk with it, feed it, pet it and train it, and you take on challenges sent by trainers who found your device's "number". The Pokémon then goes back to Crystal with the experience, stat experience and happiness it earned.
It runs on two ESP32-C3 boards. The look follows mid-2000s handhelds and consoles.
| Board | PlatformIO env | Screen | Input | Steps |
|---|---|---|---|---|
| Round ESP32-C3 1.28" | pockettrainer (default) |
GC9A01 240×240 | CST816 touch | external IMU or simulated |
| Waveshare ESP32-C3-LCD-1.47 | lcd147 |
ST7789T 180×320, portrait | BOOT button only | built-in QMI8658 |
Game logic, network and the Crystal protocol are shared. Only the UI (src/screens.cpp + src/minigames.cpp for the round board, src/rect/ for the 1.47") differs. Shared game flow (rewards, quest start, reset) lives in src/flow.cpp.
Build and flash
pio run -e pockettrainer -t upload # round board
pio run -e lcd147 -t upload # Waveshare 1.47" board
pio device monitor # serial console at 115200 baud
Web flasher
web/ holds a page that lets users flash their own board from Chrome or Edge (Web Serial, ESP Web Tools), with photos to pick the right board.
docker compose up -d --build # http://localhost:8080
- The Docker build compiles both firmwares with PlatformIO, so the server needs no toolchain. Rebuild the image after each firmware change.
- Web Serial only works on
localhostor over HTTPS: in production, put the container behind an HTTPS reverse proxy. - Each firmware is flashed as 4 parts (bootloader, partitions, otadata, app). NVS (PIN, WiFi, energy) and LittleFS (the Pokémon) are left alone, so an update keeps the save; the installer's "erase" option wipes everything.
Waveshare ESP32-C3-LCD-1.47
- Pins (read from the factory firmware): SPI SCLK=7, MOSI=5, DC=8, CS wired; I2C SDA=4, SCL=3. LCD reset and backlight go through Waveshare's I2C IO expander at 0x24 (bit 1 = reset, register 5 = backlight PWM).
- One button: short press = next item, long press (hold ~0.5 s) = confirm. A bar fills on the selected item while you hold.
- Motion (QMI8658 accelerometer + gyro, axes aligned with the screen):
- Steps are counted for real; the gyro bias is tracked automatically while the board is still.
- Hold the board upside down for 0.7 s and the image flips. Picking it up wakes the screen.
- Home: the Pokémon leans with the board and gets dizzy if you shake it.
- Care: rock the board (or tap the button) to pet the Pokémon.
- Mini-games: Force = mash the button and/or shake; Garde = tilt to move the shield into the green zone, then press; Réflexes = a target pops up left or right, flick your wrist toward it (wrong side or too early = penalty); Mémoire = short to move, long to pick. Without a sensor, Garde and Réflexes fall back to button-only versions.
- Serial
imuprints raw and screen-frame readings plus gesture counters. - If red and blue are swapped, flip
rgb_orderinsrc/lgfx_config.h. - Factory firmware backup:
backup/lcd147_factory_4MB.bin(esptool.py write_flash 0 backup/lcd147_factory_4MB.bin).
Gameplay
- Steps: earn XP, heal HP and PP, and add HP stat experience and happiness. Every 250 steps adds 1 energy (max 5). Every 300 steps adds 1 berry (max 9). Every 400 steps, a nearby trainer may call.
- Care:
- Fullness drops over time and with steps; feed a berry to restore it.
- Mood rises when you rub the Pokémon with your finger.
- Both raise Crystal's happiness. A starving Pokémon hits less hard; a very happy one lands more critical hits.
- Training: 1 energy per session. Each mini-game trains one stat:
- Force → Attack
- Garde → Defense
- Réflexes → Speed
- Mémoire → Special
- Challenges:
- Battles against 1 to 3 Pokémon, following Gen 2 rules.
- Mini-games with a target score.
- Challenges come from the server, the local API, or nearby trainers.
- Demo mode: original creatures, so you can play without Crystal.
Crystal and the network
- Protocol, payloads and flows: docs/API.md.
- WiFi setup: Options › WiFi & Crystal › Configurer. Join the WiFi network
PocketTrainer-XXXX, then openhttp://192.168.4.1. - Test tool: tools/pocket_tool.py. It deposits a test Pokémon, pushes challenges, and runs a mock sync server.
Step input
The board has no accelerometer. To count real steps, connect an MPU6050 or QMI8658 to the touch controller's I2C bus: SDA=GPIO4, SCL=GPIO5, 3V3, GND. The firmware detects it automatically.
Without a sensor, you can feed steps in three ways:
- Turn on "Marche auto" in the Options menu.
- Press the debug "+500 pas" button.
- Send the serial command
s N.
Serial commands
| Command | Effect |
|---|---|
s 500 |
Add 500 steps |
xp 200 |
Add 200 XP |
e |
Refill energy |
b |
Refill berries |
heal |
Restore HP |
quest |
Generate a local challenge |
tap X Y |
Simulate a touch at X, Y (round board) |
p / l |
Simulate a short / long button press (1.47" board) |
go N |
Open screen N |
wifi SSID|PASS |
Set the WiFi network |
server URL|TOKEN |
Set the sync server |
sync |
Sync now |
portal |
Start or stop the setup portal |
demo N |
Load demo creature N |
reset! |
Delete the Pokémon and challenges |
Any command prints the current status.