Even if you don't own a 3D printer, this might still be the best way to make an LED cube! Getting 3D parts made is fairly easy and inexpensive. There are many on-line sources.
I've built a bunch of LED cubes. They are tedious to build, so I am always looking for ways to make it a little easier. In previous tutorials, I have tried to get away from circuit boards full of shift registers, but even then, the actual construction of the cube is hard and time consuming.
So in this project, I am trying some new approaches - first using a 3D printed construction template, and second, using SPI port expanders right at the point where they are needed to keep wiring to a minimum. And while we are at it, let's use the 3D printer to make a nice baseplate and case for our finished LED cube.
I don't know if the techniques presented here are the ultimate best way to build a cube. But I do think these are some interesting alternatives that result in a high quality cube which has good performance without an excessive amount of time, effort and money.
First, let's talk about the construction template. There are two schools of thought when it comes to building LED cubes. One says build layers first and then assemble them into a cube. Building your cube one layer at a time lends itself to using templates, makes beautiful cubes, but is a beast to assemble with 64 vertical connections (for an 8x8x8 cube) between each layer. The other says build vertical panels and assemble them into a cube. Building vertical panels is somewhat harder than building layers and doesn't lend itself as well to templates, but when they are done, they are much easier to assemble into a cube. It seems like we could have the best of both, if we could build a nice template for a vertical panel - that's where the 3D printer comes in. In this tutorial, I have provided a 8x8 vertical panel template.
What you see in the photo above are places for 64 LEDs to be inserted. The square depressions are where the vertical leads (which go downward in this photo are soldered together. These depressions are simply to keep the soldering from melting the plastic (most of the time).
This template is for 3mm LEDs. I have used 5 mm LEDs in the past, but they work best when placed 1-2 inches apart. That makes for a big cube which is best viewed from across the room. And big cubes are hard to store, so I now prefer smaller cubes built with 3 mm LEDs. 3 mm LEDs require a jig to lead form, but again, the 3D printer can take care of that - I have provided one. One other minor thing I like about 3 mm LEDs - for a limited amount of time and current (both of which are always limited in cube design), 3mm LEDs with their smaller chip are a little brighter then their equivalent 5mm LED.
Now let's talk about SPI port expanders. They serve the same function as shift registers. They generate lots of extra ports from which to turn LEDs on and off. Why do I like them better than shift registers? You can buy them on their own little circuit board for $2 and they give you 16 IO pins. Place them strategically under your cube and four of these little boards provide the 64 ports that shift registers would normally provide for an 8x8x8 cube! And that is without the need for a circuit board and a lot of external components.
The drawing above shows the bottom view of the board or baseplate that we mount our cube on. It illustrates the concept of using SPI port expanders in place of shift registers - fours boards could provide the 64 vertical column drivers. We show here how one of these port expanders provides the connection to 16 vertical columns or 1/4the of our cube.
Not shown in the drawing above is the connections to the different layers of the cube. Those layer selectors are 8 regular digital output pins on our processor which drive transistors. The transistors are NPNs and are needed because a layer could potentially be lighting up all 64 LEDs contained in that layer - a lot more current than we could sink through the digital pins themselves. We'll talk more about all this later.
A reasonable question might be: Are SPI port expanders fast enough to control a cube instead of shift registers? The MCP23S17 chip used for these port expanders has what is called "WORD" mode, where all 16 IO pins can be configured with a single SPI command. It is somewhat like using "direct port access" to program shift registers. We can configure all 64 ports for a 8x8x8 cube in well under 100 microseconds - plenty fast enough for our cube and to compete with shift registers. (By the way, port expanders also come in a I2C version, but as far as I can tell, they are way too slow to work for controlling a cube!)
So in this tutorial, we are going to build an 8x8x8 cube using vertical panels built on a 3D printed template. At the base of our cube, we are going to use four 16 channel SPI port expanders wired directly to our cube's 64 vertical anode columns through 180 ohm current limiting resistors. With the use of the port expanders, we can control our cube with almost any microcontroller, so we are using an Arduino Nano.
Here is our 5 minute show for this cube:
Construction3D Printing
First a note on 3D printed parts. The STL files for all four 3D printed components (template, lead-form jig, baseplate and case) are included in this tutorial for download.
I was concerned in the beginning about whether these 3D prints would last long enough to build a whole cube. The lead forming jig was just made from PLA but easily lasted to bend 512 LED leads. The panel template would best be made out of ABS because it is exposed to soldering. However, I made mine from PETG, which is as easy to print as PLA, but handles high temperature a little better. It lasted through building 8 panels (and I suspect PLA would have worked as well), but did look a little beat up by the end - lots of little places where it got touched by a soldering iron. The baseplate and case can be printed from PLA - no heat or anything else to worry about on these pieces.
Lead Form
Building a cube can be quite time consuming, even with the methods described here. Between lead-form and panel construction, plan on taking about 3 hours to build each of the 8 panels.
Lead forming 512 LEDs is not the most fun part of this project. But it is an important part, and doing it right the first time will definitely make the whole project easier. So here are details of how to lead form the LEDs using the 3D printed jig. If they sound complicated, don't worry. You'll be able to do this lead bend in your sleep by the time you've done it 512 times!
We are bending the anode lead (the long one) with a jog to the outside edge of the LED, but it still goes down as it did originally. We are bending the cathode lead first to the outside edge of the LED and then at a right angle perpendicular to the anode lead.
While 5 mm LEDs can be lead-formed with just some needle-nosed pliers, 3mm LEDs are hard to hold and a jig is required. 1. The LED is inserted into the jig with the long anode lead away from the protruding bend guide. 2. The anode is then bent 90 degrees. There is a guide line on the jig showing there it goes.
3. The cathode lead is also bent 90 degrees but perpendicular to the anode lead. Again there is a guide line on the jig showing the direction. 4. The cathode lead is then bent 90 degrees to the right around the protruding bend guide. 5. Finally, the anode lead is bend 90 degree upward at the edge of the LED. Use your thumb to hold it down at the edge. 6. This shows the finished result. 7. The LED can be ejected from the jig by inserting a paper clip into the hole on the backside of the jig. This is the finished lead-bended LED.
I usually lead form 64 LEDs, build a panel, test it and then repeat until I have 8 good panels. Getting the lead forming right, with nice sharp angles and good 90 degree turns is very important for smooth panel construction.
Building Panels
Now let's look at building our vertical panels. The lead-formed LEDs fit into the slots in the template pretty well, but the leads are stiff and easily push the LEDs out of their slots, so I used Blue Tack, the temporary adhesive, to hold both the LED and the vertical lead above it in place until they can be soldered.
Above is a closeup view of an LED ready to be soldered. LEDs are inserted into the template starting in the upper right corner and moving from right to left and down. At first I was trying to get a whole row set up before soldering, but found it works best to solder after every two or three LEDs are in place. Once a row of LEDs is completely soldered, most of the Blue Tack can be removed, though I usually leave a couple in place just to help keep the whole panel in its place on the template. Here are some additional pictures to see how the process progresses:
I am not the best when it comes to making beautiful solder connections. But the nice thing about this template is that even if the leads are sometimes out of place, the LEDs themselves are pretty close to perfectly positioned. And that's what really matters when you are trying to make a nice cube!
I found that about 10 little balls of Blue Tack were required to build a panel. Just keep reusing them where needed and removing most as soon as soldering is done.
The panel will be stuck to the template in some of the places where vertical leads were soldered - a result of template plastic melting. It never was bad enough to seriously damage the template, but does require popping the leads loose from the template with a small screw driver sometimes. Be especially careful when removing the panel from the template to break it loose from the template at any point where it sticks, so as not to bend the entire panel!
Testing a Panel
It is important to test completed panels. There is nothing worse than getting a cube fully constructed and then finding a bad LED or a cold solder joint in the middle of your cube. In case you're wondering how a bad LED could end up in your panel, reversing the polarity during lead bend or overheating the LED during soldering are two of the easy ways to end up with a bad LED.
I test my panels while they were still in the template, as that makes replacing a bad LED or fixing a bad solder joint fairly easy. I simply used a 5 volt supply and a 180 ohm resistor and connected them to each row (ground) and column (+5) to make sure each LED lit up when it was supposed to.
Assembling the Cube
Our first task is to mount all 8 panels on our base plate. The holes in the baseplate are made deliberately large enough to make it easy to insert the panels all the way in until the bottom LED is up against the panel.
The panels are held in place with generous amounts of hot glue applied to the back side of the base plate.
Both for physical integrity and to connect up all the cathodes in each layer of our cube, we need to add horizontal rails to our cube. These rails are created with 20 gauge tinned copper wire that has been straightened and hardened by twisting it with an electric drill while pulling it straight. This technique created surprisingly stiff, straight rails. On the side facing us on the right you can see the 8 primary horizontal rails connecting up the layers in our vertical panels. In addition, there are three additional rails on the top, back side, and back corner that have been added for structural stability.
Next we need to run a vertical rail from each layer down through the base plate. This rail is used to select a layer and all its LED's cathodes and pull them to ground to select and light a layer. In the photo below, the vertical rail for layer 8 and layer 3 have been highlighted so that you can see how these connections are made. The verticals for all 8 layers are there but somewhat hard to see.
As you will see later, the other end of these vertical layer select rails are attached to the collector of our layer select transistors.
Wiring in the Port Expanders
This is one of the more interesting parts of this project, as it is definitely not the way we usually go about building an LED cube.
First, let's talk about the port expander itself. It uses a SPI interface with our Nano microcontroller and has 16 digital I/O ports. It can be selected by a software address or a chip select pin.
We will use the software address, but still need a connection to the Chip Select / Enable pin, as CS needs to be strobed to get the chip initialized. Then we also need SPI Clock and Data-In pins to operate our port expanders. So there are 3 common pins going to all 4 port expanders - Chip Select(Enable), SPI Clock, and SPI Data In (which is MOSI on our Nano).
Above is the pinout of our port expander. All the connections to the Nano are on the row of pins at the bottom, while the 16 ports that connect to the cube are at the top, i.e. A0-A7 and B0-B7.
Also in the bottom row are pins A2, A1, A0. These provide each port expander with a unique software address. In the image below, which you saw earlier, we show the 4 port expanders with their physical location and assigned addresses. Important: These 3 pins must be used to set the addresses. Address 20 is default - no connection to these three pins. For address 21, tie A0 to Vcc. For address 22, tie A1 to Vcc. For address 24, tie A2 to Vcc.
Now let's look at the connections between the port expander and our cube. The image below is pretty busy, but shows how the port expander ports map onto the cube. This image shows 1/4 of our cube and this is repeated four times at the base of the cube. The pale blue connections shown are actually 180 ohm resistors wired between the pins of the port expander and the vertical anodes rails coming from the cube. The port assignments shown here must be followed exactly for each of the four port expanders, as the software in the refresh process maps the LED lighting pattern onto the cube using these pin assignments.
It is hard to get 16 resistors soldered onto the port expander board. Blue Tack, the temporary adhesive again came to the rescue. I used it to hold the resistor in place on the board just long enough to get it soldered, than remove it and used it to hold the next resistor. It made it much, much easier!
Here is an actual photo of a port expander connected to the cube. The port expander is held in place against its post on the baseplate with a little hot glue.
Although I never found a way to make this look neat and pretty, it is a rather simple arrangement. The current limiting 180 ohm resistors themselves make the connection between the cube and the port expanders, thus avoiding the need to run additional wires between the resistors and vertical anode rails.
Adding the LayerSelectDrivers,Microcontroller,and Power Supply
We only power up one layer of our cube at a time. Each of our 64 vertical columns only light one LED at a time through its 180 ohm current limiting resistor. But a layer contains 64 LEDs which in theory could all be on at once. So we select a layer be turning on a 0.5A NPN transistor pulling the common cathodes of that layer all to ground.
This is accomplished with the addition of a small board with 8 transistors and 8 resistors. The base of the transistor is driven through a 820 ohm resistor by one of the layer select pins on the Nano. When that pin is set high, the transistor is turned on, pulling the collector and the layer it is attached to it low, thus turning on that layer. What you see at the top of the board is the collectors connected directly to the layer select rails coming from the cube.
One thing not shown in the above photo (they were added later) are another 8 resistors. These 8 180 ohm resistors were added to the collectors of each transistor with the other end tied to +5 volts. They keep the layers pulled high unless they are pulled low by turning on the transistors. While not obviously necessary, I had to add them to insure that I didn't get any "ghost images" on layers that are suppose to be off!
The Arduino Nano is mounted next to the layer select board using hot glue. A 5 volt power supply is added going to and supplying power to both the Nano and the port expanders. I needed to add a 2200 mfd. capacitor right at the Nano to insure a stable 5 volt supply to the microcontroller.
Above is a picture of the completed baseplate. While I think this is a reasonable way to build and wire a cube, I must admit, it was still a lot of hand wiring. If you are just looking for the easiest way be build a cube, buying a cube PC board on EBay and soldering shift registers into it is probably a lot easier than this!
SoftwareBasics of LED Cubes
The anodes of our LEDs are connected in columns to the base of the cube through a current limiting resistor. The cathodes are connected in layers. To turn on a particular LED, it's column is set high, then it's layer is turned on by pulling the layer's cathodes low. The layers are only turned on one at time, but they are switched fast enough that they all appear on at the same time. A timed ISR (interrupt service routine) updates the cube every few milliseconds by programming anodes and sequencing through the layers.
The content of the cube, meaning what is on and what is off, is stored in memory (the cube array) and the ISR constantly updates the cube to match what is stored in memory. The cube array is an 8x8 array of bytes. Each byte has a z (layer) and y element, and the 8 bits within that byte specify whether the 8 LEDs in the x direction are on or off.
We build animations for our cube by turning LEDs on and off in this cube array.
SPI Port Expanders
This particular cube uses SPI port expanders to configure the 64 anodes columns. The port expanders use Microchip's MCP23S17 chip which can program all 16 output ports with a single SPI command called WORD mode. This makes it very similar to a shift register. It also has a feature called HAEN which allows us to share a single CS pin between our 4 port expanders and address them through software. During construction, we assigned each port expander an address using the A0, A1, and A2 pins. You might ask why we need CS at all with software addressing, but the CS pin is necessary to initialize the port expanders.
The library we use for our port expanders is gpio_MCP23S17. There are several libraries for the MCP23S17, but this one seemed the easiest to use, because it seemed to already know we wanted to use software addressing and WORD mode. It kept things very simple and straight forward.
Refreshing this Cube
The guts of any cube software is the interrupt service routine (ISR) which refreshes the cube (updates the physical cube to match the content of the cube array in memory). Ours runs every 15 msec. Each layer is on for 1.25 msec., so 10 msec. of every 15 are used to actually light LEDs. There is perhaps another 1 msec. of "overhead" in the refresh routine used to set up those 4 port expanders 8 different times for our 8 layers. The ISR code is a little cryptic because we have to match up little 4 LED snippets addressed by our port expanders with their equivalent 4 bits in the cube array. It's all very fast thanks to the MCP23S17's WORD mode, but still a little hard to follow, even for the guy who wrote it!
The Animations
As I said earlier, I have built a bunch of cubes and written a lot of software for them, so I already have a lot of animations for 8x8x8 cubes. The Nano only has 32 KB of Flash memory, so the size of the show was basically limited to the space available on the Nano. We have a 5 minute show consisting of 13 animations.
Software Package
Included in this tutorial are three Arduino sketches, all attached as a single Zip file. There are two cube tests, Test1 just cycles through turning on every LED in the cube one at a time without the use of the refresh ISR. Test2 also turns on every LED in the cube, but does so using the ISR. The third file is the actual show with 13 animations, which runs about 5 minutes before repeating. It is actually a folder with 5 files forming an Arduino sketch with 5 tabs.
Comments