Arduino Snake Game with Raspberry Pi Pico

ear friends, welcome back.  This is Nick, and in this tutorial I’m excited to show you how to create the classic Nokia Snake game on a Raspberry Pi Pico board using Arduino. I remember playing this game when I was teenager and spending hours trying to beat my high score. 

But now, thanks to the accessibility and user-friendly nature of Arduino boards, even a teenager can build this game.    It’s incredible to see how far we’ve come in terms of technology and how it’s become more accessible to everyone.

In this tutorial, I’ll guide you through the process of building the hardware and loading the code required to bring the game to life on a Raspberry Pi Pico board. Of course we will be using the original Nokia 5110 display to make the game as close to the original as possible.

By the end of this video, you will have a fully functional game that you can play and share with your friends. So, let’s get started.

Where to get the parts

To build this project, you’ll need the following components:

? Display: https://educ8s.tv/part/NOKIA5110

? Raspberry Pi Pico: https://educ8s.tv/part/RaspberryPiPico

? Joystick Module: https://educ8s.tv/part/joystick

? Breadboard: https://educ8s.tv/part/LargeBreadboard

? Buzzer: https://educ8s.tv/part/Buzzer

? Wires: https://educ8s.tv/part/Wires

? Jumper Wires: https://educ8s.tv/part/JumperWires

The cost of the project is approximately $12.  Now, let’s move on to connecting all of the components together.

Connecting the Parts

First, we will place the Nokia 5110 display and the Raspberry Pi Pico board on the breadboard as shown, with the joystick module and the buzzer next to them.

We will start by connecting power to both modules. We will connect the 3.3V output of the Raspberry Pi Pico board to the red rail of the breadboard and the GND of the Raspberry Pi Pico board to the blue rail of the breadboard. Next, we will connect the GND pin and the LIGHT pin of the display, the GND pin of the joystick and the GND pin of the speaker to the blue rail of the breadboard. 

Then, we will connect the VCC pin of the display and the VCC pin of the joystick to the red rail of the breadboard, as shown.

Now let’s connect the remaining pins of the display. The first pin is RST and we connect it to pin GP16 of the board. The next pin is named CE and we connect it to pin GP17. The next pin is DC and we connect it to pin GP20. The 4th pin is DIN and we connect it to pin GP19. The last pin we have to connect is CLK and we connect it to pin GP18. That’s it. The display is now connected.

For the joystick module, we will connect the VRX pin to Analog Pin 0 of the board which is right here, the 10th pin counting from the left.

Then we will connect the VRY pin to Analog Pin 1, which is the 9th pin from the left on the Raspberry Pi Pico board. 

Now let’s connect the positive pin of the buzzer to pin GP22 of the board which is right here.

With these connections, our project is now ready to use!

When the project is first powered on, it will display the game title and it will wait to move the joystick.Using the joystick, we can control the movement of the Snake. 

In the snake game, your goal is to move a snake around the board, collecting food and avoiding the edges of the screen and the snake’s own body. When the snake eats food, it grows longer, which makes it harder to avoid crashing into things. The objective is to score as many points as possible by getting as much food as you can before the snake dies.

Once your snake crashes, you’ll see a game over screen that shows your score. To start again, all you have to do is move the joystick. Pretty cool, right? Let’s take a quick look at the code now.

Software

The project requires three libraries to be installed in order to compile and work properly. The first one is the Adafruit_PCD8544 for the Nokia 5110 display.

To install it, simply click on the Library Manager button, and search for the Adafruit_PCD8544 library. Then click the install button. The Arduino IDE will ask you if you want to also download the libraries required along with Nokia 5110 display. Click INSTALL ALL and after a few seconds all the required libraries will be installed on your machine. It is as easy as that.

Once all the libraries are installed, you can upload the code to your Raspberry Pi Pico board and start playing!

You can adjust the difficulty of the game by changing the value of the GAME_SPEED variable. The higher the value the more difficult the game will be. Additionally, the game is developed using Object-Oriented design, m aking it easy to modify the code to work with another display. The game logic remains exactly the same, you only need to change the methods that draw to the screen.

Conclusion

As always, you can find a link to the code of the project in the description of the video below. 

I hope you enjoyed this project and it brought back some nostalgic memories from your childhood. Write me a comment below, I would love to know how this project made you feel.

If you’re interested in understanding the algorithm behind this game, I highly recommend visiting my second YouTube channel, where I’ve created tutorials to guide you through recreating the classic Snake game on your computer. The tutorials provide a comprehensive breakdown of the code, with detailed explanations and animated demonstrations.

If you’re already familiar with C++, you can check out the first video, or if you prefer Python, the second video is a great option.

Also, if you are interested in a version of the Pong game with a color display, you can check out this other video.

Thank you very much!