December 6, 2011 Leave a comment
When my dad taught me about electronics, he compared electricity to water. He told me that amperage is like the diameter of a pipe: the greater the diameter, the more water is in the pipe. Voltage is the pressure that the water is under. The more pressure, the faster the water moves. Regardless of how high or how low either value is, the water will always want to flow in one direction. For years now, I’ve thought of electronics like plumbing because of this description. Not to say that it hindered my understanding of circuits, but it wasn’t until this past weekend that I realized that not all “plumbing” has to go somewhere.
A few months ago, I was at the local surplus store, picking up some odds and ends for projects that I may want to attempt someday. There was a pile of seven segment displays (the kind of component that has 7 lights that create numbers, given the correct pattern) for something like a quarter a piece. I picked up a half dozen, but never got around to playing with them.
On Saturday, I decided it was time to try some of these new components out. I grabbed the 7-seg displays and thought it would be fun to see what I can do with them. I went into all of this assuming that each LED segment within the display had its own dedicated anode (positive voltage) and shared a cathode (ground). This would be considered a common-cathode display. I assumed as much because, like water, electricity flows in one direction: down to the ground. If the electricity in all of the segments of the display will eventually end up at the ground, it would make sense that the display would funnel all of the power to the same common ground.
I found the part number on the side and did a google search for it in order to find the datasheet. The datasheet contained the pin description so I could map which pin would light up which segment of the display. To my dismay, I found that the display worked in the opposite manner than I expected. It contained a common anode (the power came in on one pin) and then each LED segment had its own dedicated cathode. Since I have always equated a cathode to the ground and there is only one ground, I wasn’t sure how I was going to switch the individual LED circuits on and off if they all shared a ground.
My first thought was that each cathode could be switched by a dedicated transistor. What a pain! That would mean that for every display, there would be a set of seven transistors. Not only would that take up a ton of space on the pcb board, it would break the bank on transistors.
It then occured to me: I don’t necessarily need to stop the current to turn off the circuit. I could stop it by reversing the flow. A river flows in one direction unless something changes downstream. The direction of the Mississippi river was once changed due to an earthquake. The force downstream pushed back on the force upstream. Since the downstream force was greater, the standard flow of the river changed. Why not do the same thing with electricity?
Electricity flows to the ground because there is the least amount of resistance there. All I need to do is push back on the individual cathodes, and the flow of electricity won’t pass through. I know that the supply voltage to the common anode is a little short of 3 volts (3.3 volts with a resistor). Any voltage greater than that supplied to the other end of the circuit will reverse the voltage through that circuit. The lights of the seven segment display are made up of LEDs, the power can’t move backwards (the diode will block the voltage from going the wrong way), it doesn’t move backwards. The end result is that it can’t move backwards and it can’t move forwards. The electricity just stops. Since there is no flow of electricity, the circuit turns off.
This makes it easy. I can supply 5 volts out of the I/O pins, which I can turn on and off through the software. For example, the cathode side of one of the LEDs is connected to pin 2 of my Arduino and the anode side is given 2.8 volts. If I turn pin two on, five volts are pushed towards the cathode and blocked by the LED. The 2.8 volts from the other side can’t overcome the 5 volts, so the circuit has no flow and the light is off. If I then turn pin two off, the cathode side of the LED has less than 2.8 volts, allowing the voltage from the anode side to flow through, lighting the LED.
Yay, it worked! I attached each cathode to its own pin on my Arduino. I wrote a sketch (Arduino program) that turns on and off each I/O pin in such a way that it creates the correct combinations to create numbers on the seven segment display.
Where do we go from here? Well, there are several ways to expand this. First, several seven segment displays could be connected in parallel. This would cause the same digit to appear on multiple displays. From there, using a transistor for each common anode (per display), the displays can be turned on one by one, a number is displayed, and then the display is turned off and the system moves onto the next display. If this happens fast enough, it will appear to the human eye that all displays are on all of the time, but showing different numbers. Given 14 I/O pins on my Arduino, I can get up to seven 7-segment displays in a row.
Another option is this: instead of having a dedicated I/O pin for each segment, it would be possible to controll the cathodes with a shift register. This means that the Arduino would only need three I/O pins to controll up to eight outputs on the shift register. Seven of the eight control the seven segment display. The eighth pin can control the transistor mentioned above to turn on power to the common anode of the display. Since shift registers can be daisy-chained nearly indefinately, it is possible to have a huge string of displays all being controlled by three pins on the micro controller.