Skip to main content
Version: ACS CC

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.

info

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:

ComponentInterfaceConnection Notes
TFT LCD ScreenSPIUses SPI interface: CLK, MOSI,CS
Push Buttons (4x)GPIOConnected to GPIO with pull-up
Piezo BuzzerGPIOSimple digital on/off control
DFPlayer Mini MP3UARTConnected via UART for audio
Car TweetersAnalogConnected for speakers
PAM8403 AudioAnalogConnected to DFPlayer MP3
MicroSD CardSPI/UARTUsed for storage

Schematic Diagram

Diagram

TODO

Log

Week 5 - 11 May

Documentation milestone, materials purchase, preparing materials for installation and testing the components.

Week 12 - 18 May

Assembled all the materials and wired everything up. Wrote test software for each component to check good installation. Created the schematics in KiCad mirroring the phisical connections. Completed the Hardware Milestone.

Week 19 - 25 May

I implemented the core functionality of the Snake game, along with a working menu.

Hardware

The Raspberry Pi Pico 2W is the central microcontroller for the Snake Game. It offers a 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. The snake game has a score system, and the game finish when the snake collide with a wall or when the head collide with snake's body. Also, when the snake eats it will become bigger.

VIDEO: Testing the Components

Hardware1 Hardware2 Hardware3

Schematics

Schematic KiCad

Bill of Materials

DeviceUsagePrice
Raspberry Pi Pico 2WThe microcontroller40 RON
LCD ScreenDisplaying the game (Output Device)70 RON
MicroSD cardMemory Storage40 RON
Tweeters AutoSound10 RON
MP3 ModuleAudio Module14 RON
PAM8403 PotentiometerPotentiometer7 RON
Passive BuzzerFor collision1 RON
Push ButtonConfirm move4 x 2 RON
BreadboardTesting the connections5 RON
Jumper wiresConnecting the components4 x 3 RON
Total207 RON

Software

The Snake Game implementation features an interactive splash menu, responsive snake movement with wall and self-collision detection, score tracking via dynamic rendering on the ILI9341 display, and a game‐over screen that seamlessly returns the player to the menu.

Software Diagram

LibraryDescriptionUsage
embedded-halHardware Abstraction Layer for embedded systemsAbstracts SPI and GPIO interfaces for peripherals like sensors
embassyAsync framework for embedded RustManages async tasks for input polling, game logic, and display update
embedded-graphics2D graphics library for embedded devicesUsed to render the Snake grid and object markers
rp2040-halHardware Abstraction Layer for Raspberry Pi PicoGives the game firmware direct, safe access to on‑chip peripherals
ili9341Platform‑agnostic driver for the ILI9341 SPI TFT controllerDrop‑in alternative if you wire up a larger colour display
logLogging facade for RustProvides internal logging for debugging
panic-probePanic handler for embedded systemsHelps diagnose runtime panics
static-cellSafe static storageFor safely storing peripherals and shared resources in async context
heaplessFixed‑capacity, heap‑free data structures (Vec, String, queues, maps) for microcontrollersStores the snake’s body coordinates and input queue without dynamic allocation
rand_core + rand_xorshiftUsed for generating random numbersStores the food's position randomly