Introduction: Handheld Arduino Pong Console

DFRobot reached out to me recently, wanting me to use their special Arduino Nano board and OLED. At first I wanted to create a smart bike, and I built it to its entirety. But unfortunately the Nano was too weak to run and store the massive sketch that was needed. So I decided to revisit one of my previous projects, a Neopixel matrix that ran a Pong game. I wanted to make it portable instead, and a 1.7" OLED would make a perfect display.

List of Parts:

Step 1: Video

Step 2: Designing the Game

For this Pong game I wanted to keep it relatively simple, which meant nocomputer controlled paddle or fancy ball reflection algorithms. Basically, there is a single paddle that a user can move up or down, and making the ball collide with the paddle would cause its x axis vector to flip. Each time the ball gets hit there is a sound that plays. When the game device is powered on, a screen comes up with the game title and instructions. Additionally, my mother created a small theme song that loops in the background until the top button is pressed.

Step 3: Designing the Gaming Device

My go-to CAD program is Fusion 360, so I decided to use it to design my pong gaming device. I began by designing each component used: an OLED, Arduino Nano, and a speaker.This way I can see exactly where and how each component should fit inside of the enclosure. I then put the Nano and PCB in the back part of the case, and the OLED on top of it. Next was the question of where to put the speaker and buttons. I decided that the 3W speaker could go just below the screen (looking at it from the top), and that also required putting a "grill" over the speaker so the sound wouldn't be muffled. Lastly, I added two buttons on the left side to add controls.

Step 4: Constructing the Device

I began by 3D printing each part, consisting of the lower half, the upper half, and 2 buttons. Next I soldered a female header to the 4x6cm and wired it to the Nano. This not only allows for the OLED to be easily removed, but it also elevates it above the Arduino Nano. Check the schematic for wiring information. Then I wired up the two buttons, along with a simple micro USB breakout board for power. The speaker was also attached and placed it its correct position. My Fusion 360 design allows for 3mm machine screws to hold down the OLED, speaker, and connect the two halves of the device. But, I had to make them exact, so I used my drill press to bore out 8 holes: 2 for the speaker, 2 for the screen, and 4 underneath. You can visit the Thingiverse link for the files.

Step 5: Programming the Game

The use of a simple interface was vital to keeping the program small. I started by adding several libraries: Adafruit_GFX, Adafruit_SSD1351, and the Arduino Timer library. Next I defined my pins and colors, such as the OLED's pins and 16 bit color definitions. In my code there are also 4 ways to change how the game plays, such as changing the paddle dimensions and how quickly the ball moves. A section then exists where each variable is defined, including the score and various coordinates. Whenever the device is powered on an image of a ball and some text appears on the screen, along with a little theme song which is defined earlier in the code. Once the game starts two timers are created, one that updates the paddle, and the other updates the ball. Each time the ball's position updates its coordinates are checked to make sure it doesn't go past the screen border or if it's touching a paddle. Each time it bounces either its x or y axis is inverted and a small tone plays. Watch the video at the beginning of this writeup to see how the game plays.

Step 6: Playing Pong!

The name of the game is to get the lowest score possible. There is no time limit, so it is very enjoyable and even trance-inducing. All that is necessary is pushing one of two buttons to move the paddle up or down. It is also possible to add a way to store the highest score using the Arduino's EEPROM.