Back to projects

System Level Design · Embedded Systems

Digital Ball-in-Maze Puzzle

A ball-in-maze game on an STM32, IMU-driven ball physics smoothed with a Kalman filter and rendered on an OLED. Open-ended ECSE 444 final project.

From prototype to PCB

Status
April 2023 · McGill ECSE 444 (Microprocessors) · Project
Stack
STM32 microcontroller (STM32CubeIDE) · C / Embedded C++ · On-board IMU (I2C) · ADC / DAC · Kalman filtering

Overview

Inspired by the classic ball-in-maze puzzle, I implemented a digital version as an embedded system on an STM32, the open-ended final project for McGill’s Microprocessors course (ECSE 444). Tilting the board moves a ball through a maze rendered on the OLED, with the motion driven by the microcontroller’s on-board inertial sensor.

What I did

Approach and key decisions

Kalman filtering is the heart of it. Raw accelerometer data is noisy enough that a directly-driven ball feels twitchy and unplayable. Estimating the true tilt with a Kalman filter is what turns the raw IMU stream into smooth, controllable motion, the single decision that makes the puzzle actually feel good to play.

From prototype to PCB

The ECSE 444 build proved the concept on an STM32 dev board. The project then grew into a purpose-built custom PCB: a round, USB-C powered board designed in KiCad around an ESP32-S2 (later developed for UC Berkeley’s HOPE decal, with Jonathan Lin and Alejandro Munico). The board folds everything the breadboard prototype needed onto a single self-contained device:

Figures

Prototype (STM32)

STM32 development board running the ball-in-maze game, with the maze and ball shown on a small OLED display. The original puzzle running on the STM32 dev board, maze rendered on the OLED.

Custom PCB

Full KiCad schematic of the custom ball-in-maze board, with USB-C, reset and bootstrap, power management, display interface, inertial measurement unit, and haptics sections around an ESP32-S2-SOLO. Custom board schematic: USB-C and battery power, ESP32-S2, IMU, SPI display, and haptics.

PCB layout of the round board showing the top copper (red) and bottom copper (blue) layers side by side. Round PCB layout, top (red) and bottom (blue) copper.

Photograph of the bare assembled PCB, a green round board with the ESP32-S2 module, USB-C connector, crystal, and buttons populated. The fabricated and assembled board.

The assembled board powered on, running the maze on its round OLED display. From prototype to product: the custom board running the maze on its OLED.