Charlieplexing on the GPIO Xmas Tree

As you’ve probably realised, one of the things that makes this project different from other Raspberry Pi LED add-ons is that it uses something called ‘Charlieplexing’. However, you don’t need to understand Charlieplexing to be able to use the Xmas tree with your Pi: you can just use the software supplied with no worries. But, if you are interested in knowing how it works, read on!

Firstly, though, I’ve also made a video about Charlieplexing which may (or may not!) help you understand the topic a little better:

Hopefully you already know something about how to connect individual LEDs to your Pi’s GPIO pins and control them using Python… if not, do a Google search for something like “Raspberry Pi GPIO LED Python” now! Charlieplexing is a bit different to the tutorials you’ll have seen on the web: we are going to be connecting more than one LED to each GPIO pin and then use a clever bit of trickery to light up just one LED at a time.

The first thing you need to know is that, for our tree, there are four ‘nodes’ with a pair of LEDs (and a resistor) connected between each node. Each node is then connected to one of the Pi’s GPIO pins. Have a look at the circuit diagram:

 bicolour schematic

You’ll noticed I lied a bit: normally nodes A and C have only one LED between them, but all the other nodes have two. (However, see the final paragraph for more info about this).

So how do we light up just one LED? Suppose we wanted to light up LED number 5. In this case, we need to make node A output HIGH (i.e. 3.3 volts) and node B to LOW (i.e. zero volts). LED 5 then turns on and gives out light because it is ‘forward biased’. LED 6 doesn’t light up because it is ‘reverse biased’. Of course, if we switched things round so that it was node A was set to LOW whilst node B was set to HIGH then it would be LED 6 that would light up (and not LED 5).

You might be wondering what we should do with the other nodes (C and D). Should we set them to output HIGH or LOW? The answer is…. neither! Instead, we tell the Raspberry Pi to make the relevant GPIO pins for C and D to be inputs instead of outputs. Why? Well, making them inputs is effectively the same as physically disconnecting these nodes from the Pi’s GPIO pins.

So, basically, to light up one LED you find the two nodes either side of it and make one output HIGH and one output LOW. You then configure the remaining two nodes be inputs. If you want more than one LED to be lit up at one time, you simply flick between each LED very quickly and your eye is fooled into thinking they are all on at the same time.

So there you are – a very brief introduction to Charlieplexing. It was a bit of a whistle-stop tour, but look at the video at which should explain it a bit more clearly and, like I said, you don’t need to understand how it works to enjoy using the tree as you can use the supplied functions to display LED patterns easily.

About those LEDs between nodes A and C…. ordinarily there is just one yellow LED between these nodes. However, it is possible to fit a ‘bi-colour’ LED in this position which actually contains two LED in the one physical package. One of these is green and one is red and they are connected together in a pair just like any other two LEDs in this circuit.