common cathode/common anode confusion

Sorry for the beginner question, but I am very confused about which is easiest when working with an Arduino for things like 7-segment displays... common cathode or common anode? I don't seem to be able to find much helpful information with my searches to differentiate between the two. A little additional explanation in examples like the "ShiftOut" tutorial would be really useful for beginners. That said...

Is it easiest to use common cathode or common anode devices with an Arduino? Is there some simple explanation/example somewhere to help understand why one might be easier/better than the other when using an Arduino? (e.g. required external resistors vs. internal pull-ups, or overall power requirements to drive the LED segments, or less complicated programming logic)

I am sure this is also closely related to the equally confusing (to me) notion of "sinking" or "sourcing" from Arduino pins. In trying to read data sheets for devices like TPIC6B595's and 74xx595's, it is very hard for a beginner to understand why and when to select a common cathode or common anode type of device.

I am trying to figure out how to make a cascaded 4 digit counter, using 7-segment digits, but I'm stumped with what to order/buy to get going.

Any help or hints greatly appreciated,

--Jon

It is much easer to use common anode, there are many more support for this.
Current sinking is where you connect the anode to +5V and the output switches the ground.

I'm struggling with the same thing. So to ask a beginner question...

On an arduino I have 10(ish?) 5v digitial outs, and a common ground. If I connect a common anode to 5v, how do I switch the grounds? e.g. on a common anode RGB led I have the anode and 3 pins. Which would connect where? The anode to 5v presumably from your post below, but I only have 1 common gnd for the other 3?

The other three pins would connect to the pins that you are using to control them, such as pins 2,3,4. For instance you might connect the red cathode to pin 2, green cathode to pin 3, and the blue cathode to pin 4. You would then use analogWrite to send PWM values to those pins to control the intensity of the colors.

I am trying to figure out how to make a cascaded 4 digit counter, using 7-segment digits, but I'm stumped with what to order/buy to get going.

Easiest method is non-multiplexed shift registers, 1 for each digit.
Shift out the 4 digits you want displayed.
Common anodes to +5, segments pulled low by TPIC6B595 with current limit resistors, they will support the full brightness of the display.

After that, you start looking into multiplexing.
One way is to move all the shift registers into a part like MAX7219, which can drive 8 common cathode digits.
Or perhaps you move into a 4-digit 7-segment display. MAX7219 can drive that also if the part is a common cathode display.
Or perhaps you have common anode displays, the Arduino can control PNP transistors to control the anode, while a single TPIC6B595 sinks current from all the segments wired in parallel - set up the cathodes,turn on 1 anode, repeat for the other digits.
So many ways to get there...

@kd7eir - don't I then have the common anode connected to 5v, and the 3 RGB pins also connected to PWM doing 0 or 5v. There's no ground....?

markvr:
@kd7eir - don't I then have the common anode connected to 5v, and the 3 RGB pins also connected to PWM doing 0 or 5v. There's no ground....?

Yes when the pin goes to 0V that is grounding it and the current flows. Do not forget to put a resistor between the cathode and the arduino pin, you always need a resistor when connecting LEDs direct to an arduino pin.

@Grumpy_Mike ah thanks I hadn't realised you could ground through digital pins that were at 0v. Presumably that reverses the PWM i.e. analogWrite(pin,0) would put the channel at full brightness, and analogWrite(pin,255) would turn it off entirely?

Also can I put just one resistor on the common anode, rather than needing 3, 1 for each RGB pin?

"Presumably that reverses the PWM i.e. analogWrite(pin,0) would put the channel at full brightness, and analogWrite(pin,255) would turn it off entirely?"
Exactly. Have +5 on the anode and +5 on the cathode will keep the LED off.

You can use 1 resistor on the anode if you only have 1 LED on at a time.
Otherwise, the current gets shared (unequally) between the LEDs and your brightness level will be really unequal - and possibly only the Red LED (typically it has the lowest Vf when turned on) will turn on and the Blue/Green will not turn on at all.

All good points.

  • you 'can' ground through an I/O when bringing it low/+0v (bringing it HI = +5v)
  • common anode PWM is reverse ( 0 = full on / 255 = off)
  • put a resistor on each line/color that goes to a I/O pin.. (reds take less vF than other colors,, as mentioned..and you dont want to blow it)

(just regurgitating the common rules/stuff mentioned here already)

here is a wiring diagram to use for a visual reference:

Thanks CrossRoads for the pointers and ideas. As you say, so many ways to get there. But also very confusing for a beginner. I think I have read at least another 300 posts now (many, many of them with your answers in them!), and I'm starting to understand the issues a little better. I have now read a lot more about the 595's and MAX72xx's too.

In the case of multiplexing with the MAX7219, that sort of answers one of the original questions, as it only works with common cathode displays. But the other approaches like the 595's weren't so obvious with regard to CC/CA preferences or ease of use/programming.

My next dumb question is...

I am trying to match a device that has 0.3" 4 digit displays, but I haven't been able to find a similar 4 digit display in that size, and in fact the one I'm trying to match has discrete digits soldered onto its PCB. Given the way the MAX7219 works, it looks like I can just make my own 4 digit display, using discrete CC digits, and connecting them like the attached image (borrowed from Nick Gammon's page http://www.gammon.com.au/forum/?id=11516), creating my own 12-pin-equivalent part to multiplex from the MAX7219. No issues with that are there?

Thanks again for the help.

Thanks, I have around here for a bit :wink:

Yes. Connect all the anode segments in parallel, and keep the digit select/common cathode pins seperate per digit (your digit may have 2 pins for the common cathode, connect those together.

Here some other 4-digit displays

Yes, I can see you've been around a while, but also your answers, no matter how dumb the questions, or how new the member, seem universally helpful and informative.

Thanks for confirming my approach.

Thanks also for the Kingbright link. I don't see any 0.3" displays on their site though. Right after I hit the last post, I continued my search for 0.3" 4-digit displays. It looks like Liteon makes one, http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/LTC-3710%20Series.pdf but it's non-stock at Digikey.

I'll have to keep poking around, or maybe just give up and use one slightly larger or slightly smaller. Or just use the single digit approach to make my own.

BTW, a comment I haven't read yet, but I'm sure has been made, is one of the features that makes the MAX7219 appealing for my application... the multiplexing handled by the chip doesn't bog down the Arduino. I need to send step signals to a stepper motor and want a pretty clean "loop", while displaying a pot setting on the 4-digit display (with an occasional analogRead and display update). Offloading the multiplexing to the MAX7219 seems like a real performance benefit of using that chip.

Go thru the order steps anyway - often you can get a part anyway if you don't mind a short lead time.
It may come back with a huge min buy qty also, in which case keep looking!

Yes, MAX7219 does the multiplexing for you, just write the value to display to a register when something changes, and away you go.
I've used them to control 8 digits - but I only send data when one of the digits changes.
$1.25 at taydaelectronics.com (but parts arrive from a Colorado address - weird).

Now that I have done a lot more homework and reading, please allow me to re-ask my original question...

Is there some distinct reason to choose or prefer common cathode or common anode over one another?

Taking Grumpy_Mike's comments (since I never found a tutorial or simple example showing it) I wired up two LED's and tested the two possible configurations to better understand what's going on.

The attached schematic shows what I went back and did, mainly to educate myself... two LED's, one connected to 5V and one connected to GND, with respective resistors, and then a simple sketch to confirm that HIGH and LOW are used the reverse of each other to light the two LED's. Now I know how it works, and how the logic is inverted for the 5V connected yellow LED (LOW to turn it on). So now I understand (and confirmed with breadboard and sketch) how the two versions work.

But back to my original question, since I really don't understand sinking and sourcing, is one of these two options better/preferred for the Arduino architecture?

Also WRT Grumpy_Mike's comment about common anode availability, I'm no expert, but I see tons of both CA and CC devices out there (DigiKey, Mouser, Jameco), It's not so glaringly obvious to a beginner that one is more available than the other. Am I missing something?

Thanks again for helping me get some grasp of this.

(P.S. I used CircuitLabs to draw my schematic. What is everyone else using for schematics to post?)

Common anode vs common cathode really depends on the hardware driving the LEDs.
For a part like MAX7219, it is expecting to control 8 columns of LEDs, with the cathodes of each column connected. The anodes of each row are connected. It multiplexes by driving the anodes (segments) and taking one cathode (digit) low to light up a column. Then the anodes again, and the next cathode. It does that at 800Hz, and you don't see any display flickering.

You can do the same with discrete hardware - drive the anodes from arduino pins, and sink columns of cathodes with other parts, like arduino pins buffered with transistors, or transistor arrays, to sink all the current from 8 LEDs (or however many are in a column), or using high current shift register like the TPIC6B595. You would then do the multiplexing in software - drive the anodes, sink 1 cathode, drive the anodes, sink the next cathode, etc.

You can also take a slower multplexing route that does not require external hardware except for current limit resistors - multiplex by individual LED segments.
Drive one anode, sink one cathode. If you have an 8x8 matrix, this takes 64 cycles of anode/cathode. Vs using an external part, where you can do it just 8 cycles.

Common anode - this is good for when you are not multiplexing - you drive the anode high, say from 5V, and then have a shift register per 7-segment display that you use to sink the current from each segment.
Or, you can have a current source per digit, say a PNP transistor, and you connect all the segments from the displays in parallel to one shift register or transistor array - drive one anode, sink the current from the segments, drive the next anode, sink the current, etc.

Or, go the slower single segment approach, drive an anode, sink 1 segment, repeat for all segments.

I use expresspcb for drawing things for discussion, and eagle for designing boards.

But back to my original question, since I really don't understand sinking and sourcing, is one of these two options better/preferred for the Arduino architecture?

Well you have good working examples of sourcing and sinking.

With an arduino it doesn't matter because the pins on this processor can source and sink the same amount of current. However, on a lot of other processors and logic families a pin can often sink more current than it can source. Hence there are more devices that use current sinking and why common anode devices are more common than common cathode. Also more driver chips also work with common anode than common cathode. In fact common cathode driver chips are quite rare.

It's not so glaringly obvious to a beginner that one is more available than the other. Am I missing something?

What you are missing is a wide range of experience with lots of devices. It is not always possible to get a common cathode version of every device that has a common anode. It does not apply the other way round. That is if there is a common cathode version there is always a common anode version.

Thank you both!! Your two answers are exactly what I was trying to grok.

@CrossRoads -- Once I read the datasheet, I latched onto the other benefits of the MAX7219 for my current project, and it only supports CC devices. But I still wanted to understand the issues and learn as I go on, even if I used the MAX7219 as a "lego part" (just using it without understanding why) while moving ahead. I need to go find small sample schematics of each of the scenarios, PNP, NPN, anode, cathode, sinking, sourcing... at the level I did with the two LED's, to start to learn how all these work and build a better foundation.

What you are missing is a wide range of experience with lots of devices.

Indeed. The symmetry of the Arduino pins, sinking and sourcing, was the other thing that had me confused. But now I see that some brilliant designer made them that way to make it easier for us to use them. With no legacy perspective, it was hard to understand. Now I sorta get it, but have a lot to learn. I suspect the next step in my "education" needs to be getting a handle on "open collector" and NPN vs. PNP-based designs, when I'm reading datasheets and struggling to pick appropriate parts.

I have a lot to learn, but I am having an enormous amount of fun in the meantime because the Arduino platform is so rewarding with its built-in forgiveness and relatively instant gratification.

Thanks again! Hugely appreciated.

NPN vs PNP: use NPN to sink current, aka low side switching (common cathode multiplexing); use PNP to source current, aka high side switching (common anode multiplexing). N-channel MOSFET may be subbed in for NPN, and P-channel MOSFET for PNP.
NPN benefits - can be driven just with arduino output levels, even when load has power coming a >5V supply, like 12V driving a string of 3-4-5 LEDs, or coil/motor.
PNP benefits - none, really, especially when current is being sourced from a >5V supply, then an NPN is neede also so the PNP gate can go up to 12V tobe turned off, and pulled low by the NPN to turn it on.

Sometimes PNP/P-channel can't be avoided. LED cube is good example. Columns are easily pulled low by shift register such as TPIC6B595 - but need PNP to drive the common anode layer high.
Many folks use 74HC595 to drive individual columns high and then NPN to pull common cathode layer low. This may work, but total current thru the HC595 should be held to under its 70mA Absolute Max rating, or ~8mA; TPIC6B595 is rated much higher per output, so it can sink the full 20mA that most diodes are rated for and the cube can be brighter, important when 8 layers are being multiplexed.