7-segment Displays
7 Segment Display
A 7 segment display is a component that contains 7 rectangular LEDs1 arranged so it can display the numbers 0-9.
1ignoring the DP LED
7 Segment Display
Seven-segment displays are widely used in digital clocks and electronic meters.
The 7 segments of a 7-segment display are referred to by the letters a to g.
Either all of the cathodes (i.e. negative terminals) or all of the anodes (i.e. positive terminals) of the segment LEDs are connected and brought out to a common pin; thus 7-segment are either a "common cathode" or "common anode" device.
Common Anode Common Cathode
Pinout
Look at the Datasheet
Look at the datasheet of the 7-segment LED to determine if the 7-segment LED you have has a common anode or a common cathode.
This will determine if you connect
Breadboard wiring of 7-seg
Limit the LED Current
We need to use current limiting resistors to prevent damaging the LEDs in the display.
Connect a resistor (200Ω - 400Ω) to each1 of the 7 LEDs - i.e. connect 7 resistors to your 7-segment display.
1see next slide
Why not one resistor?
If you were to use only one resistor, that one resistor would have to be sized to provide enough current for all 7 LEDs. After that its up to each diode to control the current that goes through it.
The problem is that not all real world diodes have same exact characteristics and therefore there's a danger that one diode will start conducting before all the others.
Why not one resistor?
theoretically all LEDs start conducting at the same time because LEDs have the same forward voltage
in real life one LED will likely start conducting before the others because LEDs have slightly different forward voltages
LEDs in parallel
Seven Segment Arduino 0-F
Objective
7 Segment Arduino 0-F
STEP 1 - Get an actual 7-segment display
7 Segment Arduino 0-F
Build the circuit in Tinkercad.
Be sure to use 7 resistors to limit the current for each of the 7 LEDs.
Be sure to use the same type of 7-segment display as the one you picked.
Write an Arduino Program that controls the 7 Arduino outputs to cycle through the hexadecimal numbers 0 - F on the 7 segment display (as shown to the right) in 1/2 second intervals.
NOTE: Be careful!!! The default Tinkercad resistors are in kΩ
7 Segment Arduino 0-F
Build the circuit on an actual breadboad.
Alternate 7-segment display for 2020
You can use only one
7 Segment Arduino 0-F
Start with the Arduino Blink program.
Most arduino pins can be used as an input or as an output. The setup() function currently only sets pin 13 as an output. Add code to the setup() function to set pins 7,8,9,10,11,12 as outputs as well.
void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}
7 Segment Arduino 0-F
You could use a digital_write() for each of the the 7-segments for each of the 16 digits (0-F) for a total of 7 x 16 = 112 digital_write()s.
or ….
You can use a function that writes all 7 segments using the lower 7-bits of a 1-byte hex value - your code would then only need to call this function 16 times (once for each hex digit you want to display).
7 Segment Arduino 0-F
Use the SetValue() function on the next page to write the correct values to the 7 outputs (i.e. pins 7-13) and then pause for ½ a second.
Common Anode or
Common Cathode
13 | 12 | 11 | 10 | 9 | 8 | 7 |
a | b | c | d | e | f | g |
1 | 0 | 0 | 1 | 0 | 1 | 1 |
SetValue(0x4B)
not a real number 🙂
A 0x in front a number indicates you are specifying a hexadecimal number.
7 Segment Arduino 0-F
digitalWrite(pin, value)
void SetValue(byte hex) {
digitalWrite(13, hex & 0x40);
digitalWrite(12, hex & 0x20);
digitalWrite(11, hex & 0x10);
digitalWrite(10, hex & 0x08);
digitalWrite(9, hex & 0x04);
digitalWrite(8, hex & 0x02);
digitalWrite(7, hex & 0x01);
delay(500);
}
0100 1011 0x4B
& 0100 0000 0x40
0100 0000 != 0 (pin 13 is HIGH)
SetValue(0x4B)
0100 1011 0x4B
& 0010 0000 0x20
0000 0000 = 0 (pin 12 is LOW)
7 Segment Arduino 0-F
PIN | | | | 0x4b 0x08 | 100 1011 000 1000 |
| | | 10 | | 000 1000 |
| 0x4b 0x40 | 100 1011 100 0000 | | 0x4b 0x04 | 100 1011 000 0100 |
13 | | 100 0000 | 9 | | 000 0000 |
| 0x4b 0x20 | 100 1011 010 0000 | | 0x4b 0x02 | 100 1011 000 0010 |
12 | | 000 0000 | 8 | | 000 0010 |
| 0x4b 0x10 | 100 1011 001 0000 | | 0x4b 0x01 | 100 1011 000 0001 |
11 | | 000 0000 | 7 | | 000 0001 |
ANDing the two numbers will either result in all 0 or a non-zero value.
A non-zero value in digital_write() will write a logic 1 to the pin.
SetValue(0x4B)
7 Segment Arduino 0-F
Take out the delay in Blink so that the Arudino makes the 7-segment display count from 0 to F as fast as it can.
Start the Logic program on the PC.
7 Segment Arduino 0-F
Connect the logic analyzer to the seven segments of your circuit to see the signals change.
Make sure you connect to the points in your circuit where the signals are actually changing.
ground symbol
ground wire for circuit
(gray and labeled)
7 Segment Arduino 0-F
You should be able to correlate the waveforms you captured on the logic analyzer to your truth table. You should be able to find the momemt in time each number 0-F is displayed as well as confirm your a-g signals (e.g. the signal in the picture above is high for two numbers in a row and then has two other numbers for which it is high, then repeats).
Show me your waveforms.
(point out both segment a & the number A)
Works best if your signals a - g are connected in order.