HackerBox 0112: Gamelife

by HackerBoxes in Circuits > Microcontrollers

1081 Views, 4 Favorites, 0 Comments

HackerBox 0112: Gamelife

HB0112 Whole Box.png

Welcome to HackerBox 0112. Explore artificial life and the most well known cellular automaton, Conway's Game of Life. Configure the RP2040 PiZero Development Board for development using Python with CircuitPython as well as C/C++ with the Arduino IDE. Implement the Game of Life leveraging an HDMI display output. Improve the RP2040 PiZero Development Board with the addition of two host-side I2C pull-up resistors. Implement a scrolling text display and, of course, Conway's Game of Life on the Adafruit CharliePlex 8x16 LED Matrix Bonnet. Assemble the Exclusive PicoNES pHAT to support Nintendo game controllers on the RP2040-PiZero. Install PicoNES, a Nintendo Entertainment System emulator supporting HDMI display, menu selection of SD card ROMs, and two NES controller ports. Keep up to date with the hacker community and cybersecurity policy with the DEF CON Franklin Project's first inaugural Hackers' Almanack.

There is a wealth of information for current and prospective members in the HackerBoxes FAQ. Almost all of the non-technical support emails that we receive are already answered there, so we'd really appreciate it if you can take a few minutes to read the FAQ.

Supplies

This Instructable contains information for getting started with HackerBox 0112. The full box contents are listed on the product page for HackerBox 0112 where the box is also available for purchase while supplies last. If you would like to automatically receive a HackerBox like this right in your mailbox each month, you can subscribe at HackerBoxes.com and join the party. Subscription members save at least $15 every month and automatically receive each new HackerBox shipped immediately off the production line.

A soldering iron, solder, and basic assembly tools are generally needed to work on the monthly HackerBox. A computer for running software tools is also required. Have a look at the HackerBox Workshops for tools and supplies along with a wide array of introductory activities and experiments.

The most import thing you will need is a sense of adventure, hacker spirit, patience, and curiosity. Building and experimenting with electronics, while very rewarding, can be tricky, challenging, and even frustrating at times. The goal is progress, not perfection. When you persist and enjoy the adventure, a great deal of satisfaction can be derived from this hobby. Take each step slowly, mind the details, and don't be afraid to ask for help.

WEAR SAFETY GLASSES WHEN SOLDERING, WHEN TRIMMING WIRE LEADS, OR WHEN CUTTING, DRILLING, ETC.

Artificial Life

Lenia - Artificial Life from Algorithms

Artificial Life is a field of study wherein researchers examine systems related to natural life, its processes, and its evolution, through the use of simulations with computer models, robotics, and biochemistry. Artificial Life studies the fundamental processes of living systems in artificial environments in order to gain a deeper understanding of the complex information processing that define such systems. These topics are broad, but often include evolutionary dynamics, emergent properties of collective systems, biomimicry, as well as related issues about the philosophy of the nature of life and the use of lifelike properties in artistic works. (Wikipedia)

RP2040 PiZero Development Board

RP2040Zero.png

The Waveshare RP2040-PiZero Development Board is a high-performance microcontroller board based on the Raspberry Pi RP2040 chip. It features an onboard MiniHDMI digital video interface, a microSD card slot, a PIO-USB port, and a 40PIN GPIO header similar to the Raspberry Pi 40PIN GPIO header.

The RP2040-PiZero Development Board parallels the footprint of the Raspberry Pi Zero along with a similar IO header. This makes it compatible with some, but not all, Raspberry Pi HATs or pHATs. Note that a pHAT (or partial HAT) is a smaller HAT approximately the size of the Raspberry Pi Zero. Adafruit uses the term "bonnet" for pHATs.

Initial Power Up

Plug a USB-C Cable into the USB port (not the PIO-USB port) of the RP2040-Zero. The board should power on illuminating the red pwr LED.

On the dev board, hold the boot button and hit the reset button. Your computer should now show a new "drive" called RPI-SP2.

Conway's Game of Life

Neat AI Does Conways AI Life - Allowing a neural network evolve its own patterns

Conway's Game of Life is a cellular automaton that operates on a 2D square grid. Each square (or cell) on the grid can be either alive or dead, and they evolve according to four surprisingly simple rules. The first two minutes of the video above introduces Conway's Game of Life and explains the rules of the game. The remaining six minutes present the stunning implementation of a neural network to evolve new shapes and patterns.

Back to the hardware... We will use the RP2040-PiZero Development Board and some Arduino code to implement the Game of Life and leverage an HDMI monitor or television as the display.

First, configure the Arduino IDE as presented in this Adafruit tutorial.

Note that there are three elements to the installation process:

  1. Install the Arduino IDE
  2. Configure Earle Philhower's Arduino core for RP2040
  3. Add the Adafruit Fork of the PicoDVI library

Once that is done, we can work with some Game of Life code...

  1. Grab the conway_life_DVI.ino sketch attached below
  2. Select Tools > Board > Raspberry Pi Pico/RP2040 > Waveshare RP2040 PiZero
  3. Select Tools > Port > UF2_Board
  4. On the RP2040-PiZero board, hold the boot button and hit the reset button
  5. Compile the sketch and upload to the RP2040-PiZero
  6. Connect the MiniHDMI output from the RP2040-PiZero to a television or monitor

The sketch initializes the cellular grid with fifty gliders. As explained on that Wikipedia page, the glider is a meaningful emblem within the hacker subculture. The Game of Life appeals to hackers with the concept of the glider born around the same time as the Internet and Unix. The emblem can be seen in various contexts associated with hackers.

To initialize the cellular grid, each glider is drawn to a pseudorandom location of the grid when setup() calls init_multi_glider(50). Change the commented lines in setup() to instead call init_random() if you'd like to test a random grid initialization.

Exercises to Explore

Rotation: All gliders are currently initialized in the same orientation. Add a third parameter to the function init_glider(int x, int y) for rotation. Use the passed rotation value (e.g.: 0, 1, 2, or 3) to specify which of the four rotational orientations to use when drawing the glider.

Patterns: Add additional functions to initialize other know patterns (such as spaceships or guns) into the cellular grid. While the glider is small enough that we simply drawn it into the grid pixel-by-pixel, it might make more sense for larger structures to be specified in your code as a kernel matrix that is copied into the grid as desired. For example, reference the lightweight spaceship Python implementation for the LED Matrix presented in a later step. This matrix representation is similar to the Plaintext pattern format.

Run Length Encoding: Add initialization patterns specified in RLE (run length encoding). Note that the Life objects found in the Hatsya Catagolue are encoded in RLE.

User Interface: Add control of initial conditions or other aspects of the simulation. Perhaps using an NES controller?

Higher Resolution Mission 1: The example code stores the cellular grid using two 320x240 matrices of bytes. The curr[][] matrix stores the (curr)ent generation while the next[][] matrix is a working space for building the next generation. The 320x240 matrix is pixel doubled to 640x480 whenever it is drawn to the screen. Change the two matrices to 640x480 to get four times as many cells. Not so fast! 2*640*480 bytes will not fit in memory. However, each cell only needs one bit (0 or 1) not a whole byte. You will need to implement a bit-packing abstraction to reduce the storage requirements by eight-fold, so watch this video tutorial on bitwise operators. Note that these bitwise operations work pretty much the same in Python and in Arduino/C/C++. Packing and unpacking the bits takes processor time, but much less memory. This is a simple example of a time-space tradeoff.

Higher Resolution Mission 2: PicoDVI running on the RP2040 chip can even render 800x480, but this requires tricks like overclocking, slowing flash accesses, or over-volting. Interesting, there have been some announcements just this month about clock boosting the RP2040. Be aggressive!

Implement Life on your PC: Work along with this Tech with Tim Video to code the Game of Life in Python using Pygame in less than one hour.

Add I2C Host-Side Pull-Up Resistors

I2C Pullups.png

Why add I2C pull-up resistors to the RP2040-PiZero Development Board?

Exploring the Raspberry Pi online documentation for the schematic diagrams of the Raspberry Pi Zero (and Zero W) will show the SoC connection portion copied into the image above. We are highlighting this particular portion of the schematic to illustrate that the Raspberry Pi Zero (and Zero W) include 1.8K Ohm pull-up resistors on the GPIO2 and GPIO3 pins. These are "host-side" I2C pull-up resistors discussed here.

Unfortunately, the RP2040-PiZero Development Board does not incorporate these pull-ups resistors. This presents a problem when using HATs that employ I2C interfaces since these generally assume the presence of host-side pull-up resistors. The LED pHAT that we will be working with next is an example of one that expects there to be host-side pull-up resistors.

This problem is easily remedied by placing two pull-up resistors resistors (along with a small connecting wire) onto the bottom-side of the RP2040-PiZero Development Board as shown in the image.

Two 1.8K Ohm SMD-1206 Resistors (marked "182")

Solder one terminal of a surface-mount 1.8K Ohm resistor onto both the GP2 and GP3 pins as shown in the left image.

One Axial Wire Lead Resistor

This resistor is only used to provide a nice, solid wire lead, so it doesn't matter what value the actual resistor is. Solder the wire lead of the axial resistor across the two SMD resistors terminals that are opposite from those SMD terminals soldered to the GPIO pins. Leave the axial resistor extending over the edge of the board while soldering and then snip the resistor off to leave only a wire as shown in the image on the left. Discard the axial resistor portion that was snipped off.

Connect the Pull-Up Resistors to 3.3V

As shown in the image on the right, bend the wire lead around to the 3V3 pin, snip it to length, and solder the wire onto the 3V3 pin.

Circuit Python - Adafruit LED Matrix Bonnet

LED Bonnet.png

The Adafruit CharliePlex LED Matrix Bonnet featured in HackerBox 0112 presents an 8x16 matrix of Blue LEDs. If you would like different color LEDs, another blue matrix, or any number of other amazing electronic gizmos, Adafruit is your place to go!

The 8x16 LED Matrix Bonnet can be plugged onto the RP2040-PiZero Development Board - or atop any Raspberry Pi computer with a 2x20 connector. It features a beautiful, bright grid of 128 charlieplexed LEDs driven by an IS31FL3731 (datasheet) driver chip. The driver is controlled over I2C, so only two pins are required to set 8-bit (256 level) dimming on each of 128 LEDs. The driver chip I2C interface is mapped onto two GPIO pins of the RP2040-PiZero Development Board header...

GPIO2 = SDA
GPIO3 = SCL


Configure the RP2040-PiZero for use with CircuitPython

Browse here to download the UF2 file for the latest stable release of CircuitPython.

On the dev board, hold the boot button and hit the reset button.

Your computer should now show a new "drive" called RPI-SP2.

Copy the UF2 file to that new drive.

The drive will disconnect and reconnect as CIRCUITPY.

Display Scrolling Text on the 8x16 LED Matrix Bonnet

Download this Adafruit zip bundle.

Unzip it on your computer.

Navigate into CircuitPython 9.x folder - and then into the lib folder.

Copy all the files from the lib folder.

Paste them into the lib folder on the CIRCUITPY storage device.

Grab the file font5x8.bin from this repo.

Paste the font5x8.bin file into the root folder on the CIRCUITPY storage device.

Adafruit wisely suggests Installing the Mu Editor.

Using Mu, or another text editor, open the file code.py in the root director of the CIRCUITPY storage device.

Grab the file scrolling_text.py attached below.

Copy and paste the code from scrolling_text.py into code.py

Save the updated code.py file in CIRCUITPY to execute of the code.

A text message will scroll across the 8x16 LED Matrix Bonnet.

Conway's Game of Life on the 8x16 LED Matrix Bonnet

Using Mu, or another text editor, open the file code.py in the root director of the CIRCUITPY storage device

Grab the file conways_life_8x16.py attached below.

Copy and paste the code from conways_life_8x16.py into code.py

Save the updated code.py file in CIRCUITPY to execute of the code.

Life should emerge across the 8x16 LED Matrix Bonnet.

PicoNES PHAT Kit

Pico NES pHat.png

All of this cellular automata talk is very interesting, but as Joshua so kindly asked, "Shall We Play A Game?"

The PicoNES pHAT will allow us to connect game controllers to the RP2040-PiZero Development Board.

  1. Check out the Exclusive PicoNES pHAT PCB.
  2. The two NES game controller sockets go on the side of the PCB with the silkscreen.
  3. The female 2x20 Raspberry Pi header goes on the other side of the PCB.
  4. Solder time!

Pico NES

Pico NES Breadboard.png

The Nintendo Entertainment System (NES) was an 8-bit home video game console produced by Nintendo. It was first released in Japan in July 1983 as the Family Computer (Famicom). The NES is regarded as one of the most influential game consoles. It pioneered the now-standard business model of licensing third-party developers to produce and distribute games. The NES features several influential games, including Super Mario Bros. (1985), The Legend of Zelda (1986), Metroid (1986) and Mega Man (1987), which became major franchises. (Wikipedia)

Frank Hoedemakers’ pico-infonesPlus project implements an NES emulator with SD card storage and menu support on the RP2040. It employs HDMI for display and supports two controllers for two player games. Truly a masterwork of combined resources: Jay Kumogata’s InfoNES was ported to RP2040 by Shuichi Takano using Luke Wren’s PicoDVI library, Hoedemakers developed an SD card menu, and controller code from Adafruit was incorporated.

Install Pico NES for RP2040-PiZero Development Board + PicoNES PHAT

  1. Browse over to Frank Hoedemakers’ pico-infonesPlus repository
  2. Click on the releases page
  3. Download the file pico_piconesPlusWsRP2040PiZero.uf2
  4. Connect your PC to the RP2040-PiZero USB port (not PIO-USB)
  5. On the board, push and hold the BOOT button, then press RUN
  6. Release the buttons and the "drive" RPI-RP2 will appear on your computer
  7. Drag and drop the PicoNES UF2 file onto the RPI-RP2 drive
  8. FAT32 format a MicroSD card
  9. Fill it with ".nes" ROMs (that you legally own)
  10. The ROMs can be organized into different folders

DEF CON Franklin Project

Franklin.png

The DEF CON Franklin Project was created to infuse research from the hacker community into national security and foreign policy debates. It aims to lift up groundbreaking work from DEF CON participants and villages and deliver this critical research to key policymakers across the globe. Furthermore, Franklin will enhance DEF CON community impact to actively promote democracy, justice, and human rights.

On February 6, 2025, the DEF CON Franklin Project released the First Inaugural Hackers' Almanack. Download it for an easily digestible compendium of remarkable research from DEF CON 32.

One Node at a Time

Splendor of Color Kaleidoscope Video v1.3 Up-Scaled to 4K60p Using Video AI w/ Cool Meditation Music

We hope you are enjoying this month's HackerBox adventures into electronics, computer technology, and hacker culture. We aim to curate a challenging and rewarding experience of learning through experimentation and exploration. Thank you for joining us on this journey.

Reach out and share your success in the comments below. Email support@hackerboxes.com anytime with questions or whenever you need some help.

Hungry for more? Surf over to HackerBoxes.com and join us as a monthly HackerBox subscription member. You'll get a cool box of hackable gear delivered right to your mailbox every month and you'll enjoy a generous member discount.

Please consider sharing this free Instructable with others who may be interested in learning about these subjects. Word of mouth advertising is the greatest compliment that we can receive. We sincerely appreciate your support.