PiSweeper
A Minesweeper game controlled via buttons and a joystick, displayed on an LCD screen
Author: Robert-Ionut Barbu
GitHub Project Link: https://github.com/UPB-PMRust-Students/proiect-robertbarbu27
Description
A portable Minesweeper game system that runs on a Raspberry Pi Pico W, featuring user interaction through a joystick and multiple buttons. The current game state is rendered on a color LCD screen, offering a compact yet fully playable experience of the classic logic puzzle.
- A joystick is used for cursor movement across the grid
- Two buttons allow the player to reveal a tile or place/remove a flag
- A status LED indicates the current mode: red for flagging, green for reveal
- The LCD screen displays the entire Minesweeper board in real time
Motivation
I chose this project because I used to play Minesweeper a lot when I was younger, and I’ve always enjoyed the logical thinking and strategy it involves. Recreating it on a microcontroller gave me the opportunity to combine that nostalgic interest with my passion for embedded systems. Using embedded Rust added an extra layer of complexity, requiring precise control over hardware components like the joystick, buttons, LEDs, and LCD display. The challenge of managing real-time input, rendering a dynamic game interface, and handling game logic efficiently made it a perfect project to deepen my understanding of embedded development.
Architecture
The system is organized into several core components that interact in a modular and efficient way, enabling a responsive and playable Minesweeper experience on embedded hardware. The architecture is structured as follows:
Main Components
- Input Handler: Reads input from the joystick and buttons, translates raw signals into high-level game actions (e.g., move cursor, reveal tile, place flag).
- Game Engine: Contains the core Minesweeper logic: grid generation, mine placement, flagging, flood fill for empty tiles, win/loss detection, and game state tracking.
- Display Renderer: Responsible for drawing the game board, cursor, flags, and mines to the LCD screen using
embedded-graphics
and thest7789
driver. - State Manager: Maintains the current game state (e.g., in-progress, won, lost, flag mode/reveal mode) and handles transitions based on user input and game logic.
- Feedback Controller: Controls the status LED to reflect the current mode (e.g., red for flag, green for reveal), and optionally a buzzer or other indicators for win/loss events.
Log
Week 5 - 11 May
Week 12 - 18 May
Week 19 - 25 May
Hardware
-
Raspberry Pi Pico W
- The microcontroller running the game logic and managing hardware interactions
-
Joystick Module
- Used for navigating the cursor across the Minesweeper grid
-
Button 1 (Reveal)
- Used to uncover a tile
-
Button 2 (Flag)
- Used to place or remove a flag on a tile
-
240x240 SPI LCD Screen (ST7789)
- Displays the game board and user interface
-
Status LED
- Indicates the current action mode: green for reveal, red for flag
Schematics
Bill of Materials
Device | Usage | Price |
---|---|---|
Raspberry Pi Pico W | The microcontroller | 79,32 lei |
Breadboard HQ (830 points) | For prototyping and connections | 22,00 lei |
10 cm 40p Male-Female Wires | General wiring | 5,99 lei |
20 cm 40p Male-Female Wires | General wiring | 7,99 lei |
Separated Male-Male Wires 20 cm – 10 pcs | Connections between modules | 11,90 lei |
2.2" 240x320 SPI LCD | Displays the Minesweeper grid | 59,99 lei |
White Button with Round Cover | User input (reveal/flag) | 3,98 lei |
40p 1.27 mm Male Pin Header | Soldering and module connections | 3,84 lei |
Joystick Module | Controls the cursor | ~5,35 lei |
LEDs (x2: red & green) | Status indicator (flag/reveal mode) | ~1,00 lei |
Software
Library | Description | Usage |
---|---|---|
st7789 | Display driver for ST7789 | Used to send pixel data to the LCD screen via SPI |
embedded-graphics | 2D graphics library for embedded systems | Used to draw the Minesweeper grid, cursor, and symbols |
embassy | Async runtime for embedded Rust | Manages concurrency between input polling, display updates, and game logic |
embedded-hal | Hardware Abstraction Layer | Provides unified interfaces for SPI, GPIO, ADC, etc. |
rp2040-hal | HAL for the Raspberry Pi Pico (RP2040) | Controls the Pico W’s hardware peripherals in Rust |
defmt + defmt-rtt | Logging framework for embedded Rust | Used for debugging over RTT during development |