Skip to main content
Version: ACS CC

PiSweeper

A Minesweeper game controlled via buttons and a joystick, displayed on an LCD screen

info

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

block

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 the st7789 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

  1. Raspberry Pi Pico W

    • The microcontroller running the game logic and managing hardware interactions
  2. Joystick Module

    • Used for navigating the cursor across the Minesweeper grid
  3. Button 1 (Reveal)

    • Used to uncover a tile
  4. Button 2 (Flag)

    • Used to place or remove a flag on a tile
  5. 240x240 SPI LCD Screen (ST7789)

    • Displays the game board and user interface
  6. Status LED

    • Indicates the current action mode: green for reveal, red for flag

Schematics

kicad

Bill of Materials

DeviceUsagePrice
Raspberry Pi Pico WThe microcontroller79,32 lei
Breadboard HQ (830 points)For prototyping and connections22,00 lei
10 cm 40p Male-Female WiresGeneral wiring5,99 lei
20 cm 40p Male-Female WiresGeneral wiring7,99 lei
Separated Male-Male Wires 20 cm – 10 pcsConnections between modules11,90 lei
2.2" 240x320 SPI LCDDisplays the Minesweeper grid59,99 lei
White Button with Round CoverUser input (reveal/flag)3,98 lei
40p 1.27 mm Male Pin HeaderSoldering and module connections3,84 lei
Joystick ModuleControls the cursor~5,35 lei
LEDs (x2: red & green)Status indicator (flag/reveal mode)~1,00 lei

Software

LibraryDescriptionUsage
st7789Display driver for ST7789Used to send pixel data to the LCD screen via SPI
embedded-graphics2D graphics library for embedded systemsUsed to draw the Minesweeper grid, cursor, and symbols
embassyAsync runtime for embedded RustManages concurrency between input polling, display updates, and game logic
embedded-halHardware Abstraction LayerProvides unified interfaces for SPI, GPIO, ADC, etc.
rp2040-halHAL for the Raspberry Pi Pico (RP2040)Controls the Pico W’s hardware peripherals in Rust
defmt + defmt-rttLogging framework for embedded RustUsed for debugging over RTT during development
  1. Minesweeper Game Logic Explained (YouTube - Coding Train)
  2. Lab 02 – GPIO
  3. Lab 03 – PWM & ADC
  4. Lab 04 – Asynchronous Development
  5. Lab 05 – Serial Peripheral Interface (SPI)
  6. Lab 06 – Inter-Integrated Circuit (I2C)
  7. Lab 07 – Wi-Fi