µLife: Conway's Game of Life Keychain

µLife: Conway's Game of Life Keychain

Compact keychain device running Conway's Game of Life on a 400-LED matrix using charlieplexing with STM32G431

Status:Completed
Created:December 15, 2024
Conway's Game of LifeCharlieplexingSTM32LED MatrixPCB Design

Project Description

µLife: Conway’s Game of Life Keychain

µLife (pronounced “mu-Life”) is a compact keychain device that runs Conway’s Game of Life on a 400-LED matrix.

Project Context

This keychain device was inspired by watching bitluni’s electronics videos and a recent C++ implementation of Conway’s Game of Life for a school project. The goal was to create a portable, conversation-starting demonstration of this fascinating cellular automaton that could showcase both the mathematical elegance of Conway’s rules and practical embedded systems engineering.

Rather than build yet another LED matrix display, I decided to tackle the specific challenge of implementing a full Game of Life simulator in keychain form factor. This required solving several interconnected engineering problems: controlling 400 LEDs with minimal GPIO pins, achieving sufficient brightness in a power-constrained design, and creating professional-quality firmware architecture.

Technical Implementation

Charlieplexing Architecture

The core innovation lies in using charlieplexing to control a 20×20 LED matrix (400 LEDs) with only 21 GPIO pins from the STM32G431CBU6 microcontroller. This technique leverages tri-state logic to achieve N(N-1) addressable LEDs with N GPIO pins, compared to N²/4 LEDs with standard multiplexing.

The mathematical relationship for required pins is n = ⌈1 + √L⌉, where L is the number of LEDs. For 400 LEDs, this yields exactly 21 pins - a perfect match for the available GPIO count while leaving pins for power management and user interface.

Hardware Design Evolution

Prototype 1: Proof of Concept - NUCLEO-F030R8 development board for initial validation - External LED matrix board with headers for flexible testing - 100Ω and 220Ω series resistors for current limiting - Achieved 58 Hz refresh rate but suffered from dim display

Prototype 2: Final Design - Custom STM32G431CBU6 implementation with 5× better CoreMark performance - Reduced series resistors to 1Ω for maximum LED brightness - Integrated USB-C power with XC6206P332MR-G LDO regulator - 120 Hz refresh rate for flicker-free operation - Cost-optimized using JLCPCB basic parts library

Firmware Architecture

The software follows a layered architecture separating hardware abstraction, game logic, and user interface:

  • Driver Layer: STM32 HAL integration, timer interrupts, True-RNG
  • Hardware Abstraction: Custom charlieplexing driver, button management
  • Application Layer: Game of Life engine, pattern management, user controls

Key features include detection of single, double, and long button presses, pre-programmed classic patterns (gliders, oscillators), and cryptographically random grid generation using the STM32’s True-RNG module.

Engineering Challenges and Solutions

Display Brightness Optimization

The initial prototype suffered from insufficient brightness due to the brief duty cycle of charlieplexed LEDs. Rather than accept this limitation, I systematically reduced the series resistors from 220Ω down to 1Ω, pushing the LEDs to their maximum current rating while maintaining GPIO safety margins. This increased brightness significantly while staying within the 20mA GPIO source/sink capability.

Performance Scaling

The STM32F030R8 proved inadequate for real-time Game of Life calculations at acceptable refresh rates. Upgrading to the STM32G431CBU6 provided 3.5× higher clock frequency (170 MHz vs 48 MHz) and 5× better computational performance (569 vs 106 CoreMark score), enabling smooth 120 Hz operation with responsive user controls.

Manufacturing Optimization

Assembly costs were controlled by leveraging JLCPCB’s basic parts library, limiting non-standard components to five essential parts (MCU, TVS diode, LEDs, USB connector, buttons). This strategy reduced setup fees from potentially $60+ to $15 across five boards, achieving a final cost of €10.61 per assembled unit.

Mechanical Design

The enclosure consists of two 3D-printed transparent resin pieces joined by M2 screws. The design accommodates the 3×5 cm PCB dimensions (slightly larger than the original 3×4 cm target due to routing constraints) while providing cutouts for USB-C connectivity and flush button mounting.

Key design considerations included 0.5 mm clearance around the PCB, specialized cutout for the tantalum capacitor, and countersunk screw holes for a clean aesthetic. The final dimensions of 34×54×6.85 mm maintain excellent portability while protecting the electronics.

Technical Specifications

  • Microcontroller: STM32G431CBU6 (170 MHz, ARM Cortex-M4)
  • Display: 20×20 white LED matrix (400 total LEDs)
  • Control Method: Charlieplexing with 21 GPIO pins
  • Refresh Rate: 120 Hz flicker-free
  • Power: USB-C input, 3.3V regulated, ~150mA operation
  • User Interface: Two tactile buttons with multi-press detection
  • Enclosure: Transparent resin, 34×54×6.85 mm
  • Assembly: Professional PCBA with lead-free HASL finish

Results and Performance

The final device successfully demonstrates Conway’s Game of Life with smooth animation and responsive controls. The True-RNG implementation generates genuinely unique patterns - with 2⁴⁰⁰ possible grids, each random generation is statistically guaranteed to be unprecedented.

Current consumption remains well below the 250mA design target, typically drawing 150mA during operation. The display achieves good visibility in normal indoor lighting, though bright sunlight remains challenging due to the fundamental physics of LED multiplexing.

Future Development

The next iteration will transition to an OLED display for crisp HD rendering and much larger grid sizes. This approach will eliminate the brightness limitations inherent in charlieplexing while potentially reducing overall device size. The current version serves as an excellent foundation, successfully proving the concept and providing valuable insights for the enhanced design.

Technical Documentation

The complete development process, including detailed schematics, firmware architecture diagrams, and 3D models, is documented in the full development journal. This project demonstrates practical application of embedded systems design, real-time programming, advanced GPIO techniques, and professional PCB development workflows.

Gallery

Project Files

Development Journal (PDF)

Document • 3.1 MB