Raspberry Pi 4x4x4 LED Cube


I’ve been fascinated with LED cubes for a while now, but haven’t been able to bring myself to build an Arduino-based cube. They turn on quickly and nicely, yes, but writing the code is a horrible mess of bits and bytes. The Raspberry Pi’s Python-based GPIO interface was much more appealing (and readable) to me, so I decided to build an LED cube that was based off a Raspberry Pi. An 8x8x8 cube was way too big for an entry-level LED cube project, so I went with a 4x4x4 cube instead.

If you’ve got a Raspberry Pi and 60-ish LEDs lying around, then maybe this is the project for you. It’s smaller and easier than an 8x8x8 cube, but is still large enough to display some cool animations. The Raspberry Pi also allows parallel threading, which makes writing animations much more direct (more on this later).

I was inspired to build this by chr’s 4x4x4 LED cube. It uses an Atmel ATMega as its controller, so it’s harder to code but faster to boot.

This project uses a Cartesian coordinate system, both in this Instructable and in code, to refer to LEDs on the LED cube. If you don’t know what that is or how to use it, I’d suggest reading about it before attempting this project.

EDIT: If you liked this project, feel free to vote for me in the Epilog VII contest, I’d definitely appreciate it!

WARNING! This project makes extensive use of soldering, so you must be somewhat skilled at soldering to complete this project. In addition, soldering involves the use of a VERY HOT tool which can cause burns. Should you attempt this project, you assume all inherent risks of injury from soldering. Be careful and use common sense!Raspberry Pi 4x4x4 LED Cube

Step 1: Materials – Parts

To build this 4x4x4 LED cube you will need:

  • 1x Raspberry Pi (I used a Model B, but a B+ or 2 will work as well)
  • 64x 3mm LEDs, any color (I ordered a 100 pack, this leaves plenty for mistakes)
  • 16x 200 ohm 1/4W resistors (make sure you order low-wattage resistors, I accidently bought 5W resistors once! Try prototyping with those!)
  • 2x 74HC595 shift register ICs
  • 2x 16-pin IC sockets
  • 4x C9014 transistors (or any other NPN transistor)
  • 1x 26-pin female ribbon cable socket
  • 1x 26-pin Raspberry Pi breakout ribbon cable (or a downgrade cable from B+ or 2)
  • 2x 20-pin female ribbon cable sockets
  • 1x 20-pin ribbon cable
  • 1x Adafruit Half-Breadboard Perma-Protoboard
  • 1x Adafruit Full Breadboard w/ Raspberry Pi Breakout Perma-Protoboard
  • 1x enclosure with plastic top and bottom (I got mine from OKW Enclosures, design E in their Synergy series)
  • Some solid-core wire
  • Some wire

Make sure that when buying ribbon cables and sockets they have a pin spacing of 0.1″. I accidentally bought some strange, non-standard ribbon cables that didn’t fit my sockets. Spare yourself this trouble, and make sure to buy the right cable in the beginning!

Step 2: Materials – Tools

To build this 4x4x4 LED cube you will need:

  • 1x pair of safety glasses
  • 1x drill press (a hand drill will also work, but a drill press is easier)
  • 1x 1/8″ drill bit (or 7/32″ for 5mm LEDs)
  • 1x 5/64″ drill bit
  • 1x Dremel with a rotary cutting head
  • 1x set of soldering equipment (the iron must be no hotter than 40W)
  • 1x hot glue gun
  • 1x T10 star head screwdriver or wrench (for assembling the OKW enclosure)
  • 1x pair of pliers
  • 1x pair of wire cutters/strippers
  • 1x pair of tweezers
  • 1x perfectly square piece of wood that’s big enough to fit an LED cube
  • 1x square + ruler
  • 1x pencil
  • 1x center punch or prick punch
  • 1x multimeter
  • 2x AA batteries in series, for testing LEDs at 3V
  • 3x 9V batteries (or something about that size) for layer spacers
  • Some way to get code onto the Raspberry Pi (e.g. Raspberry Pi Internet connection, flash drive transfer from computer)

Step 3: What’s an LED Cube?

So glad you asked! An LED cube is a three-dimensional display made by soldering LEDs into a cube shape. The LED cube you’ll be making if you follow this Instructable is a 4x4x4 cube, which means each layer of the cube is 4 LEDs long and 4 wide, giving 4×4=16 LEDs per layer, four layers give 16×4=64 LEDs for a 4x4x4 LED cube.

As you’ve probably noticed, the number of LEDs needed increases very quickly, so an 8x8x8 cube would need 512 LEDs, a 16x16x16 cube would need 4096 LEDs, and a 32x32x32 cube would need 32,768 LEDs!

When building an LED cube, not only must the size be considered, but the size of the LEDs must be considered as well. The 74HC595 chips I used can’t source enough current to fully drive a 5mm LED, so I decided to use a lower-power 3mm LED. Keep power consumption in mind when choosing your LEDs. Also, the Raspberry Pi Model B I used can only safely source 50mA from the GPIO pins, which is another limiting factor.

The final factor that must be considered is voxel density. A voxel is a point in three-dimensional space, as opposed to a pixel, which is a point in two-dimensional space. Higher definition in a display requires more pixels/voxels per square/cubic unit, or a higher density. When designing an LED cube, the spacing of the LEDs must be balanced with the definition of the cube. A higher density results in a better defined image, but makes it harder to see through the cube and somewhat defeats the purpose of a 3D display.

Step 4: Multiplexing

If one were to simply drive each of the 64 LEDs individually, a very big microcontroller would be needed. To cut down on the number of control pins necessary to run this cube, all of the positive (V+) leads of the LEDs are soldered together in columns, while all of the negative (GND) leads are soldered together in layers. To light an LED, the microcontroller turns on the layer and column that LED is part of. To light an LED at (0, 0, 0), layer 0 and column 0 would be enabled.

This setup allows the LED cube to be driven by 20 pins instead of 64, which is a much more reasonable number of pins. Unfortunately, if one wants to light multiple LEDs on multiple layers, this setup causes extra LEDs to light up too, which is called ghosting. To counter this effect, we use something called multiplexing. To multiplex, we light each layer of the LED cube up one at a time, cycling through them so that only one layer is visible at a time. If this cycling is done fast enough, the human eye will be unable to keep up and it will appear as though the entire cube is on at the same time. This phenomenon is known as persistence of vision.

Check out this video by chrmoe for a more visual demonstration of multiplexing and persistence of vision.

Step 5: Make a Template

Soldering 64 LEDs together is very hard freehand, so let’s make it easier and make a quick layer template! Grab a single LED and fold its GND lead out at a 90° angle and measure its length. My lead was about 23mm, so subtracting 1mm for a soldering overlap gave me a distance of 22mm between each LED.

Use a pencil to mark where the first corner LED will be, then use a square and a ruler to draw straight lines out from this point. Next mark out three more points along each line, spacing them an LED lead’s length (for me, 22mm) apart. Draw straight lines out from these points, and repeat the process until you have sixteen points all spaced an LED lead’s length from each other. Look over your work with a critical eye–it’s much easier to redraw pencil lines than to try and fix mistakes while soldering!

Next, center punch all sixteen holes and drill them out, using a 1/8″ drill bit for 3mm LEDs, and a 7/32″ drill bit for 5mm LEDs. A hand drill can be used, but if you have access to one, a drill press is much easier to use. After you’ve drilled your holes, an LED should be able to fit snugly inside each hole. This template will hold the LEDs steady for you, which makes soldering much easier. Once you’re done drilling and testing, your template is done and you can move on to soldering.

Step 6: Solder the LEDs Together

While your soldering iron is heating up, you’ll want to test your LEDs and make sure all 64 of them work, lest they end up soldered in the cube. I ended up with a couple that were already burned out, but buying a hundred-pack of LEDs ensured plenty of extra LEDs. I used two AA batteries in series to get 3V, which is about the voltage of the Raspberry Pi’s GPIO pins. Once you have 64 working LEDs, bend the GND leads for each of them out at a 90° angle. These leads will be soldered together to form the cube layers.

When soldering LEDs, one must be careful not to take too long, otherwise the LEDs will overheat and burn out. Lower wattage soldering irons will have a lower chance of burning LEDs up, so I recommend a 15W iron. I found that a 40W iron was just low enough to be able to solder without destroying everything, but anything above that will probably do more damage than soldering.

See the above pictures+notes for a visual guide on how to solder the LEDs together. When done, each layer should have one wire sticking out of its corner; this will become important later on, so make sure each layer has this wire coming out of the same corner. Check all the LEDs with your AA batteries; it’s much easier to replace an LED now than when the entire cube is constructed.

Step 7: Solder the Layers Together

Now it’s time to assemble your LED cube layers. Select the nicest-looking layer and replace it in the jig; this will become the top layer of your LED cube. Bend all sixteen of the LED leads slightly in the same direction, to help the V+ leads line up better and make soldering easier.

Place some 9V batteries on top of the LED GND leads, to act as spacers to help keep the LED cube more uniform. Solder all sixteen columns together, test your LEDs, and repeat until your entire cube is constructed. You can now move on to attaching the resistors.

Step 8: Attach the Resistors

To prevent the LEDs from burning out, resistors must be attached to each column. I found that it’s easiest to solder the resistors directly onto the LED cube, then hide them inside the enclosure. Grab a resistor, then use an alligator clip to clamp it in place next to a column. Even if there’s a slight gap, the solder will flow easily between the column and the resistor lead. Test the LED directly next to the resistor, then repeat for the remaining fifteen columns.

The next step is to modify the GND leads so the LEDs can be properly powered.

Step 9: Lengthen the GND Leads

Although it is possible to simply run wire up to the LED cube layers, doing that doesn’t yield as nice a finished product. Instead, I soldered solid-core wires to the layers of my LED cube in a low-profile fashion.

Remember the LED leads that you left sticking out from each layer? Bend those wires 90° so that they are parallel with the cube face. Next, you will bend the leads 90° down so they are parallel with the columns, but wait a moment before doing so. When you bend the leads, align them so they would be about 1/8″ apart from each other if they were longer. These wires must reach the control circuitry without touching each other, so make sure you leave enough space between wires.

Finally, solder lengths of straight solid-core wire to each bent lead, making sure the wires end up reaching to about the same height as the resistor leads. Once that’s done, your LED cube is complete. Keep your soldering iron plugged in, though, because the next step is to solder together the control circuit. However, first it’s time for another bit of education.

Step 10: What is a Shift Register?

Even though a Raspberry Pi is the real brain of this LED cube, we still need a control circuit as an intermediary between the Pi and the cube. Since the Raspberry Pi Model B only has 14 signal GPIO pins and the LED cube needs 20 signal pins to be controlled, some electronic magic is required. This is where the shift register ICs come in.

A shift register is an IC that “shifts” in serial data (a series of bits, such as 100101101) and outputs it as parallel signals. For example, if the Raspberry Pi sends a byte-long signal (1 piece of data that’s 8 bits long) into the shift register, it converts it into 8 parallel signals (8 pieces of data that are 1 bit long each) and uses those signals to directly power the LEDs.

Since this LED cube needs 16 data bits, we’ll be using two shift registers and two data wires to control the cube. Add in four pins to control the layers and four more pins to control the shift registers, and the 20 pins needed to drive the LED cube have shrunk down to ten, leaving you with four extra pins for other attachments! Not bad for just two ICs.

Of course, if you have a Raspberry Pi Model B+/A+/2 you could bypass the shift registers and directly control the LEDs, since B+/A+/2 have more (14 more, I think) GPIO pins. However, I am assuming you have a Model B/A Raspberry Pi, for the sake of compatibility.

Step 11: Solder the Control Circuit

This step is pretty complicated, so be very careful with your soldering. Consult the Fritzing schematic above for wiring instructions. If you’ve been following this Instructable exactly, you’ll be soldering your components to a breadboard-layout PCB, which means you can follow the Fritzing schematic directly. The Fritzing file is also attached to this step, if you’d like to download it and look at it on your computer (perform a connection direction inspection!). Make sure to solder IC sockets instead of the actual ICs; if something were to go wrong it’s much harder to remove ICs from a PCB than a socket.

The trickiest part of this step is soldering the ribbon cable sockets. When soldering the 26-pin socket, make sure it goes into the Raspberry Pi socket section of the protoboard, with the large-ish notch facing right. Soldering the 20-pin socket is even trickier, though, because there is no easy place to solder it in.

Here’s my method for soldering the 20-pin socket. Refer to the above pictures for details:

  1. Solder 10 wires across the breadboard, to create 10 completely connected rows
  2. Solder the socket in next to the 10 wires, making sure the large-ish notch is facing left
  3. Using an X-Acto or other craft knife, cut the traces between the socket’s two columns
  4. Use a multimeter to test for discontinuity between both sides of the board. Every pin of the socket should be discontinuous from the other pinshttp://www.instructables.com/id/HACCSY-Hackerspace-Access-Control-and-Check-in-Sys/?ALLSTEPS

Step 12: Solder the LED Cube Breakout Board

Tired of soldering yet?

Now that you have the control circuit built, it’s time to prep the LED cube breakout board. Eventually all the resistors and such will connect to this board, but not quite yet. Solder 10 wires across the bottom 10 rows, in a similar manner to what you did with the control board. Then solder in your second 20-pin socket, but this time make the large-ish notch face right from the bottom.

Cut traces between the two socket columns, then test for discontinuity with a multimeter. At this point if you were to connect the 20-pin ribbon cable to both boards, the connections on the sockets should mirror one another, i.e. pin 1 on the control board and pin 1 on the breakout board should be continuous, and so on. Once that’s done, you can (finally) unplug your soldering iron for a while, and move on to preparing the enclosure.

Step 13: Drill a Bunch of Holes in a Metal and Plastic Box

The title says it all, I guess. To give this LED cube a more professional look, I ordered an enclosure from OKW Enclosures. The enclosure came with a nice plastic lid, but in order to use it with our LED cube, it needs a bit of modification.

If the holes don’t line up with the LED cube leads they won’t work, so grab your wooden template and set a piece of paper over it. Use a pencil to punch out the sixteen holes, then align the paper on your enclosure lid and make a pencil mark at each hole. You now have sixteen marks that should be aligned in the same manner as the LED cube itself.

Take your marked lid and use a center punch to create “guide divots” for your drill. This will help keep the drill bit from wandering and increase accuracy. I found that 1/4W resistors just barely fit inside 1/8″ holes, but if you use a lower-power resistor, you could go with a smaller hole. Whatever size you use, drill out all sixteen holes, then set your LED cube on top of the lid.

If you drilled and marked accurately, the leads should be very close to fitting in the holes, however, don’t fit the LED cube into the lid yet. Instead, mark about where the extended layer leads touch the lid. These four points will be where your GND leads go. Since these holes only have wires, not resistors, running through them, you can use a smaller drill bit. I used a 5/64″ bit, which left me a little bit of space around the wires.

Once these final four holes are drilled, you can now insert your LED cube into the lid. I found that the best method was to insert the back four wires with the cube at an angle, then the next four wires, and so on until all the wires are in their holes and the cube is straight.

 

 

For more detail: Raspberry Pi 4x4x4 LED Cube


© 2015 Powered By Engineering Projects Team, Raspberry Pi Projects

Scroll to top