Using the fact that many microcontroller pins have three states (+V, GND, or
"high impedence", you can drive N*(N-1) LEDs from N pins. So the little 8
pin microcontroller like a PIC12Fxxx or an ATtiny11 can drive 20 LEDs on
its five available output pins, and still have one pin left for some kind of input.

See also https://www.instructables.com/id/Charlieplexing-LEDs--The-theory/

Step 1: 20 LEDs on 5 Pins

The current crop of low pin-count microcontrollers (6 pins to 20 pins on
the whole package) are attractively priced and 'cute', but the question
arrises as to how you can make the best use of those pins for common
applications such as driving LEDs.

A direct-connect approach to driving LEDs consumes one pin for each
LED. A traditional multiplexing scheme where rows of LED anodes are
driven by one set of N pins and each row's common cathode is driven by
another set of M pins manages to light N*M LEDs with N+M pins.
However, on a processor with only 5 or fewer outputs (as is the case
with most 8-pin microcontrollers), this barely gets you any more
outputs than direct drive.

Step 2: Charlieplexing

Assuming the output pins are actually tri-state-able (active high,
active low, and high impedence (input)) it is also possible to share
the row and column drivers and control N*(N-1) LEDs with only N pins.
One pin is connected to common cathodes of a row of LEDs and driven
low, and the N-1 pins remaining are connected to the anodes and either
driven high to light that column, or left as inputs to leave the LED
off. Maxim calls this technique "Charlieplexing", and describes it in
(1); Microchip also mentions this in their document (2) (and
implements in on the PICKit 1 board as well.)

(1) "Charlieplexing - Reduced Pin-Count LED Display Multiplexing"

(2) "Tips 'n Tricks 8-pin FLASH PIC Microcontrollers"

(3) Charlieplexing LEDs- The theory An Instructable by rgbphil

Step 3: Putting It to Work.

This drives 20 LEDs from an ATtiny11. An earlier version of this board was
actually built and appears as the main page photo. I'm afraid the picture
of the schematic is pretty hopeless; you need Eagle to tell you which signals
are connected where.

Step 4: Smaller and More Versatile...

Since most of the board is taken up by the LED array, we can make room
for either a Attiny chip OR a microchip PIC12F chip. Shrink the LEDs down
to 3mm and go to a double sided board, and we get something about 27x44mm

Alas, this board hasn't been tested yet...

Step 5: Itty Bitty

Microchip of course has their 6 pin PIC10F chips, capable of driving a
mere 6 LEDs from the 3 output pins. This is about 16mm in diameter.
Going to 603 LEDs lets you get a bit smaller, but I'm not sure what's the point.

Step 6: Software

The software gets a bit messy for serveral reasons:

1) for the PCBs shown, the LEDs are laid out in a way that is convenient
to the PCB layout, rather than in "correct" bit order. IMO, this is the
way to do things, but it does mean that Row 1 doesn't necessarilly mean
bit 1, or coluimn 3 doesn't mean bit 3. This requires a level of mapping
between the usual row/column addressing and the bits that need setting.

2) Since the same bits are used for anodes and cathodes, the common
(row) connection for some bits can be in the middle of driven (column)
bits. That means you have to shift column bits around depending on whether
they are before or after the row bit for that set of columns.

3) You have to derive output words for both the ioport and the port direction

The attached ASM code for ATtiny11 is a "proof of concept." It's embarassingly
un-optimized and poorly commented, but it's all I've got written so far.
Hiya, I'm really interested in how you've done this, and I would like to use the technique on a project I'm working on at the moment, which is a working model theatre. Does anyone know whether it is possible to have more than one LED on at once if they are connected through to the same pins?? Thank you!!! Dedward
You Can, Almost all Large LED displays use this Multiplexing Theory. Its in the code to have many lights on in the same row and column on at the same time. Sadly, I'm still working on learning that Part. but there are many resources out there that can help with the code
(after nearly a year of deep thought,) I think the problem with having more than one LED on at a time in a charlieplexed environment stems from using the microcontroller pins as both the current source and current sink for the LEDs. Most microcontrollers (old-school ones, anyway, like PICs and AVRs) can easilly source/sink enough current for ONE led (10-40mA), but if you start talking about a pin sinking the current for <em>SEVERAL</em> LEDs, you quickly run the risk of exceeding the maximum current specs.<br/><br/>In a traditional multiplexed environment it is easy to make the anodes and/or cathodes each have their own high-current drivers as needed, but it's much more difficult to do this with a connection that can be anode, OR cathode, OR off depending on circumstances (at least, without reaching a circuit complexity level that is the opposite of what we're trying to achieve by charlieplexing.)<br/>
<p>This is a long time later, but still an interesting problem. You can turn on more than one LED by using PWM to light the LEDs. e.g.You can multiplex through turning on each LED (if it's LED is meant to be on) and keep it on for up to a set amount of time depending on how bright it is meant to be (lets say 1ms is the brightest). You ignore the LEDs that are meant to be off and continue on to the next LED and the next and so on until you reach the last. If the last LED is done, you then start at the beginning again. Now the problem with this is that you will pass through all the LEDs in max 20ms. The eye perceives flashing if the changes happen slower than 24mS, so we are under that threshold, so it should work. The max brightness for any LED will be 1/20 of full brightness (if all LEDs are on). However, if typically only a small number of LEDs are on, leds say 3 or 4, then they'll be on for 1/3 or 1/4 max brightness. If someone has this circuit, maybe they can experiment and see how well this works....the LEDs might be too dim if all on to be able to see any one LED being only on for 1/20 of the time.</p>
Well, that's pretty impressive for all passive hardware! <br>It puts the programming a bit beyond a lot of people though! LOL! <br>
good day!!! i just want to know of what are the software used for making schematics like in this instructable...<br><br>hoping for your answers...
Eagle is commercial product but there is free edition which has some restrictions of course (board size, number of layers etc.). There are open source alternatives like KiCad.
These were done using EAGLE from Cadsoft. <a href="http://www.cadsoftusa.com" rel="nofollow">http://www.cadsoftusa.com</a>
You mention the trick of re-arranging the bits to make the circuit board simpler. Good plan! The way to do it easily is to first write the software as if the bits didn't need switching. Instead of writing the output byte directly to the port, you first write it to the index register. Then you use a &quot;scramble table&quot; to re-arrange the bits. You index into the table, then write that byte to the port. The advantage of this scheme is if you need to change the bit order, no change is needed to the code; only the table.<br> <br> (I'm not familiar with this processor. My comments are based on the ability to do indexed addressing mode.&nbsp; Index into a table. For example, for the &quot;noadjust&quot; routine, you would have:<br> TABLE: .byte 0b00100, 0b00010, 0b00001, 0b10000, 0b01000<br> <br> copy TEMP to index register<br> load accumulator TABLE,index<br> copy accumulator to ANODE<br> ...<br> You can have separate tables for the port and the direction register. The tables can be large (256 bytes for an 8-bit scramble function) without needing a compare for each value possible. The code becomes compact and easy to debug. You can stack tables. For example, one set to give the port/direction drives, and one to do the bit scrambling (used twice: once to scramble the port bits, again to scramble the direction bits)).<br> <br> Table lookup is the key to fast processing!
can i use Attiny13A instead of Attiny11...?? thanks :)
Yes; the same principles would apply with any 6-IO cpu...<br>
This might be of interest :<br /> http://www.edn.com/article/CA6666229.html?spacedesc=designideas&amp;industryid=44217<br /> the additional transistor should be able to source additional LED in series, at some additional cost though...<br />
can you download it on the computer if so what websight?
What operating system are you using? And what AVR hardware? Did you actually build the PCB that was downloadable? While this code is a sample of how to do &quot;Charlieplexing&quot;, it's certainly not an &quot;easy to understand&quot; thing for a beginner. You might want to look at <a rel="nofollow" href="https://www.instructables.com/id/Arduino-Charliplexed-Heart-just-in-time-for-Valen/">This Instructable</a>, which uses 6 outputs from an Arduino to drive 27 LEDs...<br/>
Hi, i'm also kind of new to the arduino and multiplexing i know hom it works but the only thing i need help with is how i can send "GND" signals through the pins.? What do i need to write in the code to make it do that?
In Arduino, "digitalWrite(pin, LOW);" outputs GND signals through that pin, for all practical purposes. (digitalWrite(pin, HIGH); sends +5, and "pinMode(pin, INPUT)" turns the pin off, mostly.)
Thank you :D
Hey im a 13 year old kid, and it looks like using a microcontroller would be a fun thing. Where the heck did most of u guys learn this stuff? Even if i knew how to just set up a microcontroller and just copy&pasted code would be nice
<a rel="nofollow" href="http://www.parallax.com/Store/Robots/RollingRobots/tabid/128/CategoryID/3/List/0/SortField/0/Level/a/ProductID/535/Default.aspx">Boe Bot kit</a><a rel="nofollow" href="http://www.parallax.com/Store/Microcontrollers/BASICStampProgrammingKits/tabid/136/CategoryID/11/List/0/SortField/0/Level/a/ProductID/320/Default.aspx">whats a microcontroler</a>hi, im 13 also and i use microcontrolers for a ton of fun things, a great way to get a start is with a parallax, whats a microcontroler kit(my first kit), or a parralax Boe bot, which im still working on improving. for the most fun i woudl recoment getting the boe bot <br/>
I agree, Parallax Does an exellent job of teaching these kinds of techtronics. I started with the BASIC Stamp 2 Board Of Education kit and I can honestly say that every penny was worth it. I would definatly recommend buying the Boe-Bot kit if you are a fairly quick learner. All of Parallax's starter kits are definatly high-quality and the included textbook is really well-written (i.e, something that you can actually read without letting the ZzZzZs turn your book into a pillow.) One Kit can pretty much teach you all of the basic -level stuff, and from there you can buy other kits, or you can put some thought into design and make just about anythhing you can come up with. But i would recommend taking a computer science class to become more familiar with programming computers. Also, if you are unfamiliar with Java, computer sciences can help, if you are a seasoned veteran to programming, we have our own subspecies! Here it is:<br/><br/><em>Homo sapiens programmiens</em>- A solitary, red-eyed mammal which often talks to inanimate objects.<br/>
See also <a href="https://www.instructables.com/id/How-to-choose-a-MicroController/">https://www.instructables.com/id/How-to-choose-a-MicroController/</a><br/>which discusses a number of strategies for starting with microcontrollers in some detail. It does include mention of the Parallax Basic Stamp, Arduino, and other &quot;entry level&quot; alternatives...<br/>
they both use a BASIC Stamp microcontroler,
and they both come with guides on how to program them with examples, and if u follow it u will be programing them in no time! there are also online codes and help and a discussion frum on the parralax website
thanks for all the comments. I'll probably get an arduino...
Buy an Arduino, and get the free software with example codes. Also, on their main website there are many tutorials and guides that help you learn.
Take a look at the <a rel="nofollow" href="https://www.instructables.com/id/How-to-choose-a-MicroController/">How to Choose a Microcontroller instructable.</a> Be sure to read the comments; there's a lot of good data there as well as in the instructable itself.<br/>
umm i tryied to download the file to my arduino microcontroller and it has a error for about everything u typed. why does it do that??????
Um. How exactly are you trying to "download" it? It's an assembler program rather the C or Arduino sketch, so it has an entirely different way that it needs to be built (and a different set of tools.)
i kno im getting annoying.. but how do you ground the microcantroller?????????????
"GND" on circuits like this usually just means a common connection to the negative side of the power supply. (VCC or VDD being the positive side...)
man you own lol. ty
how u kno what resistors to use agin? umm <br/>(total - led voltage)/ma = ohms??? if that is pls say or tell me the right 1<br/>
That looks right to me. There are lots of Intsructables/Tutorials/calculators about computing the LED resistances...
hi its my first time too and im just wondering... what is the ma of a led???
Most common LEDs are spec'ed at up to 20mA or so (continuous.) In an arrangement like this, where each LED is only on for a fraction of the time, you can get away with higher currents, but the absolute max depends on the exact LED. There are "high power" LEDs that will take over 1A.
Kind of a newbie question but how do you open the eagle files in eagle?
Depending on your OS, you should be able to unzip to .brd and .sch files, and then just double-click them. Or use the "open" menu of eagle.
thanks very much it worked like a charm
Geeklord visit sparkfun.com and look at the picaxe microchips they are cheap, the software is free and they are easy to learn. Its a good place to start or look at parallax.com at their basic stamp it is also easy but more expensive. I haven't upgraded myself to more powerful chips yet because I am happy with the picaxe.
i wish i understood what this is talking about
Did soemthing like this with a PIC. Made the 20th LED a IR, and put a push button and IR detector on it.<br/><a rel="nofollow" href="http://www.2dkits.com/zencart/index.php?main_page=product_info&amp;products_id=6">http://www.2dkits.com/zencart/index.php?main_page=product_info&amp;products_id=6</a><br/>
Ah, so you did the "blinkies"! I found them via a site about DuckCon and ordered five last christmas for the kids and family. Haven't put any together yet, though. Nice looking circuit and PCB. Very resonably priced, too...
I don't think y'all are properly utilizing modern technology. Instead of worrying about getting your average current up to "nominal" so your LEDs are bright enough, just use brighter LEDs. With the modern n*1000mCd LEDs, you probably won't need more than 20mA pulses at small duty cycles. (of course, it's a cost-tradeoff thing between brighter LEDs and more expensive driving schemes.)
The biggest problem with charlieplexing is a source/sink capability of IO and relatively short time when single LED is on. There are only two methods to get reasonable luminous intensity of LEDS with charlieplexing:<br/>1. Use high current uC IO. Most of AVR uC's allow 40mA@5V, (20 mA@5V in PIC's is not enough)<br/>2. Use external hardware (makesPCB layout verry complicated, since it's tristated logics!!)<br/><br/>I decided to select 1. and I'm able to drive 2*24 leds (2*2 charlieplexing with 4 pins=16 pins). ATTiny 2313 takes 200-220mA of peak current, Single LED takes about 50mA, there are 4 LEDs on at a time, PWM is set to about 20%. <br/><br/>But, how to get even more from LEDs with charlieplexing on uC? This is my hobby, so if you have more ideas - would be great to know....<br/>Anyway this is what I did to get more and more out of LEDs:<br/>All you need to do is to use at least 2 independent charlieplexings with the same number of IO (I used two identical 2 times 4 IO). Now, put capacitors (ceramic!!) between every corresponding IO (In my project there are 2*4 capacitors 470nF). You can believe it or not, but there is a sequence of IO control which injects current from two of these capacitors to LEDs which allows current 100mA@5.5V peak though one LED.<br/><br/>You probably think this is a one time experiment with ATTiny 2313.. No, it's not since these pulses are verry short.. What do you think about my idea about charge pump, to get more and more??<br/><br/>Brutte <br/> <br/>
For a higher res display with more LEDs, the MCU would not be able to power the LEDs unless you only had one on at a time. On a large display with only one LED on at a time, the duty cycle of each LED would be too low so the LEDs would be too dim, and unless you have a very fast processor you'd have flicker. You'd need to be able to run through every LED in around 50mS to avoid flicker. Charlieplexing would put a huge computing load on the processor and make the code much more complex to write and debug as well as. That in turn would compound the problem of needing to cycle through all the LEDs fast. Overall, this technique is a cute toy but serves no practical purpose. It's a lot of fun to take the 20 LED version and show it to someone who knows just enough about electronics to be dangerous and watch them try to explain it. I have a couple of other circuits like that which are electronically so simple it's "obvious" to look at that they can't do what they do.
I don't think charlieplexing need be significantly more cpu intensive than regular multiplexing, unless you do the "single LED at a time" method.. You CAN do charlieplexing with row driver transistors and not have problems with current loading; see the Maxim app note...
First, you'd need transistor drivers on the rows and columns. The chip is doing the sourcing and sinking, and is limited to around 25mA each. That that point, you already may as well consider dedicated LED driver chips, they'd be cheaper and smaller. Second, with transistor drivers, you'd have a fixed amount of current for groupings of variable numbers of LEDs so the brightnesses would be flickering as the pattern changes. You'd want 10-20mA through each LED and 50mA will damage the LED, 100 will cause rapid LED death. For a non-trivial display size, you'd fry LEDs with a few on and have unacceptable dim LEDs with a lot on. The solution here is to add a resistor for each LED; this would not be needed with dedicated LED drivers. Third, softwarewise, each time you want to change rows, you have to modify the port register and output the correct byte to the port. It might not be that hard, but you're not going to be doing it in a chip taking care of other stuff and displaying some LEDs.
Hmm. We probably have different sorts of applications in mind... I don't think I'd use cp on anything bigger than 7x8 leds per micro, which is probably below what you consider non-trivial display size, but above anything I'm likely to do. I agree that cp is not a good idea for a large scrolling sign, for instance. OTOH, which "dedicated LED driver chips" did you have in mind? In my experience, such things tend to be very expensive compared to today's crop of microcontrollers. (I paid $0.25 for the tiny11 on the PCB pictured, as part of a group buy. And they're still less than $1 in ones at digikey...) By some definition, anything with a human-readable display CAN dedicate a good part of its cycles to display management, and turn off the display for the times when it needs to do other things (if there ARE other things. Some (pretty cool) applications don't have much too them other than making a cool display.)
Was that the group buy on piclist a while back? I was tempted to get in on it but learning a new architechture to save a few bucks didn't seem worth it. The driver chips I'm thinking of are a couple of dollars, but they each control 16 LEDs with constant current sources, and you can set each LED to one of 256 brightness values and it will stay like that until you change it. They use I2C, so you're looking at 2 IO pins to control as many LEDs as you want, and the set-and-forget feature means nothing to take care of in your firmware. It's pretty cool to play with but you're right it is a lot more expensive. Anyway, the charlieplexing application you built for this article is very cool and a great use of CP. I'm thinking about building one myself, but with 10 red-green LEDs all in a row. I've built one with 8 red-green LEDs using a pair of shift registers, and CP is looking like a great way to do version 2.
Check out the Maxim drivers - MAX6951 et al. They do all the charlieplexing internally, and give you a simple SPI or I2C interface. Not the cheapest of drivers, but easy to use.<br/><br/>The older version of these is the MAX7219. I've used most of these, and they all work well.<br/><br/><a rel="nofollow" href="http://www.maxim-ic.com/quick_view2.cfm/qv_pk/3195">http://www.maxim-ic.com/quick_view2.cfm/qv_pk/3195</a><br/>

About This Instructable




Bio: Middle aged geek username also works at yahoo.com, mac.com, comcast.net, wharton-10.arpa
More by westfw:Visualizing EAGLE Edits with a Gerber Viewer Make a Double CD/DVD Case From a Single Sheet of Paper Single Sided Really Bare Bones Board Arduino in EAGLE. 
Add instructable to: