Arduino Pong Game with Raspberry Pi Pico

Today, we’re embarking on an exciting project to build a classic Pong game using Arduino and an OLED display. In this game, you’ll be playing against the computer, controlling the left paddle using a joystick. As you score points, the score will be updated on the screen. The first player to reach 10 points wins the game! Not only is this project fun to build, but it’s also quick and easy. In just a few minutes, you’ll have your very own Pong game. So, let’s get started and have some fun!

Where to get the parts

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

? Color OLED: https://educ8s.tv/part/OLED13

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

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

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

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

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

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

Connecting the Parts

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

We will start by connecting power to both modules. We will connect the 5V 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 of the display and the GND pin of the joystick 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.

To connect the display, we will connect the SCL pin to pin GP5, which is pin #7 on the Raspberry Pi Pico board. The SDA pin of the display will be connected to pin GP4, which is pin #6.

For the joystick module, we will connect the VRY pin to Analog Pin 1, which is pin #32 on the Raspberry Pi Pico board, right here. We will only be connecting one wire, as we are only interested in the Y-axis movement of the joystick in this game. With these connections, our project is now ready to use!

When the project is first powered on, it will display a splash screen with custom graphics. Once the splash screen is displayed, we can start the game by moving the joystick up or down. Using the joystick, we can control the movement of the right paddle. The objective of the game is to be the first player to reach 10 points. Once a player reaches 10 points, a game over screen will be displayed. To restart the game, we simply need to move the joystick up or down. Isn’t it cool? Let’s take a quick look at the code now.

Software

The project requires only one library to be installed in order to compile and work properly. The library needed is the GyverOLED library for the OLED display. To install it, simply click on the Library Manager button, search for the GyverOLED library, and then click the install button. That’s it. Once the library is installed, you can upload the code to your Raspberry Pi Pico board.

You can adjust the difficulty of the game by changing the value of the GAME_SPEED variable. Additionally, the game is developed using Object-Oriented design, making 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

In this project, I have chosen to use Arduino instead of CircuitPython or MicroPython, because Arduino provides a faster processing speed, which is crucial for a smooth gaming experience. If you want to see the difference in speed for yourself, you can check out this video.

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!