"So, you want to build an 8x8x8 RGB LED Cube"
I've been playing around with electronics and Arduino's for a while now, including building a high amp switch controller for my car and a six lane Pinewood Derby Judge for our Scouts group.
So I was intrigued and then hooked when I found Kevin Darrah's great site with his detailed explanations and build video's.
However there were a couple of areas of his build I thought I could improve upon.
On the plus side:
- Kevin's detailed explanations of the Arduino code required for this complex programme simplified the coding side of the build.
- I support Kevin's use of individual transistors to drive each of the 192 cathodes. Whilst this requires a component rich hardware design it allows you to drive each LED hard without risking overloading a single driver chip managing 8 (or more) LEDs.
Areas I wanted to improve:
- There must be a better way of building the cube itself plus there are over 2000 solder joints in a 8x8x8 RGB cub and if one were to fail/break in the middle it would be nigh on impossible to access and fix
- All that wiring!!!! I've had some experience in designing PCB's in the past so aimed to build a single PCB to both host the significant number of components required and the cube itself
Further searching revealed further cube designs from which I have taken other areas of inspiration.
Nick Schulze has built a wonderful example of note albeit with a simpler STP16 hardware approach and a 32bit chipKIT UNO. I leveraged his cube design rather than Kevin's.
SuperTech-IT has focused on simplifying the hardware side with a single PCB approach integrating and expanding both Kevin and Nick's programming approach with a focus on eliminating all wiring.
So a plan was set. Using Kevin's schematic, Nick's Cube structure, design a single PCB and develop a solution to both simplify the build and strengthen the cube itself.
Step 1: All Those LED's!
8x8x8 = 512 RGB LEDs. eBay is your friend here and I bought 1000 from a Chinese supplier.
The design I chose uses 5mm Common Anode RGB LED's - so each LED has a Cathode (negative) wire for each of the three primary colours (Red/Green/Blue) and a single Anode (positive) wire that is common for each of the colours.
Testing the LED's
Whilst cheap I was a little concerned about quality. The last thing you want to to find a dud LED in the middle of your cube so I set about testing each of the 512 LED's I would use.
To simplify the approach I designed a little breadboard and a simple Arduino program which would drive two LED's Red>Green>Blue individually and then all on for White on the press of a button.
One LED would act as a common reference for all the others to ensure that all the LED's were of a common brightness.
Once you get into the hang of pushing an LED into the breadboard, pressing the button, watching the LED flash through the colours it doesn't take too long to review all 512. As an aside I didn't find a single defect and was very pleased with the quality of LED's.
Choosing current limiting resistor values
While the breadboard is out it's a good time to test and validate the LED current limiting resistors you'll need to use. There are many calculators out there to help you choose the right value and it won't be the same for all the colours (Red will almost certainly have a different requirement from Green and Blue).
One key area to look out for is the overall White colour the LED emits when all the RGB colours are on. You can balance the value of the resistors to produce a clean White colour within the current limits of the LED.
Step 2: Simplifying the Cube Build
A jig to build each 8x8 slice
Building a cube of this complexity is not to be taken on lightly. This will require a significant investment of your time.
The approach I designed simplified the soldering of each 8x8 vertical "slice" of the cube in a single event, as opposed to building lines of 8 LEDs in turn and then soldering 8 of these together in a separate operation.
You will require a jig for this approach and a little time invested here reaps huge benefits later.
The picture above shows the simplicity of this design.
- I used some 18mm x 12mm softwood sourced from a local hardware store.
- Drilled 8 x 5mm holes in the middle of the 18mm side, 30mm apart on 8 lengths allowing for an extra 50mm length on each end.
- Use two lengths of wood on each side and fix these 8 drilled sections ensuring they are parallel to each other and exactly 30mm apart.
- I would advise to use some wood glue in addition to a nail/screw when fixing these together. You don't want this jig to flex.
- At the top and bottom end of the jig I set another length and put three small nails/panel pins in file with each column of holes for the LED's. The centre one being exactly in line and the other two 5mm apart on each side. We will use these nails to secure the straight lengths of wire used to form the cube - more later.
- You will notice on the pictures above another length of wood at a slight angle to the others. This one will be important later as we will cut our structural wires in line with this angle which will significantly simplify positioning each of these vertical slices into the PCB at a later date.
Take your time in building this jig. The more accurate you are here the more accurate your final cube will be.
Step 3: Preparing the LED's
LED lead connections
One of the concerns I had on previous examples I have read about was the use of simple butt joints when soldering the LED's to the framing wire. This would lead to two key issues
- It is very difficult and time consuming to hold an LED lead in position next to the framing wire without it moving long enough to ensure you get a good solder joint.
- Butt joints can break easily - something I wanted to avoid.
So I designed a solution whereby each LED is prepared with a loop at the end of each lead, through which the framing wire passes which both holds the wires in position during soldering and also provides a mechanical connection in addition to the solder for increased strength.
The downside of this was that preparation of each of the 512 LEDs took longer - I did this in batches of 64, a slice at a time, and got this down to around 3hrs per slice.
On the plus side the actual soldering of the slice using the previous jig took just over an hour.
LED bending jig
I designed a jig to support the preparation of the LED's - picture above with key dimensions.
- I took one of the previously used 18x12mm rails, drilled a 5mm hole through the centre of the 18mm side and then laid this rail down on a small panel of MDF (you could use any scrap piece of wood, this was just what I had to hand) and carried on the 5mm hole in the rail through to the centre of the MDF.
- Using the drill bit to ensure both the hole in the rail and the MDF are aligned take a pencil and draw a line along both sides of the rail along the MDF.
- Remove the drill and rail and you are left with a 5MM hole in the MDF and two parallel lines either side of it matching the rail dimensions (18mm apart).
- Draw another line through the centre of the 5mm hole perpendicular to the rail lines.
- I used 22swg tinned copper wire (a 500g roll was sufficient) which has a width of 0.711mm. I found online (eBay to the rescue again) some 0.8mm drill bits and used these as the formers around which I would bend the LED leads around to form a loop.
- Drill three 0.8mm drill bits, the middle one on the centre line of the 5mm LED hole, the others 5mm apart and importantly just outside of the rail line away from the LED hole on the MDF board- not on the line but with one side of the drill just touching the rail line.
- A fourth 0.8mm drill bit is then drilled again on the centre line of the 5mm LED hole on the other rail line and this time just inside of the rail line. The picture above should make this description a bit clearer.
- Leave the drills in the wood with about 1-15mm of the drill shank protruding from the MDF.
Now you need a tool - a good project is always one where you need to buy a special tool :-). You'll need a small pair of flat nose pliers (eBay again for £2 - £3). These have a straight parallel long nose and flat end - see picture.
Now comes the long task of preparing each of 512 LED's. I suggest you do them in batches. More details in the pictures above
- Hold the LED in the pliers with the four leads pointing towards you.
- IMPORTANT - The order and orientation of the leads is vital in this step. The Anode will be the longest lead second one in of the four leads. MAKE SURE THIS IS THE SECOND ONE IN FROM THE RIGHT. Get this wrong and your LED will fail to light up correctly as we test them later on - I know I made 2 errors out of 512.
- Whilst holding the LED in the pliers put the LED bulb into the 5mm hole in the MDF board as shown in the picture above. You may need to clearance the 5mm hole a bit at the top to ensure the Pliers lay flat on the MDF.
- Bend the LED leads around the drill bits in turn to form a loop. I found that if you back off the bend a shade when complete it opens up the loop a shade and helps to remove the loops from the drill bits when extracting the LED from the jig
- Cut off the excess from the four leads close to the loop with a pair of small wire cutters.
- Bend the Anode Loop, the one on its own, 90 degrees so the loop is facing upright towards the LED bulb
- Put the finished LED down on a flat surface and make sure all the leads lie flat along the surface, a little pressure on the LED will align them all simply
That's it.... now repeat 511 times :-)
Step 4: Building the Slices
Straightening the framing wire
So we now have a jig to make our 8x8 slices and a bundle of tested and prepared LED's.
All you need now is some framing wire. to hold all the LED's together. I used a 500g roll of 22swg tinned copper wire (again from eBay)
Now of course you'll want to straighten the wire as it comes off the roll. An easy if yet another manual task. Cut of a section of wire to length and hold both ends in two pairs of pliers and gently pull and stretch the wire. If your good you'll feel the wire stretch and then you can stop, if your heavy handed the wire will break at the pliers when it's stretched enough. Both ways are fine and you'll end up not only straightening the wire but also hardening it a bit so it will hold its form.
For each 8x8 frame you'll need 24 lengths long enough to run the full length of your jig with some spare at the ends to wrap around the panel pins to hold down whilst soldering. In addition you'll need 8 lengths for the perpendicular Anode wires just a bit wider than the width of the jig.
Building an 8x8 slice
Now wires straightened we get to the fun part.
- With the jig sitting on its two vertical rails and the 8 drilled cross rails facing you push 8 LEDs into one column at a time with the three legs of the LEDs pointing towards you.
- Now thread a straightened framing wire through the middle LED lead loops of all of the 8 LEDs and tie down each end by wrapping around the panel pins.
- Repeat this for the two outer framing wires.
- Then repeat the steps above for the other 7 columns.
You'll now have 64 LED's threaded together with 24 vertical framing wires. Make sure all of the LEDs are sitting flush against the wooden rails and straighten out any LED legs to remove any inconsistencies.
Now break out your soldering iron and fix down all the 192 connections between the LED loops and the framing wires. I'm not going to explain how to solder here, there are plenty of excellent tutorials to be found that explain this much better than I can.
Finished? Take a moment to admire your handywork the flip the jig over. We still need to add in the Anode framing wires.
Now you can see why we bent the anode lead loops 90 degrees.
- Take your 8 straightened anode framing wires and again thread through each of the 8 LEDs in each row.
- I cut the wire to the width of the jig but didn't attempt to fix these down to panel pins.
- Once finished take a moment to straighten up any LEDs to ensure you have straight consistent runs and once again solder all of the 64 connection points.
Testing the 8x8 slice
One slice down but before you cut it out of the jig lets test it first. For this you'll need a 5v source (from your Arduino or your LED tester breadboard) and single resistor (anything around 100 ohms will do).
- Connect one wire to Ground, this will be used across all of the 24 cathode framing wires.
- Connect the other wire to 5v through the resistor.
- Hold the 5v wire to one of the framing wires on the 8 anode levels
- Run the Ground wire across each of the 24 cathode framing wires.
- Check each LED lights up Red, Green and Blue for each of the 8 LED's connected to the same anode wire.
- Now move the 5v wire onto the next level and run the check again until you have tested each level, each LED and each colour.
If you find one LED does not work then you probably mixed up the anode lead on the LED when bending the LED leads. IF you find one not working then I suggest you cut out an remove the LED, take a spare prepared LED, open up the loops on the LED leads, push this new LED into the jig and bend back the loops around the framing wires as best you can.
Once all tested you can now cut out the slide from the jig. To do this cut the framing wire on the top row close to the LED lead loops and cut the bottom framing wires along the slightly angled jig frame.
Leave all the long ends of the framing wire for now, we'll tidy up those later when we build the cube.
One down, 7 more to go.
I belive I have met my first objective and developed a solution to simplify the build of the cube slices.
Step 5: Onto the Electronics
Designing the PCB
My second objective was to remove all the wiring but still leave room for some flexibility.
To that end I decided that I would:
- Bring the 6 processor control wires off the board via a connector. Most cube drivers I have seen use an SPI derivative for data transfer which requires 4 inputs - Data, Clock, Output enable and Latch - plus I added 5v and Ground so we can power the processor from the same cable.
- Leave open the serial in and serial out connections between the 74HC595 shift register chips so that you can define different loops between the chips.
- Kevins schematic is for the anode driver first then all 8 chips driving a single colour next and then the next two colours sequentially for a total of 25 shift registers.
- Nicks schematic has a separate loop back to the processor for each colour.
In addition I wanted to
- Use through hole components (as that's what I am used to).
- Limit myself to a two layer PCB board (again as within my experience).
- Have all the components on one side of the PCB (the underside) and allow for the LED slices to be soldered directly to the top side of the PCB.
So it was going to end up being a big board (270mm x 270mm) to support a cube with 30mm spacing between LED's - even so it was still a squeeze to fit in all the components and traces.
I've used a couple of different PCB design software in the past with success.
For ease of use Pad2Pad is great but you are locked into their expensive manufacturing costs as you can't export Gerber files. For this build I used DesignSpark (not as simple to use as Pad2Pad but can export gerber files) and have since been experimenting with Eagle (a very capable tool but I'm still going up the learning curve).
I dare not add up the hours spent on the software design of the PCB, it took multiple attempts to get right but I am very pleased with the result. There are a couple of missing traces in my first version but they are simple to replace. For manufacturing a small batch of PCBs I used and would recommend SeeedStudio. Good response to questions, competitive pricing and fast service.
I am since contemplating designing a SMD version which I could then have made with all the components already placed and soldered.
Lots of components
As for the components I used the following (aligning to Kevin's schematic)
- 200 NPN 2N3904 transistors
- 25 100nF capacitors
- 8 100uF capacitors
- 8 IRF9Z34N MOSFETS
- 25 74HC595 shift registers
- 128 82 Ohm 1/8W resistors (Red LED current limiting resistors)
- 64 130 Ohm 1/8W resistors (Green & Blue LED current limiting resistors)
- 250 1k Ohm 1/8W resistors (with some extras)
- 250 10k Ohm 1/8W resistors (with some extras)
- 1 5v 20A power supply (more than enough)
- 1 Arduino Mega (or processor of your choice)
- some single row header pins to connect to the Arduino
- some jumper cable to create the serial in/out loops between the shift registers
- a 6 pin header cable to board connector
- a 240v power supply cable and plug
I used and would recommend Farnell Components for ordering these in the UK, especially given their next day service and competitive pricing.
Soldering... lots of soldering
Then it was several hours of soldering all the components onto the board. I won't go through the details here but a couple of lessons I learnt were:
- Keep a solder pump and solder wick to hand - you'll need it.
- A flux pen really works although it's messy to clean up afterwards
- Use a small diameter solder - I found the best to be a 0.5mm 60/40 Tin/Lead 2.5% flux solder.
- A magnifying glass is handy to spot any solder bridges.
- Take your time, do a batch at a time and inspect all joints before proceeding to the next area.
- As always keep your soldering iron tip clean.
Given the Red colour of the LED's will probably need a different resistor value to the Green and the Blue I marked up the current limiting resistors on the PCB A, B and C. Now is the time to define the final orientation of the slices in comparison to PCB to define which lead of the LED's relates to which current limiting resistor location.
Once complete I cleaned the board with PCB cleaner, washed it down with soap and water and dried it thoroughly.
Testing your finished PCB
Before we put this to one side we need to test that it all works.
I loaded up Kevin's Arduino code (for the mega you'll need to make some minor changes) and developed a simple test program that would flash all LEDs on and off continuously.
- I made an LED testing wire by taking a single colour LED, holding a 100 Ohm resistor to one of the leads and then adding a long wire to each of the open ends. A bit of electrical tape around the open leads to stop any shorts and marked up the positive (anode) wire from the LED.
- Connect up your processor (in my case an Arduino mega) to the board with the 6 connectors
- Connect up power to the board from the power supply
- Connect the Anode test lead to a 5v source on the board
- Then put the Cathode wire from the LED testing wire onto each of the PCB cube cathode connectors in turn.
- All being well the LED on the testing lead should flash on and off, if so move onto the next one.
- If it doesn't flash then your into fault finding. I'd first check your solder joints for any dry joints, outside of that I'd suggest you work in turn away from the shift registers checking a component at a time.
Test all 192 cathodes then modify your code to test the anode layer drivers, swap over your LED test lead and connect it to ground and the test each of the 8 layer drivers.
Once you have completed and tested the PCB the fun really starts - now to build the cube.
Step 6: Building the Cube
Preparing your Anode level connectors - another jig
We have one more item to fabricate before we start to solder your 8x8 slices onto the PCB.
As we add slices we will need to add braces to the outside of each slice joining the horizontal slices together.
Given we connected all the LED's with loops to the framing wires lets not stop now.
To build the anode cross braces:
- Take another length of the wood you used for the rails and draw a line down the centre of the rail.
- Make 8 marks along this line 30mm apart.
- Take 8 of the 0.8mm drill bits and drill them into the wood, leaving the drill bit in the wood with the shank protruding about 10mm from the surface.
- Cut off a length of framing wire and straighten it as before.
- Wrap one end of the wire around the first drill bit forming a loop and then loop the wire around each subsequent drill bit forming a straight wire with 8 loops along its length.
This takes some practice but try and manipulate the wire after forming all the loops to get the wire as straight as possible. Gently prise off the wire from the drill bits and then attempt to straighten it out completely.
For the final cube you will need 16 lengths of wire each with 8 loops but during the construction process its handy to have a number of two and three loop lengths to hand to support each new slice with its neighbour.
Finally we can build the cube
We'll need to raise the PCB off the surface in order to align and lower each slice onto the PCB. I used a couple to small plastic boxes on either side of the PCB.
Remembering your orientation of the slice chosen before when defining the location of the current limiting resistors you can now lower the first slice into the holes in the PCB at one end. I suggest you start with the furthest set of holes away from you and work towards yourself.
This is where we see the advantage of cutting the cathode framing wires at an angle. This will allow you to locate each of the 24 cathode wires individually.
To support the slice and define its vertical location I used the wooden rail we used to make the anode connectors and placed this along the PCB under the first set of LEDs. With a engineers square used to ensure the slice is perpendicular to the PCB and level from end to end you can now solder the cathode framing wires into the PCB.
You can test this slice now but I found it best to put the first two slices onto the PCB and use short 2 loop anode connectors at a couple of places along the two slices before initial testing to make these first two slices more stable. After these first two test each slice in turn before adding the next.
Testing the slices.
The anode drivers are along one of the sides of the PCB and there are holes in the PCB where we will eventually connect up each layer to its driver. For now we'll use these with some log wires and 8 mini crocodile clips to attach to each layer in each slice in turn.
With the cathodes soldered down onto the PCB and the anodes connected to the drivers with the wires and clips we can then test the slice by modifying the code we used to test the PCB with a new animation.
- Write a simple animation to light up all the LEDs in your slice each colour at a time (all Red, then Green then Red then all on for White). You can define the slice number as a variable so you can amend this as you test each slice in turn.
- Connect the processor and power to the PCB and turn on.
- Check all LEDs light up in all colours.
The only defect I have observed here was due to a dry joint on one of the vertical cathode framing wires.
Solder and test each slice in turn.
Were almost there. There are two more elements we need to add to the cube now we have soldered and tested all 8 of the slices.
Anode layer connectors
Now we can break out the anode connectors with the 8 loops you prepared earlier.
Thread these across the slices joining the same layer in each slice on both slides. I moved mine until they were about 5mm away from the nearest LED cathode wire. Make sure they look straight and level before soldering all the loops and join each of the 8 anode layers together.
Anode driver connectors
Remove all the wires previously used to test the slices from the anode driver holes in the PCB and make sure the holes are clear of solder - solder wick is your friend here.
Each of the 8 anode drivers on the PCB need to be connected to an individual layer on the PCB. The anode driver nearest the power connections on the PCB should be connected to the lowest level, then work back incrementally towards the rear of the PCB and the 8th layer.
Bend a small right angle in a piece of straighten framing wire and lower the long side of the wire through the cube into the anode driver hole on the PCB. Make sure the wire is straight and level, not touching any other wire in the cube and then solder this onto the anode layer of the cube and onto the PCB
Complete for all 8 anode drivers.
Step 7: It's Complete
The build is over, your done.
With all the preparation, building, testing you've done this bit is now simple.
- Connect the power supply to the PCB
- Connect the processor to the PCB.
- Power on.
- Load or enable the animations in your software, upload to the processor and let it do it's thing
Making a case
You'll want to protect your investment after putting in all these hours.
We made a case out of some oak boards and a small sheet of ply and built a draw into the back where we could access the power supply and Arduino as well as fitting a USB plug onto the back of case to allow for easier access for reprogramming.
Then we finished it off with an acrylic case from acrylicdisplaycases.co.uk. Very well recomended.
Over to you
There are now two things you can turn your mind to:
- What kind of support/box you want to design and build to support the PCB and house the power supply and processor - I'll leave that to your imagination.
- Get into the code and start to design and write your own animations. Kevin, Nick and SuperTech-IT have done some great work here to start you on your way.
Step 8: Clip of Final Product in Action
My thanks to Kevin and SuperTech-IT for animations plus a few of my own I've created to date
Step 9: Animation - Snakes
One of my own animations to share using Kevin Darrah's code
Call the following in void Loop
snakes(200); // Iterations
Step 10: Once Your Into the Groove
My brother and I have now built one each and we're working on a third :-)
UPDATE - Third cube is now completed and we are going to put this one up for sale on eBay along with two spare PCB boards (and instructions).
We'll be making some revisions to the PCB predominantly to support the development of our next project - a 16x16x16 RGB LED cube
Step 11: Latest Version of My Arduino Mega Code
Attached you will find here the latest version of my code.
This is predominately taken from the solution developed by Kevin Darrah here but I have ported this over to the Arduino Mega and added to the animations either from other sources or developed myself.
The pins on the Arduino Mega are:
- Latch - pin 44
- Blank - pin 45
- Data - pin 51
- Clock - pin 52