Charlieplexing LEDs- The theory

Charlieplexing LEDs- The theory
This instructable is less a build you're own project and more a description of the theory of charlieplexing. It's suitable for people with the basics of electronics, but not complete beginners. I've written it in response to the many questions I've gotten in my previously published Instructables.

What is 'Charlieplexing'? It is driving lots of LEDs with only a few pins. In case you're wondering Charlieplexing is named after Charles Allen at Maxim who developed the technique.

This can be useful for lots of things. You may need to display status information on a small microcontroller, but only have a few pins spare. You may want to show a fancy dot matrix or clock display but don't want to use lots of components.

Some other projects demonstrating charlieplexing you may want to look at are:
How to drive a lot of LEDs from a few microcontroller pins.
by Westfw :- http://www.instructables.com/id/ED0NCY0UVWEP287ISO/
And a couple of my own projects,
The Microdot watch:- http://www.instructables.com/id/EWM2OIT78OERWHR38Z/
The Minidot 2 clock:- http://www.instructables.com/id/E11GKKELKAEZ7BFZAK/
Another cool example of the use of charlieplexing is at:
http://www.jsdesign.co.uk/charlie/

The Minidot 2 clock introduces an advanced charlieplexing scheme for fading/dimming which won't be discussed here.

UPDATE 19 August 2008 : I've added a zip file with a circuit that may be able to exploit the matrix charliplexing for high power LEDs discussed (at length :) ) in the comments section. It has a pushbutton + position encoder to do a user interface, plus circuitry for either USB or RS232 computer control. Each of the high side voltage rails can be set to one of two voltages, say 2.2V for RED LEDs and 3.4V for green/blue/white. The voltage for the high side rails can be set by trimpot. I'd envisage that a 20wire IDC ribbon cable be plugged into the board, and 20pin IDC connectors added along the length of the ribbon, each LED board having links to whatever wires in the matrix are desired. The circuit is in Eagle Cad and rendered in the sub image below. The high side circuit is implemented by using optocouplers which I think might be suitable.

I haven't actually tested this circuit nor written any software because of lack of time, but have put it up for comment, I'm particularly interested in the optocoupler implementation. Anyone brave enough to give it a go...please post your results.

UPDATE 27th August 2008: For those not using EagleCad....added below is a pdf of the schematic
HPCharlie.pdf(595x842) 44 KB
 
Remove these adsRemove these ads by Signing Up
 

Step 1Some LED theory

Some LED theory
Charlieplexing relies on a number of useful aspects of LEDs and modern microcontrollers.

Firstly what happens when you connect an LED to electricity.

The main diagram below shows what is called the If v Vf curve of a typical 5mm low power LED.
If stands for 'forward current'
Vf stands for 'forward voltage'
The vertical axis in otherwords shows the current that will flow through an LED if you put the horizontal axis voltage across it's terminals. It works the other way around as well, if you measure that the current is of some value, you can look across to the horizontal axis and see the voltage the LED will present across it's terminals.
The second diagram shows a schematic representation of an LED with If and Vf labelled.

From the main diagram I've also labelled areas of the graph that are of interest.
- The first area is where the LED is 'off'. More accurately the LED is emitting light so dimly you won't be able to see it unless you had some sort of super-duper image intensifier.
- The second area has the LED just slightly emitting a dim glow.
- The third area is where an LED is usually operated and is emitting light at the manufacturers rating.
- The forth area is where an LED is operated beyond it's operating limits, is probably glowing very brightly but alas for only a short time before the magic smoke inside escapes and it won't operate again......ie in this area it burns out because too much current flows through it.

Note that the If/Vf curve or operating curve of the LED is a 'non-linear' curve. That is, it is not a straight line...it has a bend or kink in it.

Lastly this diagram is for a typical 5mm red LED designed to operate at 20mA. Different LEDs from different manufacturers have different operating curves. For example in this diagram at 20mA the forward voltage of the LED will be approximately 1.9V. For a blue 5mm LED at 20mA the forward voltage might be 3.4V. For a high power white luxeon LED at 350mA the forward voltage might be around 3.2V. Some LEDs packages might be several LEDs in series or in parallel, changing the Vf/If curve again.

Typically a manufactuer will specify an operating current which is safe to use the LED at, and the forward voltage at that current. Usually (but not always) you get a graph similiar to below in the datasheet. You need to look at the datasheet for the LED to determine what the forward voltage is at different operating currents.

Why is this graph so important? Because it shows that when a voltage is across the LED, the current that will flow will be according to the graph. Lower the voltage and less current will flow.....and the LED will be 'off'. This is part of the theory of charlieplexing, which we'll get to in the next step.



« Previous Step   View All StepsNext Step »
96 comments
1-40 of 96next »
Nov 29, 2011. 4:48 PMmaikmuc says:
hi
I would like to make a chain of LED lights for the x-mas tree out of it, pulsing and blinking in different modes. I also want to use 6 pins to be able to use 30 LED's in a total lenght of 3 meters...
Will this work? or will the LED's are too dim?
Oct 1, 2011. 5:37 AMebeccarayray says:
Thank you so much for posting this! I am working on my electrical engineering senior design project which is going to be a bicycle with a lighting system along with other features. I am looking into Charlieplexing the taillight which is made up of 3 premade LED matrices.

My main question is, what is the actual time that each LED is lit up? I understand that the human eye takes in a new image 25 time per second, so I'm wondering how long should each LED stay lit for.

I'm also concerned that with the LED matrix I'm using, I won't actually be able to wire all of them up in the way that you've shown. This is the part I'm using: http://www.futurlec.com/LED/LEDM88RGCA.shtml

Check out http://litebike.info for more information about our project!

Thanks again.
Sep 8, 2011. 6:42 AMTail_wag says:
Simply an excellent article. Can you confirm that we cannot turn on all LED's in the matrix at the same time using this method? Thanks.
Aug 13, 2011. 4:11 AMEliche says:
Excellent explanation, very easy to follow and very helpful.
Mar 31, 2011. 2:37 PMbudabob07 says:
If you were to set pin A to high and pin C to low, led 5 would light up. But wouldnt leds 1 and 3 also light up (dimly) This is what happened to me when i tried the circuit
Jul 10, 2010. 1:17 PMlavert31 says:
hey, if instead if disconnecting pin B you will put it in HIGH you'll get the same effect. current wont go through LED 1 due to zero voltage difference. i say that because i wonder how can you disconnect and reconnect pins in the microcontroller? you can either put it on 1 or 0 no?
Oct 12, 2010. 4:43 PMRob Cranfill says:
Good question. That is addressed in the next "step", "Tri-states".
Oct 12, 2010. 1:55 PMRob Cranfill says:
Typo: In the 6th paragraph, last sentence,

// With 5V on pin B and 0V on pin A LED1 will glow.

should be "LED2", right?

- rob
Aug 17, 2010. 9:26 AMWVvan says:
A most excellent article. Couldn't be more clear.
Aug 4, 2010. 3:44 PMVick Jr says:
OK. I understand the theory completely, even the math for computing how many leds can be controlled with x many io pins. If that schematic for a charlieplex matrix were expanded, it would be fractal. It's pretty cool actually. Now to turn theory into practice. I'm trying to make a charlieplexed led cube that's 4x4x4 (64 leds) which could theoretically be controlled with 9 io pins, but I can't wrap my head around mapping a 2d fractal charlieplex schematic into a 3d circuit. I already have all the wows done, with all the cathodes on a row connected and the anodes unconnected for now. How do i complete it? Any help would be appreciated. I plan to control it with an arduino, and may make it into an instructible. (if people aren't tired of led cubes, that is) My backup plan is to just have a pin corresponding to each of the 4 levels and each of the 16 columns. Thats 20 io pins needed. The arduino has 13 regular digital pins, 6 analogue pins that can also be used as digital io, so it's 1 pin short. I'd have to leave something off.
Aug 4, 2010. 5:56 PMVick Jr says:
Ahhhh, I see what you did. I actually got the idea to use xmas tree leds from you, but I was constructing it according to this and didn't alternate the polarity of the leds with the layers, which I think is the key to your method. No matter, I have plenty of xmas lights and plenty of time. I can make 2 cubes (or one giant stack!) There might also be a way to charlieplex one or two places in my configuration. I only need to reduce the number of io pins by 1 to work with the ardiuno. Thanks for your help, and how's your next cube with the "proper charlieplex driving scheme" coming along? Try making a template to put your leds in, then overlay the chicken wire or whatever (I used paperclips) and solder it in. That would be a good way to get the leds and their support structure as exact as possible.
Aug 6, 2010. 7:58 AMVick Jr says:
I like the hex idea-sortof like an led ball or sphere. As for the string idea, check out this project for charlieplexed string of 12.

If and when I make an instructable, I'll be sure to refer to yours. I'm having problems getting my cube to work with my arduino though. When I test it with a battery, connecting positive and negative to the correct wires, the correct led lights up, but when I use the ardiuno, some leds work fine, but others will not light up, or have other leds light up with them. If the cube works, then it must be a problem with my arduino or with my program.

Is it possible that there's some sort of interference or something between the pins that makes them not behave as expected?

Here's my code (sorry if formatting is undone.)

It's pretty well commented. The cube is set up like yours, with alternate rows as complimentary drives. I use all the io pins except 13 and 19 (analogue 5).  T light up an led first disconnect all pins (set as input), then set it's poll and level as input and apply voltage and ground (digital out HIGH/digital out LOW) appropriately.

/*
This program controls a 4x4x4 semi-charlieplexed LED cube using 18 io pins
Alternate rows of the cube have leds with opposite poles, and are complimentary drives.
pins are refereed to by row, column, and layer (r,c,l), going front-to-back,left-to-right, and bottom-to-top.
The rows and columns are connected to poles that go through the layers.
*/

//array mapping led rows and columns to arduino pins
int gridPinMap[4][4]=
{
{0,1,2,3},
{4,5,6,7},
{11,10,9,8},
{14,15,16,12}
};

//ints mapping cube levels to arduino pins
int levels01pin = 17;
int levels23pin=18;

void setup(){
Serial.begin(9600);// initialize serial communications at 9600 bps:
allOff();
pinMode(13, INPUT);//we don't use 13 b/c it has a built-in resistor but just in case, disconnect it
}

void loop(){//main loop
//this simple program turns each pin on for a second successivly
for (int r=0;r<4;r++){
for (int c=0;c<4;c++){
for (int l=0;l<4;l++){
LEDON(r,c,l);
delay(1000);
allOff();
delay(1000);
}
}
}
}

//this function disconnects all the io pins we are using, so nothing should be on at all.
void allOff(){
Serial.print("\nOFF" );
//set everything to output by default
for (int r=0;r<4;r++){
for (int c=0;c<4;c++){
pinMode(gridPinMap[r][c], INPUT);
}
}
pinMode(levels01pin, INPUT);
pinMode(levels23pin, INPUT);
}

//this function turns on the led at (r,c,l)
void LEDON(int r, int c, int l){
Serial.print("\n(");
Serial.print(r);
Serial.print(c);
Serial.print(l);
Serial.print(")");

//if the led to light is in row 0 or 2, it's column needs a ground (digital out LOW), and the level needs a positive voltage (digital out HIGH).
//Vice-versa if on levels 1 or 3

switch (l) {
case 0://bottom level
//disconnect the other two columns so no other pins go on
//pinMode(levels23pin, INPUT);
//send ground to column of pin
pinMode(gridPinMap[r][c], OUTPUT);
digitalWrite(gridPinMap[r][c],LOW);
//send voltage to row of pin
pinMode(levels01pin, OUTPUT);
digitalWrite(levels01pin,HIGH);
break;
case 1://first level up
//pinMode(levels23pin, INPUT);
pinMode(gridPinMap[r][c], OUTPUT);
digitalWrite(gridPinMap[r][c],HIGH);
pinMode(levels01pin, OUTPUT);
digitalWrite(levels01pin,LOW);
break;
case 2://second level up
//pinMode(levels01pin, INPUT);
pinMode(gridPinMap[r][c], OUTPUT);
digitalWrite(gridPinMap[r][c],LOW);
pinMode(levels23pin, OUTPUT);
digitalWrite(levels23pin,HIGH);
break;
case 3://top level
//pinMode(levels01pin, INPUT);
pinMode(gridPinMap[r][c], OUTPUT);
digitalWrite(gridPinMap[r][c],HIGH);
pinMode(levels23pin, OUTPUT);
digitalWrite(levels23pin,LOW);
break;
}
}
Aug 7, 2010. 6:35 AMVick Jr says:
The LEDs are the same type, but they are ripped from an old string of xmas lights. They are bleached from sunlight, some are rusty, but they seem to work.

The regular arduino language is a high level C-like library with functions for pin manipulation, but I did find this page on directly manipulating pins . It should be helpfull. I'll try it in a bit.
Jul 10, 2010. 1:24 PMlavert31 says:
Ohhhh o.k! now i answered myself! putting pin B in an HIGH state will cause LED 3 to glow... the only solution is to disconnect pin B . thanks for this very comprehensive tutorial! Etay
Jul 10, 2010. 1:20 PMlavert31 says:
:-) o.k now you actually answered my question about disconnect pins. but still, instead of disconnect you can put it on HIGH no?
Jun 23, 2010. 11:07 AMtonysofla says:
I made a 12 led Charlieplexed with softwarebased 8bit PWM
http://www.youtube.com/watch?v=8apRaZQbv5w
Apr 5, 2010. 11:59 AMcodongolev says:
man.... that explained it so well. thanks!
Jan 16, 2010. 4:18 PMRobbMeex says:
I just put this thing together!! Thanks a bunch. I was looking for a simple two digit display for a GPS speedometer.
Oct 22, 2009. 3:00 AMhaooken says:
Excellent explanation. I'll definitely have to give this a try.
Aug 20, 2009. 6:27 PMricecooker7654 says:
i first i was slightly intimidated by ur explanation but after reading it, i feel like i can teach my electronics teacher this concept. thanks -drew
Aug 10, 2009. 10:27 PMmichaeletompkins says:
Thanks a lot!
May 30, 2009. 3:36 PMKoolraap says:
It's such an easy to understand explanation, i totally graped the concept with one read :)
Aug 3, 2009. 2:57 PMian25 says:
I have never understood this "charlieplexing" thing, but after reading this I understood it completely. 5 *'s
Apr 6, 2009. 10:48 AMaolinger says:
I've got it, and I'm a complete new to to microcontrollers and electronics! Thanks for this great explanations! Alex
Mar 18, 2009. 7:26 PM51fordf2 says:
Thanks, about the easiest to understand explanation I have seen. R
Mar 1, 2009. 2:05 PMgeeklord says:
In step two, don't you want 3.2-3.8 volts across an LED?
Mar 2, 2009. 5:16 PMgeeklord says:
thank you, that was helpful
Jan 25, 2009. 12:34 PMUziMonkey says:
Thanks, this was really helpful.
Dec 5, 2008. 4:02 PMyourcat says:
Thanks for posting this!
Oct 30, 2008. 2:35 AMCarlos Marmo says:
Wonderful Work! Congratulations!
Aug 26, 2008. 6:38 AMelectric_destruction says:
NICE!!! i havent been able to get an account 4 a while, but i hav been reading instructables for monthes. urs really helped me out with a problem i had 2 solve. AWSOME!!!
1-40 of 96next »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
22
Followers
7
Author:rgbphil
update later