In December of 2017, I created a Handheld Arduino Pong Console that used an Arduino Nano and OLED screen, along with two buttons.
This was fine at the time, but the console was a bit too large and cumbersome. Recently, however, I have been trying to recreate some of my past projects. This time, I wanted to make a very tiny console that people can play snake on.
To make the console small, I couldn’t use any Arduino dev board, which is why I went with an ATtiny85.
It features enough I/O to run the game, including two ADC pins and, I2C port, and a GPIO pin. I opted to use a simple 2-axis joystick/switch module, as it is easy to interface with and only needs 3 pins for signaling.
Finally, it was time to decide which display was needed. Since DFRobot’s 128 x 64 OLED screen has a small size but plenty of resolution, I went with it.
To begin, I attached an ATtiny85 to a SOP-8 to DIP-8 breakout PCB and soldered it to a small piece of perf-board. Next, I soldered on two headers- one for programming and the other for the screen. After doing that, I connected the analog joystick’s pins to the perf-board and wired it accordingly. For the final step, I wired a micro USB breakout board to the rest of the system for power.
The enclosure was designed in Fusion 360. I began by creating and laying out the components I used in the actual build, then I created an enclosure around them.
I wanted to mimic an arcade box from the 80’s, but still maintain a very small size. Below are some renders of the enclosure:
Snake is a fairly easy game to program. I set a maximum snake length of 30 to save on RAM, meaning that once the snake has eaten 29 pixels, the player wins. To keep track of the segments of the snake, I created a 2-dimensional array that stores ordered pairs for each segment.
Whenever the head moves to a new location, its previous positions get cascaded downwards. Every time a segment is consumed, a new one is spawned at a random point. Collision checking is done by iterating through the coordinates of each segment and seeing if the head’s coordinates are the same. Additionally, hitting the snake along any of the walls will cause the player to lose as well.
I started by powering on the console and waiting for the screen to load in the food and first segment of the snake. Then I simply piloted the snake by moving the joystick in the correct direction while watching it eat the food. This game is fun to play and is a great boredom killer in a tiny package.