Driving a 4-digit 7-segment display, various ways...
There are a number of similar 4-digit 7-segment LED displays in the market. Although basically the same, they vary in critical ways:
- common anode or common cathode configuration
- number and assignment of pins
The basic unit will have 12 pins, and each "digit" will comprise 7 LED segments plus a decimal point. Units are also available with 14 or 16 pins. The additional pins are used to control punctuation and other effects such as the colon typically used in 12/24 hour clock displays.
Although pin assignments vary, they all operate in a similar manner:
- a pin is common to a specific LED segment that is repeated across all digits e.g. pin 8 = "top bar of the digit"
- another pin is common to all elements in a given digit e.g. pin 6 = "all elements in the first digit"
- creating (powering) a circuit across the two pins will light the selected segment in the selected digit
- the "common anode"/"common cathode" terminology basically indicates the polarity of the circuit. Common cathode means
So much for theory; the hardest thing tends to be finding the right datasheet! I was unable to find a datasheet matching the part I have - stamped as an "SMA420564" - but figuring it out just takes a little poking around with a 5V + resistor probe. Here's my 'reverse-engineered' datasheet:
It's a 4-digit common cathode unit, with the common cathode for each digit on pins 7,10,11,6.
The anode connections for each segment are mapped in the folliwng table. The LED segments are labelled clockwise from A (top bar) to F (top left bar); G is the centre bar; and 'dp' is the decimal point segment after the digit:
pin(digit) | 7 (D1) | 10 (D2) | 11 (D3) | 6 (D4) |
---|---|---|---|---|
1 | E | E | E | E |
2 | D | D | D | D |
3 | dp | dp | dp | dp |
4 | C | C | C | C |
5 | G | G | G | G |
8 | A | A | A | A |
9 | F | F | F | F |
12 | B | B | B | B |
While you can wire up each segment pin to a digital out on the Arduino, it soon becomes pretty wasteful of pins. And how we program the unit depends in turn on how we drive it. See the following projects for various approaches:
- SingleShift - uses an 8-bit shift register and some BJTs, total of 7 Arduino GPIO pins required
- DoubleShift - uses two 8-bit shift registers and some BJTs, total of 3 Arduino GPIO pins required
- DoubleShiftWithFETs - uses two 8-bit shift registers and some n-channel FETs, total of 3 Arduino GPIO pins required
- KW4-561 Datasheet - not matching the part I have, but a pretty standard example
- a good How to.. question at EE.SE
- another great answer on Arduino.SE
- 4-Digit 7-Segment LED Display + Arduino - example of direct-wiring the LED unit
- Arduino UNO running 4-digit 7-segment display - another good example f direct-wiring the LED unit