Snake game
This project brings the classic Snake game to life on a minimalist embedded system, offering a retro gaming experience using physical button controls and a dynamic LED matrix display.
Author: Vlad Adascalului
GitHub Project Link: https://github.com/UPB-PMRust-Students/proiect-vladadas01
Description
This project consists of an interactive, classic Snake game implemented on a Raspberry Pi Pico. The game is displayed on a LED matrix screen and controlled using four directional push-buttons. The player navigates the snake on a 2D grid to collect "food," causing the snake's body to grow progressively. The game includes collisions with the walls and the snake's own body. Sound effects for events such as eating food or game over are provided using an MP3 module, offering richer audio feedback compared to simple tones.
Navigate your pixelated snake across a grid, gobbling up food and growing with each bite—all powered by a Raspberry Pi Pico 2W, an LED matrix, four tactile buttons, and an MP3 sound module. This embedded Snake game captures the charm of early arcade games in a compact and educational hardware setup.
Motivation
The motivation behind this project is:
To implement a dynamic game on a resource-constrained embedded device.
To practice real-time rendering and input handling.
To explore using a microcontroller for interactive visual games with hardware.
3. Architecture
The system has the following layers:
- Input Layer:
- 4x Push-buttons (for directional control: up, down, left, right)
- Processing Layer:
- Raspberry Pi Pico 2W
- Game logic engine written in Rust
- MicroSD Card
- Output Layer:
- 1x TFT SPI LCD screen (for visual game rendering)
- 1x Passive buzzer for sound feedback
- 1x DFPlayer Mini MP3 Module (for audio playback)
- 1x PAM8403 Audio Amplifier Module with Potentiometer (for volume control and amplification)
- 1x Set of Car Tweeters 003 (used as audio output/speakers)
Communication is done using:
Component | Interface | Connection Notes |
---|---|---|
TFT LCD Screen | SPI | Uses SPI interface: CLK, MOSI,CS |
Push Buttons (4x) | GPIO | Connected to GPIO with pull-up |
Piezo Buzzer | GPIO | Simple digital on/off control |
DFPlayer Mini MP3 | UART | Connected via UART for audio |
Car Tweeters | Analog | Connected for speakers |
PAM8403 Audio | Analog | Connected to DFPlayer MP3 |
MicroSD Card | SPI/UART | Used for storage |
Diagram
TODO
Log
Week 5 - 11 May
Week 12 - 18 May
Week 19 - 25 May
Hardware
The Raspberry Pi Pico 2W is the central microcontroller for the Snake Game. It offers a dual-core ARM Cortex-M0+ processor and sufficient GPIOs to interface with peripherals required by the system.
The user controls the snake using four tactile push-buttons corresponding to movement directions. The game is displayed on a grid rendered on a TFT SPI LCD screen, offering a colorful and responsive interface. A piezo buzzer is also connected for basic sound feedback, such as playing a tone when food is collected or when the game ends.
Schematics
TODO
Bill of Materials
Device | Usage | Price |
---|---|---|
Raspberry Pi Pico 2W | The microcontroller | 40 RON |
LCD Screen | Displaying the game (Output Device) | 70 RON |
MicroSD card | Memory Storage | 40 RON |
Tweeters Auto | Sound | 10 RON |
MP3 Module | Audio Module | 14 RON |
PAM8403 Potentiometer | Potentiometer | 7 RON |
Passive Buzzer | For collision | 1 RON |
Push Button | Confirm move | 4 x 2 RON |
Breadboard | Testing the connections | 5 RON |
Jumper wires | Connecting the components | 4 x 3 RON |
Total | 207 RON |
Software
Library | Description | Usage |
---|---|---|
embedded-hal | Hardware Abstraction Layer for embedded systems | Abstracts SPI and GPIO interfaces for peripherals like sensors |
embassy | Async framework for embedded Rust | Manages async tasks for input polling, game logic, and display update |
embedded-graphics | 2D graphics library for embedded devices | Used to render the Snake grid and object markers |
rp2040-hal | Hardware Abstraction Layer for Raspberry Pi Pico | Gives the game firmware direct, safe access to on‑chip peripherals |
ili9341 | Platform‑agnostic driver for the ILI9341 SPI TFT controller | Drop‑in alternative if you wire up a larger colour display |
log | Logging facade for Rust | Provides internal logging for debugging |
panic-probe | Panic handler for embedded systems | Helps diagnose runtime panics |
static-cell | Safe static storage | For safely storing peripherals and shared resources in async context |
heapless | Fixed‑capacity, heap‑free data structures (Vec, String, queues, maps) for microcontrollers | Stores the snake’s body coordinates and input queue without dynamic allocation |