Skip to main content

Snakes and Apples

My project has the goal of using a Raspberry Pi to simulate the old video game Snake.

info

Author: Radu Matei
GitHub Project Link: https://github.com/UPB-FILS-MA/project-matei7-7

Description

In my project I want to recreate the original game simply known as "Snake" on a Raspberry Pi, using an LCD display as a screen and four buttons as the movements of the player-controlled snake. The fifth and final button will only be for starting the game. The game consists of a snake that can move up, left, down or right and of randomly generating apples that the snake has to eat in order to get bigger and, therefore, gain a higher score. The display will work using Embedded-graphics, displaying for the whole duration of the game the game area, where apples can spawn and the player can move to get them, and at the top, separated from the rest of the game, there will be a score counter and a current high score. The game stops when the snake collides with its own head or one of the borders. During the game, buzzers will be used to create sound effects when gaining score or dying, and for the background music.

Motivation

Ever since I was a child, I have been playing video games - from the first ever look over my dad's shoulder to see what he was doing on the computer I was hooked. I've been playing them my whole life ever since, and since high school, where I discovered coding and that I was very good at it, my dream became very clear to me: creating video games. I have done my fair share of coding problems and even games in Unity, and the software part is what I really love. And now, I have the opportunity to make a game, code it, and then make a physical machine that will run my game. Physically. That sounds amazing and, even if hardware is not really my specialty, I will do my best to make the best game I can.

Architecture

Project_architecture

Log

Week 6 - 12 May

  • created index.md
  • made a prototype of the KiCad schematic
  • starting to experiment with cardboard boxes and other things that could be used as a cover for the wiring and the hardware

Week 7 - 19 May

  • ordered the physical pieces
  • assembled them on a breadboard
  • didn't find my LCD as a KiCad component, not even with Mouser's site, so made my own custom LCD using KiCad
  • finalized KiCad schematic

Week 20 - 26 May

  • went through 4 iterations of code
  • slowly but surely managed to get through every problem
  • optimized everything I could
  • added background music and stunning visuals
  • put LCD and buttons on a smaller breadboard for easier access

Hardware

  • Raspberry Pi Pico W
    A microcontroller for the project - takes input from the buttons and displays the game scene accordingly

  • LCD Display
    A display that shows a grid for the snake to move through, the snake, the apples, and at the top the score and the current high score - microcontroller takes care of the software and displays it on the LCD ST7735

  • Buzzer/Buzzers
    These are used for background music and sound effects when dying, gaining score and when achieving a high-score - microcontroller sends signals when a specific event happens

  • Buttons
    These are used to control the snake - they are put in a N/W/S/E formation and represent every movement that the player can do; the fifth button is just for starting the game - these send signals to the microcontroller

This is the current prototype of my project, changes are 100% going to happen - a mask is going to be put to hide the hardware and the screen + the buttons will be moved to a separate breadboard to be more easily accessed for the user:

Project_seen_from_above

Project_seen_from_one_side

Project_seen_from_the_other_side

Schematics

KiCad

Bill of Materials

DeviceUsagePrice
Rapspberry Pi Pico WThe microcontroller35 RON
LCD SPI DisplayThe display - ST773530 RON
3.3V BuzzerBuzzers for sound effects and background music2 RON / Buzzer
Buttons4 Buttons for the movement buttons + 1 Button for ON switch2 RON
WiresWires for connecting the hardware7 RON
BredboardBredboard for connecting the hardware10 RON
ResistorsResistors0.1 RON

Software

LibraryDescriptionUsage
ST7789Display driver for ST7789Used for the display
embedded-graphics2D graphics libraryUsed for drawing to the display
embassy-timeTime delay libraryUsed for timing of music and creating RNG
embassy-embedded-halSPI and I2C libraryUsed for actually configuring the SPI lcd
embassy-rpClosest to a default libraryUsed for SPI, GPIO pins and peripherals
  1. Snake (Video Game)
  2. Snake - Code for C++
  3. Youtube link for custom KiCad schematic
  4. Greatly helped with frequencies for all music notes
  5. VS Code shortcuts - made my life way easier