One of the nice things about working for myself, is that I’m able to do random things as they strike me. Yesterday morning I woke up wondering how many LEDs I could fit on an Arduino shield. This isn’t the first time I’ve wondered that, but it is the first time I decided to give it a try. I was finishing up the Open Heart V2 PCB design, so I was already in EagleCAD, and already thinking about Charlieplexing. I then downloaded the Adafruit Proto Shield design files to get the proper measurements of the header spacing. Within 5 hours or so, I was able to flush it out. I then met up with my friend Christian for some makerbotting that evening, and he suggested I blog about my design process. Read on to get both some information on my thinking process, and a solid overview of wiring up complex Charlieplexed displays.
Like most of my projects, this started with me just thinking about something random, and then the “what if” takes a hold till I flush it out. In this case I was just lying in bed when that feeling struck me. I started thinking about Charlieplexing, and how many possible LEDs you could use with an Arduino. I knew that theoretically the Arduino could use all 14 general I/O pins to drive a Charlieplexed display, which would give a total of 182 LEDs. The way to calculate that is with N*(N-1), where N is equal to the number of pins you are willing to use to drive the display. That wouldn’t be very useful though, since you could then only use the Arduino to display from memory. The communication pins must be free, so that leaves us with 12 general I/O pins, which comes to 132 LEDs.
The question for me was then whether I could fit 132 LEDs into the proto area. The answer was no, not in a way that I liked. I ended up with only 126 LEDs, which is just 6 short of the maximum. Basically I added about 20 LEDs to the schematic, and then moved them around in the shield space till I worked out how many I could fit in there comfortably. The arrangement I came up with is a 9×14 grid of 3mm LEDs, which gave the largest number in that space. It’s large enough to display text, simple video, a game, or whatever. It also leaves some room for a small proto area, which could be used for buttons/sensors connected to the analog in, or even for those last 6 LEDs.
Once I figured out how many LEDs I could fit, I got down to the ugly business of placing them. I’ve been getting a ton of practice with Eagle lately, so that didn’t prove to be as hard as it sounds. Monotonous, sure, but not difficult. This is where my OCD is actually helpful. I set all 126 LEDs into a grid patter in the schematic first, then placing them on the board. I finished both in around an hour or so. Once I finished that up, it came down to the actual business of finishing up the schematic wiring.
I decided to wire up the first eight columns in a standard configuration. That then left me the other six columns to worry about after. I’ll try to explain the process of wiring a simple Charlieplexed grid as best I can. The easiest way I’ve seen is to do a grid of N*(N-1). Each pin will ultimately have N-1 positive, and N-1 negative connections. In this example we are going to use 4 pins to drive 12 LEDs:
You will start by wiring the N-1 row or column together with either the positive or negative connections on the LEDs. I’ve chosen to wire the negative connections on the rows, and positive in the columns, but it doesn’t really matter as long as you keep them straight. Now, for the columns you are going to have to do an off-set. Remember when I said that each pin can have N-1 positive and negative connections? Well we’ve just wired up 3 negative connections to 4 pins, so now we can only place 3 positive ones on each connection. If you look closely at all of the vertical connections, I’ve only got 3 LEDs on each of the 4 pins due to the off-set.
The off-set also helps to shift all of the LEDs in a pin mapping table. Basically, you can’t connect the positive and negative of an LED to the same pin, as that will cause a short. I started wiring the top N-1 in the first column on the left to the LED connection not already wired, then I wired the top N-2, N-3, etc. Now do the same thing from the right side, but start from the bottom. You will then have a sort of diagonal line of un-connected LEDs. Now just wire the top of the second to the bottom of the first, then the top of the third to the bottom of the second, etc. The the last row on the bottom is all by itself. You should end up with N columns of N-1 LEDs. The last step is to connect rows and columns together. I like to just go with the closest, as that makes a slightly more readable schematic.
This small 3×4 gives a pin mapping like this. You’ll notice a pattern hopefully. All of the negative pins group together in blocks of 3. Then the positive ones go down till you hit the same number, and skip one. It’s a bit rough to get your head around at first, but once you see the pattern, you can understand why it’s not that bad. I did this for the first 8 columns of 9 LEDs, and used 9 pins to do it. You can see what I finally ended up with here (click for larger):
Since I’m going with a non-square configuration, that made things a bit more complicated. What I ended up in the end was to wire the last 6 columns together in pairs. Remember that each pin can handle N-1 positive and negative connections. Since I was only using 8 of each, that left me with 3 positive and negative (6 total) connections to the first 9 pins I used. Being that there are 6 columns left, that worked out perfectly! I only needed to wire one connection to each of the remaining 6 LEDs on each row, as the other will get wired in series. I decided to wire the columns on the right in pairs together, because then you could theoretically drop off two columns to gain another general I/O Pin if you really need it. If you take a look, I’ve alternated between wiring the positive and negative connections. I ended up with this pin mapping.
So, what’s the next step you ask? I’m going to send off for this PCB to be made, and then I’ll build it. Hopefully I didn’t make a simple mistake, and this PCB will work just fine. If it turns out to work as well as I hope, then this may be a new kit. Once I find out that this works for sure, the PCB files will be released as well. I’ll also make sure to update once I get the PCBs in and built out.