13 October 2010

The Charlie Cube

Project Features

  • 27 LEDs in a 3x3x3 configuration
  • Controller is a AVR tiny13 with 1 kByte of program memory
  • Programmed in C

The idea is not new. You can find loads and loads of LED cubes on the net. Some are small, some are insanely large and some even use RGB LEDs. And I must say I like them all. One LED-cube caught my eye because it mentions that it uses charlieplexing to control the LEDs. Its size is 5x4x4. But the instructable also says that with the 14 ports used it could have controlled 182 LEDs instead of the 80 it actually uses.

This got me thinking. How would you go about if you wanted to make a charlieplexed LED cube with efficient use of the available ports? Basically, with charlieplexing you get a multiplexed 2D matrix. How do you fit that into a 3D cube? (For the rest of this post I assume that you know what charlieplexing is.)

If a problem is complex, you start to solve it by making simplifications. Later you can gradually increase the complexity. A 1x1x1 cube is of course trivial. A 2x2x2 cube is pointless, because according to the laws of charlieplexing you need at least 4 ports to control 8 LEDs. You could simply use the same configuration as in the Nano POV to do that. And it really is quite wasteful, because with 4 ports you could actually drive 12 LEDs. So this is not challenging and in fact it is another sparse charlieplexing scheme.

So only for a 3x3x3 LED cube things start to become interesting. The basic figures: You end up controlling 27 LEDs and need 6 IO ports. And you could control no more than 30 LEDs. This is efficient.

I went with a tidy and systematic approach to transform a charlieplexing matrix to a 3D cube. First I layed out the matrix, which is 6x5 LEDs. Immediately, there is an interesting fact. There are 6 rows.

Cut that in two and you get two matrices with 3x5 LEDs.

If you move them next to each other horizontally, you get a 3x10 configuration.
All that is left to do now is to take away one column, stack that structure in the 3rd dimension and you are done.
Building It

Originally I had not planned to actually build a cube. It was meant as a kind of mental exercise. But when I realised that this was not really such a complicated structure, I changed my mind. Also, I wanted to explore how far I could get with a really small controller. And in this case, I could just get away with a DIP8 AVR tiny. Why? Because it has up to 6 usable IO ports - if you disable the reset pin and resort to high voltage serial programming. I do have an STK500 development board so that was not really an issue (or so I thought).

As recommended by several cube builders, I made a simple template by drilling holes (3 mm in my case) in the desired 3 x 3 layout of one layer of the cube into a piece of wood. Then I used that template to solder three layers of no-name LEDs into shape. Here of course is a major difference between a conventionally multiplexed cube and its charlieplexed counterpart.

Whereas with the former you connect e.g. the kathodes of all the LEDs in one layer, with the latter you only connect halve the layer. For my cube a layer consisted of 9 LEDs so I ended up with a group of 4 and a group of five LEDs.

Also, when you connect the layers of a normally multiplexed LED cube, you can simply connect all columns of the cube. As you can see from the matrix above, this is not possible for all columns when charlieplexing. The next image shows the vertical connections (the LED'S anodes) in blue.

And finally you need to connect the right layer structures to the right column. When this is done, the structure is ready for action. As in other projects, I did not plan to use current limiting resistors because at low operating voltages the tiny13 would limit the output current whether I wanted it or not.

First Try

In order to test the hardware I wrote a simple routine that would just fire up all LEDs one after the other. And I had an immediate disappointment - although every LED was lighting up. The ones connected to port 5 of the tiny13 were very dim. The reason for that was, that the repurposed reset pin has a weak driver. I knew this beforehand, but had expected to be able to equalise different brightness levels by using a differentiated timing scheme (i.e. by activating the dimmer LEDs for longer). But this was beyond all hope.

So in order to rescue the project I had to add a driver to port 5. I chose to use a simple variant with just two transistors. Once that was in place, all LEDs had an acceptable level of brightness - as long as you are not looking at it in bright daylight.


Another thing I wanted to try was to program the tiny13 in C. I hadn’t used C on microcontrollers before and I do prefer assembler. But it is always worth trying something new. And I was curious how a 1kByte controller would manage with a high level language.

I actually found it quite acceptable. I wrote an interrupt routine to do the multiplexing and displaying. And I wrote another routine to generate the animated patterns. I started by setting each LED individually, then waited and then set a new pattern. This works, but means that you fill up the program memory in no time. So I looked for a more systematic approach.

It turned out, that it is quite simple to generate certain elements in a cube with relatively little data. In my software, all LEDs have a number assigned, starting with “1” in the top right front corner, “2” on the top right edge and so on.

If you want to activate a row of three LEDs you can activate LEDs 1 to 3. Or you can activate LED 4 to 6. In the middle layer, e.g. the left row would be LEDs 16 to 18. So in order to light a row, you can use a subroutine that needs only one parameter: the offset.

Equally, if you want to activate the top layer you need to activate LEDs 1 to 9. So again all you need is a special routine that gets only one parameter (the offset) and then lights up 9 LEDs in a row.

Things get a bit more complicated if you try to switch on a row of LEDs, e.g. in the top layer, but in the other direction. Say you want the front edge to light up. You now need to activate LEDs 1, 4 and 7. The routine needed here needs one parameter as well (the offset), but this time only activates every third LED. Just like with the first subroutine, this routine can be extended to light up the whole front of the cube. You perform the same operation, but do it nine instead of three times.

To make things as efficient as possible I wrote a universal pattern generating subroutine. It gets four parameters: An offset, the number of LEDs to light up, a skip value and a repeat value. This routine can light up any rows, layers or even the whole cube. And that includes diagonal patterns and checkerboard type patterns. Then on top of this routine I built another set of more specialised routines which fix one or several parameters (e.g. 3 LEDs to activate, no repetition if you want to activate a row).

Such a set of routines is really an efficient and simple to use tool set for writing pattern sequences. I must admit that this routine was not an idea that came to me in a bright flash. It only developed gradually while I tried to implement more and more patterns and was forced to compress the code.

Final thoughts

This project doesn’t make sense if you just want an LED cube. You can get bigger controllers with more ports and more program memory for almost the same price. And if you add drivers in order to increase brightness levels you might just as well use e.g. an ATmega8 controller and could almost avoid multiplexing altogether.

But the whole purpose of this project was actually to exercise “the little grey cells” a bit. And it was fun. It is really a curious thing that a couple of flashing LEDs can be so gratifying.

If you do want to build this, find the source code here. There is no schematic. If you need one, that project isn't for you. I would recommend to use high-brightness LEDs to get a better result than I did.

And finally, here are two videos of the cube in action.


  1. I want to make the same as i'm too intersted in electronics and circuits,
    i'm a newbie so can u help..

  2. Depends on what help and how much help you need...

  3. Hey Tom,
    Which pins of this cube are you using for the communication with the microcontroller?

  4. Hey RandyB,
    take a look at the first schematic. It shows how to control a matrix of 30 LEDs with 5 IO ports.

    The rest of the post explains how to map that matrix to a 3D cube structure. In the last schematic, PORTn are the connections to the controller.

    If you are new to charlieplexing, you might want to try something simpler first. Take a look at my very first blog entry about a 4x5 matrix!

  5. When you are connecting the layers together, how do you join the 2 sections of one layer together? I tried building it but im left with 2 halves of the cube and im confused about how to join them. Could you help me please?

  6. Please have a look at the schematic right above the section "Building it". You don't connect the two sections of a layer at all. You have got 3 layers with two sections. These six sections get connected to six different ports.

  7. Wonder full ...i really liked it

  8. Hi, I don't see how u came up with the 3D structure... can you explain?

  9. Very briefly: We need to drive 27 LEDs (3x3x3).

    Using Charlieplexing we need 6 ports (6x5=30).

    A Matrix with 6x5 LEDs can be transformed to a matrix with 3x10 LEDs.

    Cut away one column (to 3x9) and fold like a "Z".


  10. Hi Tom...
    I am very much interested in electronics. But some reasons i studied IT. Now i'm interested to learn some tricks in electronics.
    Can you help me about circuits ,chips ,micro controller coding.......

    1. This is a very general question which I fear I can not answer. But there is tons of information available on the net.

      My advice is to google for "basic electronics tutorials".

      Look at other people's work and try to understand it. Try to build small projects. Modify them. Experiment a lot. Don't start with huge complicated projects, since this would only frustrate you.

  11. hi tom,i want to made the 3x3x3 cube without using the programming(like 4x4x4 using diodes)....In the above video you made with diodes only but your schematic is about software in it..can u explain briefly how i can made 3x3x3 cube without using programming..

    1. I fear it is not possible to make this cube without using a programmable controller. You somehow need to generate the sequences that you want to display. This is what a microcontroller does.

      I remember seeing a project where someone used CMOS ICs (without programming) to generate more or less random sequences. But I don't remember the page.

      Also please note that the wiring scheme that I am using is relatively hard to understand. So this project is deceiving, because there is very little hardware, but the logic behind it is complex.

  12. can i get the program for 4x4x4 cube ?

    1. Yes you can. There is a link to the download at the end of the post.

  13. where to connect that two tansistors and resistor ????
    shows in abov pic
    plzzz rply sir !!!

  14. Hello Tom,

    i would like to do a school project of the 3x3x3 Charlie Cube. And your design is the best i could find and it is one of the few designs which i think are understable for the students. I wanted to ask you if i could use your Graphics in this project. All credits would go to you and I will definitely recommend your site to the students.

    1. Hi Georg,

      that is OK, in fact I would be honoured. Use my graphics to your heart's content.

      I am not sure that this is an easy to understand project. But I guess that it depends on the age and interest of your students.

      An easier project (albeit a little more extensive) is my simple 4x4x4 cube project. Just in case you are looking for something simpler.

      I'd be interested how your students managed. So if could share any insights, that would be great!

    2. Hi Tom,

      thank you for your positive answer. I have finished the charlie cube and i have managed programming it with a MSP430. I know that I need to break it down, so that the students will understand it. But I think that this will be possible with the good graphics that you are providing. I also wanted to do the 4x4x4 cube, but as I didn't finish it by myself (yet) I don't think this would be a good idea. If the project is well received I think I will do the 4x4x4 cube with my students. But regardless of the outcome, I'll do it for myself because you made a great site and you explain it very good.