IRL Chrome T-Rex Game Powered By Raspberry Pi Zero
In all started in one weekend. My life-partner Ariella and I went to GeekCon, a weekend hackathon devoted to building useless (but nevertheless super-cool) maker projects.
We had an ambitious goal: we wanted to build Chrome's infamous no-internet dinosaur game, but in real-life. We spent the weekend building a prototype with Arduino and some parts that we ordered in advance (such as PCB for the T-Rex):
Eventually, by the end of the weekend, we had a semi-working prototype. It wasn't very reliable, the cacti wouldn't go back to the beginning of the track, and it was trust based - the game had no way to detect if you hit a cactus. Nevertheless, the children who attended the GeekCon faire event at the end of that weekend loved it:
I'm Going to The Chrome Dev Summit! ?
The prototype was fun to play and motivated me to keep working on that project. We shared the video with the organizers of the annual Chrome developer event, the Chrome Dev Summit, and they invited us to present the game in the event that year. Exciting!
We had about one month to the event, and I spent all my free time improving the hardware: replacing the cheap DC motors with stepper motors, revamping the jump mechanism, creating a loop so the cacti would automatically go back to the start of the track, making the button wireless, and so on.
You can read all the gory details of how I revised every single part in the project, and also learn how I programmed the game using the JavaScript language.
I packed the project in the suitcase and prayed it will make it through the longer journey to San Francisco. I spent the last night before the summit hacking the high score system and improving the jump mechanism, and eventually the game was ready (more or less) for the big day:
The game was played nearly thousand times, and one of the determined attendees made a high score of 129 points!
Living Room Clock ⌚
When I got home, I put the project for display in the living room. A few week later I found a way to make it actually useful - I added an hardware RTC module (which keeps track of the time), and turned the game into a decorative clock:
Over the time, some of the components started to fail. I used a bread-board power supply module with 5V and 3.3V regulators, but at some point they both died and I had to add external regulators. Adding these, as well as the RTC module made the board really crowded. It was a big wire mess:
Another issue was daylight saving time. The board was powered by an nRF52832 microcontroller, which only had Bluetooth connectivity, so it could not connect directly to the internet and update the time. I had to manually connect to it and set the time every 6 months. It'd also start drifting...
Raspberry Pi Zero To The Rescue ?
At this point, I decided to revise the electronics, replacing the nRF52832 microcontroller with a Raspberry Pi Zero-W that would control the game.
The Pi Zero connected to my local WiFi network, so I can easily SSH there and tinker with the code. It also updates the time automatically from the internet. Lovely!
It was also a good opportunity to try and solve the breadboard wire mess and learn how to create a hat for Raspberry Pi (which I have never done before). I created a spreadsheet listing all the hardware parts and their required connections, and designed the PCB in KiCad (using this great template).
A few weeks later, the PCBs for the T-Rex Pi-Zero uHat arrived:
I started assembling the components. I had to drill larger holes for the power connector, as I used the wrong footprint ?♂️
And then, installed it on top of the Pi Zero:
And installed it in the project:
I was very happy to find out all the hardware worked like a charm. As the original game (and clock) code was written in JavaScript, I could adapt it to run on the Pi in just a few hours. I used the excellent johhny-five library on top of Node.js.
The only thing proved difficult was controlling the stepper motor drivers accurately. I eventually managed to work out accurately timed signal on the Pi using the pigpiod library (and even sent them some pull-requests in the process), but that deserves a separate blog post.
Hooray! My T-Rex game has got a new brain, and I no longer have to manually update the clock every time.
Source Code, Behind The Scenes, and More
You can find the source code and all the design files for the project on GitHub:
Check out this short video to see how the hardware works (showing the original game brain):
If you liked this project, be sure to check out our 2018 GeekCon project: A robot that plays the trumpet. Just like its predecessor, it was also chosen to present at the Chrome Dev Summit.
What's next for the Pi-powered IRL T-Rex project?
I could add alarm clock functions, or perhaps connect it to my Google Home, so that you could start the game and even play using your voice. Or perhaps add some alarm-clock functionality. Or show the weather forecast on the E-paper display. Who knows?