Skip to main content

Conway's Game of Life on NodeMCU (+ AMOLED)

Conway's Game of Life running on the NodeMCU.
One of my favorite programming assignments during school was to write a version of Conway's Game of Life in Python. At the time I was far more concerned with getting things working than I was with writing clean and efficient code, which only served to complicate my efforts to debug wonky behavior. I especially remember my struggle to accurately count the number of neighbors for a cell on the edge of the board. (My solution, if I remember correctly, was to add a hidden single-cell border to the board that didn't have any logic performed on it.)

In researching what others have built using a NodeMCU/ESP8266 and "128x64 I2C AMOLED" boards, I came across a pong clock written in Lua. Unfortunately, I haven't had much luck with Lua on the ESP8266 chip, so I was unable to flash the code onto one of my spare boards. Would it be possible to implement something similar using Arduino on the NodeMCU, though? To find out, I decided to test my ability to use the SSD1306 display control library and APIs for Arduino, by rewriting Conway's Game of Life.

The random visualization running with each cell represented as an 8x8 pixel square.

To start, I decided to whip together a random visualization. Every cell is randomly assigned an on/off value, the display shows the cells, and then the next grid replaces it on the display after a set amount of time. Easier said than done- I ran into a low memory situation and my board kept resetting itself. The solution I took was to simply scale up the size of the cells. Instead of each cell being 1 pixel, each cell became 4 pixels. A welcome side effect of this change was a much more striking visual that took on the appearance of a "living" QR code.

With that first test done, I got to it and wrote an Arduino sketch for Conway's Game of Life, which you can see running in the picture up above. Seeing how the board is likely to become stagnant after a while, it is reseeded after a pre-set number of cycles to ensure that things stay interesting.

Once I'm back home with access to my boards, I hope to finally write Pong. Till then there are a number of hardware competitions I've entered that I'll be working on.