Also on Twitter https://twitter.com/ThereminHero/status/1189721638419472384

The Goal

Back in September I set out to build an LED cube made out of LED matrix panels. What I eventually ended up with is a battery powered / raspberry pi driven interactive cube, able to (among other things) play emulated NES and gameboy games while dealing with all the intricacies of wrapping a 2D game around the outside of a cube. Oh, and I threw in a lazy susan to make single player games actually playable.

The Components

6x Adafruit 64x64 P2.5 LED Matrix

1x Raspberry Pi 4

1x Adafruit LED Matrix Raspberry Pi Bonnet

6x 5v buck regulators

1x Hexapod power distribution board with built in 12V and 5V regulator

1x 4S battery

3D printed frame parts (several)

many fasteners of various sizes

The Research

I quickly found myself out of my depth on the CAD side of things. The tech specification of the LED panels, the electrical requirements, and the boards to drive everything were readily available. However, building a frame to house the panels and electronics while ensuring it was sturdy was going to become a mammoth task. I didn't want to end up in a "prototype hell" scenario... hundreds of hours of 3D prints for failed ideas. I figured some people must have been through this adventure already, and I was right.

( source: Bob Miller - https://twitter.com/kernlbob )

Enter Twitter and Github

The community of cube builders is quite small but also very willing to share their designs and CAD files. There are a few people I'd like to mention specifically who already have excellent resources (and you should check them out).

Bob Miller - https://kbob.github.io/2019/08/23/led-cubes - start here, it will give you an overview.

A Happy Teddybear - https://twitter.com/1HappyTeddybear - https://github.com/AHappyTeddy/LED-Cube-Build-Files

zaurak - https://twitter.com/zzaurak

Greg Davill - https://twitter.com/GregDavill

Piotr Esden-Tempski - https://twitter.com/esden

polyfloyd - https://github.com/polyfloyd

Henner Zeller - https://github.com/hzeller/rpi-rgb-led-matrix

I eventually settled on an absolutely incredible design by HappyTeddybear who had all the STL files available for the P2.5 64x64 panels. Seriously, this guy was the saviour of this project. Check out the genius of his design.

The Build

{gallery} Build Gallery

The frame fits together beautifully. The hinge design for the lid is a piece of practical art. The lid and adjoining frame have special indents for neodymium magnets to keep it held together, while still allowing access to the internals. There are mounting frames with specific screw holes to hold the raspberry pi and the voltage regulators.

Testing the panels

While waiting for the frames to print, I sourced the LED panels from the UK based company Pimoroni, who have been excellent at getting components to me quickly. After some hacky wiring, I got the chain of panels hooked up together and tested them out with my bench power supply. I was delighted to see they worked smoothly and at high frame rates on the Pi 4 after some software tweaks. See Adafruit's setup guide for the Bonnet - https://learn.adafruit.com/adafruit-rgb-matrix-bonnet-for-raspberry-pi/

Here is some example code showing Conway's Game Of Life spread over all 6 panels.

The First Switch-On

After several hours of screwing the frames together and wiring everything up, it was finally time to see the cube strutting its stuff. I completely fell in love with Shady, which allows you to render almost any webgl shader on the cube that can be found on sites like shadertoy.com.

First non-flickery cube video! pic.twitter.com/7fIj0wLh9u — Greig Stewart (@ThereminHero) September 10, 2019

Making it Interactive

As a display piece, the cube is excellent. But to take things further, I wanted to make it interactive in some way. I found some demos for simple games (pong, snake) but my love for old games consoles immediately made me think about running emulators. With my day-job expertise mostly focused around web tech, I naturally started hunting for a good javascript Game Boy emulator. Then I got to work getting something running on one of the panels.

The frames needed to be retrieved from chromium and read by a node.js server (both running on the pi) so they could be converted to raw data to send over GPIO. Luckily I found NCC, which can do exactly that, among other things. Eventually I tried 6 different games at once. Here it is in windows, but the environment is similar in raspbian, minus the GPIO sending part. The rpi-rgb-led-matrix node bindings take care of the rest.

This didn't work too well because of the Pi's relatively limited CPU, but is was still a fun experiment. One game preformed well, though. Next, I wanted to make something that utilised all of the sides at once in a single game. Well, four of them at least.

At this point it was well into October, and with Halloween looming I had been inspired by other projects to try something using the cube. It HAD to be Castlevania. But it had to use all sides, not just one.

Thankfully a good javascript NES emulator exists and is well documented. I figured out how to "cut out" parts of the emulated image and stitch it back onto the cube. Although this was only half the battle (foreshadowing).

For the rotation of the cube I got a cheap lazy susan on ebay and hooked up a variable voltage power supply. With 2 pedals I was able to operate it in real-time while playing the game. The next step will be to automate this with a motor driver and arduino connected to the pi.

It seemed like I had it all figured out, right?

The Scrolling Issue

Unlike games like the original Legend of Zelda, Castlevania scrolls when you move horizontally. This is a problem. The character is always in the centre of the screen and the background scrolls past. I wanted the opposite; for the background to stay in a fixed position so that Simon would be walking around the cube, not fixed in one place (i.e. de-scrolled). I knew this would make a more visually appealing result and would allow for lower frame rates to not look terrible.

The short version is... the solution was to look at the value in the PPU's scrolling register combined with data in another offset in memory to work out Simon's position relative to the level, and offset the the emulator "window" by this amount. This gives us a de-scrolled version of the game.

Hacking emulators is fun. pic.twitter.com/tobhtTsjYL — Greig Stewart (@ThereminHero) October 27, 2019

Next comes the wrapping. It's easier to show how this works rather than trying to explain it. I like to have 3 copies of the output when I'm debugging - it makes things easier to visualise.

Here's a visual clue as to how the wrapping works. It needs to be de-scrolled first though. pic.twitter.com/OgbnRcfq6X — Greig Stewart (@ThereminHero) November 1, 2019

The Journey

It has been a challenging but highly rewarding project, and this is just the start. I want to make more interesting interactive experiences using this tech. Imagine multiplayer games on multiple sides of the cube, or games that react to gravity when you tilt or shake it.

For anyone wanting to build their own cube, I say GO FOR IT. Just make sure you shop around for those LED panels. They can be a bit pricey when you need 6 of them. And good luck!

Check out my other projects on YouTube. For more info you can contact me on Twitter.