Game of Life Desk Toy
Game of Life on a tiny OLED display


John Conway's Game of Life has interested me since I first heard about it. Complex behaviors derived from simple rules and the "gameplay" that emerges from those rules is very fascinating. I've had these 1" OLED screens sitting in my parts drawer for a while and decided making a Game of Life desk toy would be a fun project. It was also an excuse to use these big buttons that I bought which are very satisfying to press. It runs on a ESP-01 module and is powered by USB.
Conway's Game of Life
Once the game logic was sorted, I implemented the OLED display. There are a number of libraries for driving these displays but I found that the U8g2lib library was the fastest and very simple to code. I also implemented a push button with the EasyButton library to turn the display on or off, reset the game or display game stats on the bottom of the screen.
Separating out the code solved the watchdog issue.


The first step was getting GoL running on the ESP module. The ESP is compatible with the Arduino IDE so I went on GitHub and found a repo of someone that already implemented GoL for the Arduino. I adapted the code to work on the ESP but kept getting watchdog errors. Through trial and error and much Googling, I discovered that the ESP has a watchdog that resets the MCU if a loop goes too long without exiting.
This isn't a problem for small game worlds, but for the relatively large 128x64 resolution of my display the watchdog kept barking. I ended up rewriting most of the code so that no sub-routine spent too long without returning to the main loop. For testing, I used the serial console to display the game using X for living cells and . for dead cells.


Everything connected on a breadboard.




Finally, I designed an enclosure in Fusion 360 to hold everything and printed it out on my 3D printer. I went through a number of prototypes so that the display would sit perfectly in the frame. The case is just big enough to contain the MCU, push button and a regulator to convert the 5V from USB to the 3.3V the ESP requires. I had to solder some connections while everything was inside and I managed to get everything connected with only slight damage to case. You can see the little carrier I made with a scrap of perfboard and header sockets. I wanted the ESP to be removable in case I wanted to update the code. I also made a little holder so it would sit nicely on my desk-mounted power strip. There's something wistful about a little MCU, dutifully doing thousands of calculations a second, just so I can have something that looks nice on my desk. It makes me pensive to look at sometimes.


Everything stuffed inside. Securing the nut was quite tricky.


The USB cable came from an old laptop mouse. Very thin and flexible.
Checkout the code on my GitHub page.
GoL running in the serial console with stats at the top.
Any live cell with fewer than two live neighbours dies, as if by underpopulation.
Any live cell with two or three live neighbours lives on to the next generation.
Any live cell with more than three live neighbours dies, as if by overpopulation.
Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
The rules of Life.