Playing the "Dinosaur Run Game" on an ATtiny10 Without Batteries

Jump and dodge obstacles on this keychain-sized PCB game console!

Evan Rust
5 years agoWearables / Displays

It has happened to almost all of us: suddenly going offline while using Chrome and having that dinosaur run game pop up. This is what inspired this project's creator, ridoluc, to develop a much smaller implementation of the game. What he was able to come up with can fit in a 34 x 25mm area and run indefinitely without the need for a battery.

How the game works

The dino run game has a fairly self-explanatory title. The user starts with their character positioned at the beginning of the map, and as the game progresses, there are more obstacles to hop over at an ever-increasing speed. Once the T-Rex has encountered an obstacle, the game ends and can be restarted at the beginning. The score is calculated by seeing how many "steps" have been completed.

Components

In order to make this game "system" as small as possible, it was vital that the microcontroller also be... tiny. So the choice was the ATtiny10, which as the name implies, is very tiny in both physical size and capabilities. Just for reference, the ATmega328P (what the Arduino Uno uses) has 32KB of flash and 2KB of RAM. In comparison, the ATtiny10 has a mere 1KB of flash, 32 bytes of RAM, for GPIO pins, and a single 16-bit timer, although it is only 1.6 x 2.9mm large.

For the display, he went with a simple 128x32 OLED which is controlled via I2C. Power is stepped up with a boost converter that charges a supercapacitor. This way, small decreases in power from the onboard solar panels on the back won't shut everything off immediately. With this circuitry, the game can run as long as there is enough sunlight striking the back of the board.

The PCB

Using a breadboard for the circuit wouldn't suffice due to its large size and inability to handle tiny components, so a custom PCB was in order. The entire backside is taken up by the solar cell, and its output is routed to the front into a boost converter. The converted power is sent to the rest of the components and the capacitor for smoothing. On the top is the OLED, which is attached directly to the PCB rather than over the board it came with. Finally, the ATtiny10 is soldered just below, and it attaches to the OLED and the jump button which is positioned at the bottom.

Driving a display

Ordinarily, an I2C display would be connected to hardware I2C pins and the programmer would talk with it through an API. However, only having 32 bytes of memory to work with means that the normal framebuffer is unusable. So, the program is written entirely in assembly to make up for this. I2C data is sent over two of the four GPIO pins using a "bit-banged" protocol (individual bits are sent at the application level) rather than placing them into a dedicated hardware buffer.

Programming the game

As mentioned before, everything is written in AVR assembly, so it might be hard for most people to understand, although it does have ample comments. The program begins by initializing the display and setting up where enemies will appear, as well as the current score (0) and the player's position. There is a custom TWI driver for the display that takes in a byte from register R20 and uses instruction timing to output them over the SDA line. Enemies are drawn along with the player at every frame update, and the player's sprite even has simulated gravity by incrementing or decrementing the register that stores its current height.

For more information on the program, check out the GitHub repo for this project and look through some of the source code.

Jumping over obstacles

After flashing the firmware to the microcontroller with the TPI protocol, its time to play. This project is a great demonstration of how just a couple simple components and a bit of clever coding can come together for an amazing miniature device.

Evan Rust
IoT, web, and embedded systems enthusiast. Contact me for product reviews or custom project requests.
Latest articles
Sponsored articles
Related articles
Get our weekly newsletter when you join Hackster.
Latest articles
Read more
Related articles