Practical PIC Projects
   

53 LED CUBE Controller
for PIC16F688

 


Now available from the on-line store

Short kit includes all parts to build working cube (excludes main cube LEDs)



Description

Do a search on YouTube and you'll turn up literally dozens of video clips of LED cubes, small 3x3x3 cubes,  bi-colour, RGB and mono cubes, amazing 16 x 16 x 16 RGB cubes.  However, very few show you how to make one and provide the firmware.

The cube described on this page uses a 5 x 5 x 5 matrix of single colour LEDs.  This is a good size to experiment with as the number of LEDs required at 125 keeps the cost down, doesn't take too long to assemble and just fits onto a eurocard sized PCB.  The power requirement is under 1 amp and the use of just one colour keeps both the hardware construction and control software fairly simple.

The project includes a ready to program HEX file with some demo cube animations and also the source code.  The firmware implements a simple macro drawing processor command set so if you've got some programming skills you can create your own animations for the cube.

Although the project on this page uses a PCB, the original prototype (see below) was constructed on a prototype pad board so if you're not able to make your own PCB it's still possible to make this project yourself.  (we've now had some PCB's manufactured - you can buy one from the on-line shop )


prototype controller


 


prototype controllers and
 LED cube

Underside of prototype LED cube

All lit up; orange 3mm LEDs 


Schematic

Download schematic in PDF

 

Final PCB version

Circuit Description

The LED cube is made up from 125 LEDs arranged into 5 layers of 25 LEDs each.  The display itself is multiplexed so instead of requiring 125 connections it requires one to each of the five layers and 25 to each LED in a layer making a total of 30.  The cube is refreshed by a software interrupt routine with each layer active for 2ms, so the entire cube is refreshed every 10mS (100Hz). This results in a display with no visible flicker.

Only 8  I/O lines are needed to control the LED drivers for the cube which allows a tiny 14 pin PIC 16F688 microcontroller to control the whole cube. This micro has an internal 8Mhz clock and 4Kwords of program memory. 

Each of the LED layers is arranged in a 5 x 5 matrix and controlled by a transistor in an emitter follower configuration connected to the LED anodes.  When the respective layer control output from the PIC goes high the base of the transistor is held at +5V and the emitter sits approximately 0.7 volts below this.   The transistors used are BC637 NPN transistors, if an alternative is used it should be of similar specification, have an Ic rating of at least 1 amp and check the pin out.

The cathodes of the LEDs are connected to IC2 & IC3.  These are STP16CP05 low voltage 16-bit constant current sink drivers.  The LED current is set by a single resistor connected to the RSET input of the IC (pin 23).  The 680R resistor gives a LED current of ~28mA; this resistor can be altered to vary the current supplied to the LEDs ( consult the datasheet before altering the value of this resistor)

The LED driver supplied in the 555FSK kit available from the PIC projects store uses the alternative CAT4016 LED driver.  This part uses a different ratio for the current mirror that is used to set the LED current.  From 08/10/2009 the RSET resistors supplied with the kit are 1K8.  If you want to alter the LED current it is calculated as Iled = 50 x (1.2 / RSET)

One layer of the cube

One column of the LED cube

The advantage of using a constant current sink driver IC's is that almost any LED can be used and the supply current remains constant regardless of the LED forward voltage.  If the output current does need to be altered, it only requires the current setting resistor on the two drivers to be changed.

The outputs of the current sink drivers are controlled by data loaded into the driver IC over a serial input.  The two driver ICs are cascaded so the PIC simply clocks in 25 bits of data to control the LEDs in each layer then sets the respective layer driver output high.  The board uses the SOIC package variant of the STP16CP05 but this part is available in PDIP package (see here for more info)

The capacitors provide power supply decoupling.  C4 and C5 in particular are important and should be tantalum bead types located close to the driver ICs

Diode D1 allows the PIC programmer when attached to J1 (ICSP header) to detect power on the target board while preventing it from actually powering the target.  Depending on your particular programmer this diode may be omitted altogether, but if in doubt fit it.  The power LED is not critical, you can use almost any 3mm LED for this, or omit it altogether if you don't want a power indicator.

Pin header JP2 provide +5volt and Gnd connections and also brings out the PIC I/O port pins RA4 and RA5.  RA4 is also connected to the switch S1 on the PCB.  These are made available for those of you who want to add additional features to the software.

Power to the circuit is provided through the DC input jack J1.  This should be connected to a 5 volt regulated power supply capable of supplying at least 1.5 amp.  The power supply should also be able to maintain regulation while the load switches between 15mA to around 700ma every 2mS, all the plug-top style ones in my workshop work fine but if you have problems this is something to check.

The J1 (ICSP header) allows in-circuit programming of the PIC microcontroller.  It will work with the genuine Microchip PICKit2 programmer and I've also tested with several clone versions of the PICkit2.  I don't test with any other types of programmer.

PCB Layout

Download PCB artwork in PDF

 

Download Overlay in PDF

Download Overlay (mirrored)

The circuit has been designed to fit onto a single sided 160mm x 100mm eurocard size PCB.  The single sided design makes home production of the PCB straightforward. 

To make it even easier, you can now buy the PCB or short kit containing all the parts except for the main cube body LEDs from the on-line store

Component List

You can buy all the parts needed to build this project from most component suppliers world wide. In the UK you can get everything except the 16F688 from Rapid Online and I've included a parts list with their part numbers below.  You can also buy a kit of parts from the Online-Store

What LEDs to use

The overall effect of the LED cube can vary enormously, so choosing and using the right type of LEDs is important.  This section gives some tips and suggestions on the type of LEDs to use.

For the main cube LEDs you can use virtually any 5mm or 3mm LEDs you want.  Some LEDs are better suited for use in a cube than others so here are some tips.

In my opinion the cubes made with 3mm LEDs in diffused packages work best, there is more space within the cube body which makes it visually more effective and the diffused body distributes the light better. 

Water clear packaged LEDs are not very effective since the LED illuminates the one directly above it.  High brightness LEDs are even worse in this respect and LEDs with 15o viewing angle are hopeless in my experience.  LEDs with outputs around 50-150mcd seem to work quite well.

If you can get LEDs in a milky white diffused package these are ideal, however they are generally not that easy to find.

If you have LEDs in a clear package you can diffuse them using Plasti-Kote Glass Frosting spray.  This works quite well but don't spray the LEDs until they've been assembled in the jig otherwise the jig rubs the coating off the side of the LEDs.

One difficulty I've found is that you can find two different LEDs that on spec' appear to have similar light output, but when you compare them in use one is much brighter.

Therefore if you can it's worth experimenting with different LEDs before assembling an entire cube.  You can put together eight LEDs in to a 2 x 2 x 2 cube; connect it into one corner of the driver PCB to get an idea of whether a particular LED is going to work effectively.

Finally, the cube needs 125 LEDs, buy a couple of extra ones so you have spares in case you get a faulty one, lose one etc.

You can try a cube with either of the LEDs below which are available from RapidOnline, alternative colours are available, check the website, but these were a reasonable specification vs. price. Also check out sellers on e-Bay for cheap LEDs.  (The 3mm orange LEDs used on the cube in the top video came from http://stores.ebay.co.uk/component-shop, item is ORANGE Standard 3mm LEDs Pack of 50 )

  • L-7104YD MINIATURE 3MM PURE ORANGE LED (RC)  Part No 55-0097
  • L-7113ID LED 5MM RED DIFF 45MCD (RC) Part No 55-0155

     

All Rapid parts/descriptions correct at 23-February 2009.  You should check part# and descriptions are correct when ordering in case I've made a mistake transferring them onto this page.

Component Description Part #
R1,2 (order 1 pack) PK 100 680R 0.25W CF RESISTOR (RC)
(see note 2 below)
62-0366
R3 (order 1 pack) PACK 100 10K 0.25W CF RESISTOR (RC) 62-0394
R4 (order 1 pack) PK 100 270R 0.25W CF RESISTOR (RC) 62-0356
     
C1,2,3 100N 2.5MM X7R DIELEC.CERAMIC (RC) 08-1015
C4,5,6 10UF 10V TANTALUM BEAD 5MM (RC) 11-0624
     
Cube LEDs (order 125+) see text above -
D1 (see note 1) BAT85 SCHOTTKY DIODE 30V DO-34 (RC) 47-3108
Q1,2,3,4,5 * BC635 TRAN NPN 45V 1A TO92 TRUSEMI RC 81-0075
IC1** PIC16F688-I/P MICROCONTROLLER (RC) n/a (see below)
IC2,3 (see note 2) STP16CP05M SO24 16 BIT LED DRIVER (RC)
See below for alternative parts
82-0125
LED1 L-7104GD MINIATURE 3MM GREEN LED (RC) 55-0105
socket for IC1 14 PIN 0.3IN DIL SKT (RC) ALSO 22-0132 22-0155
J1 2.1 PCB DC POWER SOCKET (RC) 20-0970
JP1 (see note 1) 5 WAY R/A SINGLE ROW PLUG (RC) 22-0710
JP2 (see note 1) 4 W SINGLE ROW PCB HEADER PLUG RC 22-0505
S1 TACTILE SWITCH 6X6MM HEIGHT 5MM (RC) 78-0621
LED matrix sockets 32 WAY TURNED PIN SIL SOCKET(RC) 22-1703
Power supply 5V 1.5A MINI PLUGTOP SW MODE PSU RC 85-2955

note 1:
JP1, JP2 and D1 are not required to build a working LED cube.  These parts are not supplied in the kit.

* You can use BC635, BC637 or BC639 as an alternative for the transistors Q1-Q5.  BC635 seem cheapest at December 2009.

** Rapid Online don't stock the 16F688 but you can buy it from Farnell, part # 9760563 , 8BIT FLASH MCU, 16F688, DIP14.  You can also buy a pre-programmed 16F688 from the Picprojects online shop

note 2:
Alternatives to the STP16CP05

The LED Cube kit is supplied with the Catalyst Semiconductor (ON Semiconductor) CAT4016W-T1 part.

The CAT4016 uses a different current setting ratio to the STP16CP05 so you MUST use 1K8 resistors instead of the 680R shown on the schematic.  The kit is supplied with the required 1K8 resistors.

CAT4016W-T1 is available from Farnell, order code 1656115
 

If you want to build the driver on prototype board Farnell sell the PDIP version of the STP16CP05, part # 1292453,  

Allegro Microsystems make the A6276 which based on spec' appears to be a pin compatible alternative to the STP16CP05 and is also available in PDIP and SOIC packages.

Other equivalents based on spec' are Toshiba TB62726AFNA and Macroblock  MBI5025

(based on spec' means I've read the datasheets and they appear equivalent but I haven't constructed a cube using any of these alternatives)


Power Supply Mishaps 

We've sold lots of kits for the LED cube and on the whole there have been no problems getting the kit to work.

However, a number of times now people have connected the wrong power supply to the board, in several cases they had it working with the correct 5 volt power supply but they have just picked up the wrong PSU by mistake and damaged a working board.  I've done it myself so I speak from experience.

  Firstly here's a tip.  Put some tape or other marking on the end of the power jack lead to make it stand out from all the other DC power jacks you may have around.  This will help avoid picking the wrong one by mistake.

The original board design does not have protection for over-voltage or reverse supply connection. Any voltage above 5 volts, or a reversed power connection will destroy components on the board.

  • The CAT4016 drivers chips IC2/3 are the most likely to fail.
  • If the voltage applied is >10 volts it will damage or destroy the tantalum capacitors C4/5/6
    If one shows visible signs of damage, replace all of them.
  • The PIC microcontroller is a little more robust and may well survive a few seconds, but given a high enough voltage or long enough and it too will fail.

Because the PIC microcontroller has input protection diodes connected to the power rails, the board may actually survive a reversed power connection.  This does however depend on the power supply and the length of time it's connected so expect the worst.

Finally, if you do have a power supply accident, contact us and we can sort out replacement components for you at a very reasonable cost.


Construction photos:

Soldering the surface mount parts and assembling the LEDs into a cube are not jobs for a novice electronic kit builder, don't attempt this project unless you are confident of your ability and have the necessary skills and equipment.

Whatever your ability level please take time to read through this section once before starting construction and refer to it again during construction.  You are also advised to refer to the schematic diagram.

Assembly is in two stages; control PCB and LED cube.  It's easiest to assemble the LEDs into a cube using the PCB to hold it in place so I suggest the PCB is assembled first.

1. The controller PCB
2. The LED cube

Assembling the controller PCB

Fig.1

 
Fig .2

 
Fig. 3

Fig. 1 Check the PCB to make sure all the holes have been drilled, and look for any etching faults, bridges, breaks etc. before commencing with the assembly.

Fig. 2 The design has deliberately been kept to a single sided PCB, however this has meant 16 wire links are needed to interconnect tracks on the copper side.  You should start by installing these wires.

Fig. 3 The silk screen overlay for the PCB doesn't show the location of the 16 link wires. The location of the links is indicated by the yellow lines over layed on the photo.  (download PDF version of this image )


Fig.4

 
Fig .5

 
Fig. 6

 

Fig. 4/5 Snap the SIL socket in to individual pins (use a knife) and then solder one in to each of the 25 LED holes and 5 layer drive connections.  (you can of course solder the LEDs of the cube directly to the PCB, however it makes repair and removal of the cube difficult should you have a fault or wish to swap cubes)
(The kit includes a 32 way SIL socket strip, you only need 30 so you have two spare)

Fig. 6 Install the resistors. 

Colour value bands on the resistor body are:
R1/R2 are 1K8 (brown-grey-black-brown-brown)1K80
R3 is 10K  (brown-black-orange-gold)  10K resistor
R4 is 270R  (red-violet-brown-gold)     270R resistor

The Short Cube kit includes two 1K8 resistors for R1/R2 for use the the CAT4016 LED driver IC's. 
D1 is not included as it is not required to build the working cube from the kit.


Fig.7

 
Fig .8

 
Fig. 9

 

Fig. 7 Install the capacitors.  Note that the Tantalum capacitors C4/5/6 must be fitted the correct way round.  There will normally be a vertical line and/or '+' symbol on body of the capacitor above the positive lead and one lead is normally longer than the other; the long lead is the '+' positive lead.

Fig. 8 Install the 5 transistors, again ensuring they are positioned as shown on the overlay.

Fig. 9  Finish the upper side of the PCB by installing the LED, switch, pin headers and sockets.  When installing the LED fit the cathode lead into the hole marked 'Ca' on the PCB.  The LED cathode lead is the shorter of the two leads.

At this point, apply 5 volts to the DC input jack and take note of the following: 

  1. The DC jack requires a centre +ve input connection.  As there is no reverse polarity protection on the board you must ensure the power supply connector is correctly wired or you will destroy the LED driver IC's.
  2. You must use a 5 volt regulated DC power supply.

Use a multimeter to ensure there is 5 volts present between pins 1 and 14 of the IC1 socket.  If not find the fault and correct it before proceeding.


Fig.10

 
Fig .11

 
Fig. 12

 
Fig. 10/11   Views of the assembled PCB from different angles.

Fig. 12  Note the polarity marking on the Tantalum capacitor C5. Also the orientation of the PIC16F688.


Fig.13
Fig.14
Fig.15


Fig.13   You should now tin with solder the PCB tracks that carry the 5 volt supply and the connections from the transistors to the layer connector pins as shown in this photo.  On the PCB supplied with the kit, the wide tracks without the green solder mask over them all need tinning.  You only need a thin layer of solder.

Fig. 14  Now install IC2/3 to the copper side of the PCB.  You must ensure the IC is fitted the correct way round.  The photo shows a small dimple on the top of the IC package (bottom left). This denotes pin 1.

(The LED cube kit is supplied with the alternative CAT4016 LED driver)

Carefully align and centre the package over the solder pads, then solder the corner lead on one side.  Check the package is still aligned and then solder the opposite corner on the other side of the package.  If it's still aligned, proceed to solder the remaining leads.  Repeat this with the second IC.  Check there are no solder bridges between any of the leads. If you do get a bridge use some solder wick (copper braid) to remove it.

Tip: I solder SMD parts with a 0.8mm chisel bit and 22swg solder; 18swg solder and/or a larger bit are much more likely to lead to bridges and shorts. With care you can easily solder each pin individually and make a neat, clean job of it.  The PCB you can buy from the online store has a solder resist mask which greatly reduces the chances of bridging, though you still need to take care.

You may have read elsewhere a technique for soldering the surface mount parts where a large soldering iron bit is used to cover all the pins in lots of solder then the excess is removed using solder wick or some other method.  DON'T DO THIS.

Fig. 15  Once both ICs have been soldered in to place you should give the copper side of the board a thorough visual inspection to check for solder bridges between pads and tracks. It's a good idea to spray the copper side of the PCB with a conformal coating once assembly is complete to protect against corrosion. If you've bought the PCB for this project from the online store it already has a protective coating so this isn't necessary.

Install PCB standoff or spacers into the four mounting holes at the corners of the PCB.  These should provide enough clearance to ensure the board isn't resting on the two Surface Mount ICs.

You should also install the PIC16F688 into the IC1 socket at this point making sure it is fitted the correct way round.

Power Supply

WARNING:  You must use a 5 volt regulated power supply.

Connect a 5 volt, 1.0 amp power supply to the DC power input jack J1.  The DC jack requires a centre +ve input connection.  The power supply should be rated for 1 amp or greater, i.e. 1.5 amp would also be fine to use but 0.5 amp isn't.

The power LED1 should light. Measure the voltage between pins 1 and 14 of IC1 again to ensure there is 5 volts present.

As there is no reverse polarity protection on the board you must ensure the power supply connector is correctly wired or you will damage and destroy the LED driver IC's and other parts. 

If you apply a higher voltage to the board you will destroy the PIC and driver ICs.  While the PIC is easy to swap out, removing the two surface mount ICs will be very difficult and likely to result in damage to the PCB.

 


Assembling the LED Cube

It takes me about 01h30m to assemble the LEDs in a cube and that doesn't include assembly of the main PCB so you'll want to allow yourself plenty of time.  Patience is your friend on this one.

To assemble the LEDs into a cube you will need to make a simple jig  using a piece of MDF or similar material (see photo right). You can download a PDF template for the jig here.

LED Jig template

5mm LED cube

Fig.1

 
Fig .2

 
Fig. 3

 

Fig 1. Carefully bend the leads on each LED as shown.  The LED cathode should be cranked out so it is aligned with the side of the LED package.  This is more important with 5mm LEDs than 3mm LEDs which have a much narrower package.  The anode should be bent to an angle of 90o.  Take care bending the leads to avoid stressing them as they enter the LED body.

The fig 1. photo should only be used as a reference for forming the leads, not to identify the cathode/anode terminals.   Normally the shorter lead is the cathode, but you should verify this before assembling the cube.

Fig 2. The LED anodes run horizontally around the jig and are connected together.  The LED cathodes are perpendicular to the jig. Install five LEDs into one row of holes as shown.  The last LED should have its anode lead bent round so it connects with the LED in the next row.  Solder the anode of each LED to the next LED. 

Fig 3. Using a 5 volt power supply and resistor (anything from 120 to 330 ohms will work), test each LED to make sure it is not faulty or installed with anode/cathode terminals reversed.  With a 125 LEDs to assemble getting one the wrong way round as the tedium sets in is quite likely!

WARNING.  If you skip this test and get the LEDs assembled into the cube then find an LED isn't working it will be extremely difficult to correct it.


Fig.4

 
Fig .5

 
Fig. 6

 

Fig 4. Install LEDs into the next row and solder their anodes together.

Fig 5/6. Connect the anode terminal of the right most LED to the LED in the next row. You will also have the anode lead from the LED to the left meeting at this point.  Solder all three leads together as shown making sure the lead from the LED on the previous row clears the vertical cathode lead.


Fig.7

 
Fig .8

 
Fig. 9

 

Fig 7. Continue to install LEDs in to each of the rows, soldering and testing as you go.

Fig 8. With all five rows completed  solder a wire across all the rows to hold the layer in shape.  This wire also serves as an electrical connection.  Note how the wire goes over-and-under the LED anode leads.

Carefully remove the assembled layer from the jig and put to one side. Repeat the previous steps for each of the five layers.


Fig.10

 
Fig .11

 
Fig. 12

(1280 x 960 resolution)
 

Fig 9-12.  These pictures show the general arrangement of the LED cube. 

Assemble the cube by inserting the cathode leads of the first LED layer into the sockets on the PCB.

Next attach the second layer to the first.  The best way to do this is lie the PCB on its side.  Solder the four corner LEDs of the second layer to the first layer. 

With the four corners soldered, put the PCB flat on the work surface.  Next work around the outside of the cube soldering the two layers together.  Then work your way in to the middle of the cube soldering each LED to the one below.  It's a bit fiddly getting into the middle of the cube but not impossible.

All the time keep looking across the LEDs from several directions to ensure the LEDs in the upper layer are level and aligned with those in the layer below; make any adjustments as needed.  If you don't keep the layers level as you go the whole cube will be distorted by the time you get to the very top layer.

Repeat this until all five layers are connected together to form the cube.


Fig.13

 

 

 
Fig 13. Once all the layers are in place attach the five wires to the layer drive sockets as shown in the photo.  Ensure the wires do not short on each other as they rise up through  the cube.  The sockets are spaced apart on the PCB to help with this.  The connections are labeled L1 to L5, L1 being the lowest layer, L5 being the top.

Example of cube constructed with 3mm amber LEDs.

To construct the cube with 3mm LEDs a second template was printed and then fixed to the 5mm jig with an offset.   This was then drilled with 3mm holes to make a single jig that can be used for assembling both 3mm and 5mm cubes.  In practice the body of most 3mm LEDs seems to be about 2.9mm or less so the LED sits a bit lose in 3mm hole.  You might want to drill at 2.5mm and ream the holes out, frankly I couldn't be bothered but it is easier to solder it altogether if the LED body is held by the jig.

 

5mm Cube with green LEDs


Operation

The code supplied with the LED Cube kit is designed to run standalone without user intervention. (This code can also be download from the Firmware section)

At power on it displays the text 'PICPROJECTS' and then continues to run through a range of randomly selected animation effects.    If the S1 switch is held down at power-on it will skip the text  display.

To modify or develop your own animation effects you will need to modify the source code, reassemble it and reprogram the PIC using a separate PIC programmer.  Details for the drawing processor can be found here

Changing the startup text display

If you want to personalise the text that it displays at startup, here's how.

You will need:

  • The free MPLAB IDE software installed on your computer.    A short guide to downloading and using MPLAB can be found here.
  • A PIC Programmer hardware device e.g. Microchip PICkit2

Download the ledCubeC.zip file from the firmware section below and put all the files into a directory on your computer.

Open the files ledCubeC.asm and CubeProgram.inc

Find the section in the CubeProgram.inc file shown in the screen dump right.

Each character is animated using two instructions, for example the letter 'P' is done using these two instructions.

LDR R0,    'P'
JSR WRITE

To change the text simply edit the file, changing the characters; you can add or remove the LDR/JSR instruction pairs if you need more or less characters.

LDR RZ,4
MSET
LDR R0,    
'H'
JSR WRITE
LDR R0,    
'E'
JSR WRITE
LDR R0,    
'L'
JSR WRITE
LDR R0,    
'L'
JSR WRITE
LDR R0,    
'0'
JSR WRITE
RET

In the example above the text 'HELLO' will be animated at start-up instead of 'PICPROJECTS'

Once the CubeProgram.inc file has been modified save it.   Then select the ledcubeC.asm file and reassemble it.  The resulting ledcubeC.HEX file will then need to be programmed into the PIC.

You can go back to the original code at anytime by downloading the ledcubeC.HEX file and re-programming the PIC.


Firmware

The HEX file is ready to program directly into a PIC 16F688.  The zip file contains the source code which you can modify or just view to see how it works.  If you are going to modify the code I recommend you download and install the Microchip MPLAB IDE which will allow you to edit, modify and program the PIC seamlessly.

Not got a PIC programmer?  Buy a pre-programmed PIC from the on-line shop

Description Filename Download link
Source code for 16F688 ledcubeC.zip, v1.0.2, 12/03/2009 download
HEX file ready to program into the PIC ledcubeC.HEX, v1.0.2, 12/03/2009
(animations 13/04/2009)
download
checksum 0x579C

Description and programming details for the LED Cube Drawing Processor.

If you need a PIC Programmer I strongly recommend the Microchip PICKit 2, this is available from suppliers world wide or direct from Microchip.  It's reasonably cheap to buy and reliable. 

 



Contact us: