Introduction
The project is a seven segments common anode LED
display system based on the Arduino development board which makes strings of texts
loaded to the Arduino to scroll across the LEDs segments.
Common anode here means that the anodes of all the segmented LEDs are "tied" or connected together, which would mean that, a "0" is required to turn an LED on and "1" to turn off an LED. The reverse is the case for a common cathode seven segments LED system.
So as not to make the article so lengthy and maybe
boring with too much technical details, I have decided to divide the full article
into a series with several sequel episodes. That means, each episode is
dependent on the previous one, and to grasp a proper understanding of the
future episode’s discourse, you might for example, have to read episodes 1, 2
and 3, before you would read episode 4 of the series.
The article is divided into several sections below
that would guide the reader on steps to building the project.
Here is a video demonstration of the working seven
segment scrolling project on You Tube.
Background
You
are most likely to find a device with LED segments on your table at home, on your
microwave oven, air-conditioning unit, car clock, car radio, key-holders, etc. They have become popular
because they consume less power, are pocket friendly, have a range of colour
varieties, they are sturdy, quite reliable, and are very simple to use.
Diodes use very little energy. Light Emitting Diodes (LED) emit slightly more energy than a standard diode in order to produce the
light that you see, and the voltage drop across a small LED is so meager that
it is negligible. Because of this, LEDs are often the best choice for making
electronics than LCD (Liquid Crystal Display) technology, because of its
low-power consumption and generally reduces the cost of digital display
devices.
A 7-segment LED |
Seven-segment digit displays are limited to displaying
numbers digits - 0 through 9, and can also display some alphabets. The seven
segment cannot display alphabet characters like, M, N, K, V, W, X, and Z. Though
some of these listed alphabet characters can be improvised using more than one seven-segment digit or displaying lower case versions of those alphabet characters. For more exotic alphanumeric characters
lettering, the four-teen segment display would be preferable to be used in
getting more robust segment representation of alphanumeric characters. The 14-segments can also display the "@,
%, and #" signs or special characters.
Theory of Operation
The
Display system starts by scrolling texts from the right corner and the texts
moves across the six seven-segment digits screen and exits through the left corner or window as shown in
the video demonstration above. This form of scrolling across the screen is usually
the most common scrolling presentation, though there could be a lot of other
ways for texts entries and exits. To understand how this is achieved, the memory
(RAM) is where the scrolling/text-movement manipulations take place.
First
off, in the RAM, there are two locations; the locations usually have an array
or stack size of different lengths. In the context of this design, the first
location, which would be called the display area or region (any character
here is automatically displayed onto the seven-segments digits screen) has six arrays, and the
second location has arrays too, of a length of 40 (could be of any length
depending on the availability of memory on your device). The second location, or
say we call it the un-displayed region, which could hold a whole lot of
characters than the display area. Now, the display area and the un-displayed
area are now co-joined, to form a much longer array or stack length. Next, we
shall name the co-joined stacks, the Screen-Buffer Area (i.e. display region +
un-displayed region). To achieve the
scrolling text effect mentioned earlier, that is, alphanumeric characters entering
from the right and exiting on the left, characters are first stored in the
un-displayed region and rotated or shifted once to the left continuously and
those characters advance towards the left, entering to the display area, and
thus producing the scrolling text effect.
POV
Actually, the display process is heavily based on a principle
called Persistence of Vision (POV). The POV is the fundamental principle
behind how most electronic display systems work, like, your TV screen, phone
screen, tabs, laptop screen, etc. It is the same principle that animations are
also based on. The POV principle involves different frames displayed and
repeated in quick successions without the human eye detecting that the frames
are changing.
Usually, the human eye retains a displayed frame for a fraction of a second after the frame has been removed or changed. Although we do not perceive them as individual frames but the brain perceives the differences in the images as continuous and gives the illusion of an animation or motion effect. For the frames to be seen or perceived as continuous, the frames must be repeated 25 to 30 times in a second.
Slowing the repeating or scanning process, that is, achieving anything less than 25/30 frames per second would cause flickering which could be perceived by the eye. The next section describes how this is accomplished by the hardware.
Multiplexing
It is the process or technique used to reduce the number of micro-controller pins needed and also to reduce the power requirements, however, at the cost of time and/or brightness.
It is the process or technique used to reduce the number of micro-controller pins needed and also to reduce the power requirements, however, at the cost of time and/or brightness.
In the process, a single digit is turned on/off
instead of turning on the whole digits or rows. After some time, the segments
LEDs are turned off. And the next segment LEDs is turned on, etc. After
cycling through a digit/row, the process repeats with the next digit/row. But
the downside is that it takes longer to display information and brightness is
reduced because the program needs to cycle through all the segments before
moving to the next digit. You will observe a slight flicker as you begin to
cascade (add) more seven segments LED's.
Basic Micro-controller (Arduino) Circuit
The circuit is intended to be basic for most of our projects that would require a display system, like, Temperature sensor project, keypad interface project, 14-segment display project, digital clock, etc. That would mean that the source code for the display function would not change for any of the upcoming above-listed projects.
Basic Micro-controller (Arduino) Circuit
The circuit is intended to be basic for most of our projects that would require a display system, like, Temperature sensor project, keypad interface project, 14-segment display project, digital clock, etc. That would mean that the source code for the display function would not change for any of the upcoming above-listed projects.
Arduino UNO and Segment Units I/O Connection |
Bill of Material
for entire project
To be able to build this project and other projects featured on the blog in full, it is recommended you get our full Arduino starter kit which can be purchased from our part store (at our office) for a cost of N7, 500.00.
Part List for Project
|
|||
SN
|
Items
|
Qty
|
Description
|
1
|
Arduino UNO R3
|
1
|
|
2
|
Jumper Cables
|
20
|
|
3
|
4 LEDs Units Module
|
1
|
Common Anode
|
4
|
2 LEDs Units Module
|
1
|
Common Anode
|
5
|
9V Battery
|
1
|
|
6
|
Power Jack Battery Clip
|
1
|
|
7
|
Resistors
|
6
|
Optional, 100 ohms, 1/4 W
|
7segments alphanumeric patterning
Determining seven segments patterns could be fun, quite interesting, straight forward, but requires meticulous calculating.
Common Anode 7-Segments Pattern
Generation
|
||||||||||
Segment
|
DP
|
G
|
F
|
E
|
D
|
C
|
B
|
A
|
Hex.
|
Description
|
"0"
|
0
|
1
|
0
|
0
|
0
|
0
|
0
|
0
|
40
|
|
"1"
|
0
|
1
|
1
|
1
|
1
|
0
|
0
|
1
|
79
|
Note that "F9" gives
same result as "79"
|
"2"
|
0
|
0
|
1
|
0
|
0
|
1
|
0
|
0
|
24
|
|
"3"
|
0
|
0
|
1
|
1
|
0
|
0
|
0
|
0
|
30
|
|
"4"
|
0
|
0
|
0
|
1
|
1
|
0
|
0
|
1
|
99
|
|
"A"
|
0
|
0
|
1
|
0
|
0
|
0
|
0
|
0
|
20
|
for lower-case alphabet a
|
"B"
|
0
|
0
|
0
|
0
|
0
|
0
|
1
|
1
|
03
|
for lower-case alphabet b
|
"C"
|
0
|
0
|
1
|
0
|
0
|
1
|
1
|
1
|
27
|
for lower-case alphabet c
|
"D"
|
0
|
0
|
1
|
0
|
0
|
0
|
0
|
1
|
21
|
for lower-case alphabet d
|
"E"
|
0
|
0
|
0
|
0
|
0
|
1
|
0
|
0
|
04
|
for lower-case alphabet e
|
The above table only caters for seven bits which
appropriately corresponds to the seven LED segments, but I want to assume that
since the micro-controller (MCU) processes in 8-bits, I would assume an optional bit
– the eighth bit (for DP - decimal point) which could be a 1 or 0. The value of
the eighth bit does not in any way affect the segment pattern code since there is no physical connection from the MCU to DP pin on the LED module. This means
that for the lower-case alphabet segment “a,” which has an equivalent of 20
hexadecimal (0010 and 0000 concatenated) as shown above, I could also say; 1010
0000, which corresponds to a hexadecimal value of A0, would still display a
correct segment “a” on the LEDs, because the value of the eighth bit does not
affect the result. But for our convention, I have decided to use zeros for the
eighth bit which also means that the decimal points (DP) on your LED segment units should be lights-off.
Please note this when using in source codes.
Another question brews; why not A-B-C-D-E-F-G for pattern generation instead of G-F-E-D-C-B-A?
Another question brews; why not A-B-C-D-E-F-G for pattern generation instead of G-F-E-D-C-B-A?
The reason is not far-fetched and it's as a result of the way the controller scans the segments, backwards, and this should not pose any problem. All you need do is follow the pattern generation on the above table and everything would be fine with your segments. Hopefully, this backward-scan would be addressed in a future blog post episode.
In the source code section you can see there the full pattern for ASCII characters (0-9 and a-z) equivalents determined by the above table generator.
To do segment patterning using the same code for common cathode, you will have to do a direct hexadecimal inversion, maybe using a calculator.
Circuit Wiring and Installation
The wiring for the circuit is quite intuitive and straight forward. A total of 20 jumpers are required for the complete connection.
The figure below shows the pin-outs for both the four-in-one 7-segments unit and also for the dual or double-in-one 7-segments unit.
s1 through s4 are control/power pins for segments 1 to 4 on the four-in-one and s1, s2 for double-in-one control/power pins.
The wiring for the circuit is quite intuitive and straight forward. A total of 20 jumpers are required for the complete connection.
The figure below shows the pin-outs for both the four-in-one 7-segments unit and also for the dual or double-in-one 7-segments unit.
s1 through s4 are control/power pins for segments 1 to 4 on the four-in-one and s1, s2 for double-in-one control/power pins.
To start, identify your segment pins on your LED
unit modules. Map and draw on a paper the 7-segment pin out above for clarity
and easy wiring.
Note that the pin-outs above in the figure for both the seven segments double-in-one and four-in-one units only applies to the seven segments LED display modules in our starer kit. Peradventure you need to figure out how to test and determine the pin outs for your LED display units, whether its a common anode or common cathode, the process of determining is very easy, you can always get a tutorial on the internet or using Google Search, on how to test and determine the pin outs of a common anode or common cathode seven segment LED unit. Follow this link to find out how to test for segments pins (a, b, c, d, e, f, g and DP) for common cathode or common cathode LED unit: Test for LEDs.
Next, insert the LED units to your breadboard. Of course, I am assuming here also that you already know how to use a bread/solder-less board.
Then, connect the Arduino port pins to the seven segment LED units using jumper pins as shown in the main circuit figure above. First, for the four-in-one LED unit module, one end of the jumper pins are inserted to Pins 0 through 6 holes on the Arduino board (just follow the Arduino circuit connection diagram above), and the other end of the jumper pins are then connected to seven segment pins, respectively to pins, a, b, c, d, e, f and g, already inserted on the breadboard. Check to see and ensure jumper pins are making firm contact and are not slack.
Next, connect another seven jumpers’ pin "a" through pin "g", of the four-in-one seven segment LED unit in parallel, by connecting to pins "a" through pins "g" of the double-in-one seven segments unit.
For my wiring connection shown, I have used seven white-coloured jumpers for the first LEDs unit and seven yellow jumpers for parallel connection to the double-in-one unit. This is not compulsory, but I have done so to simplify my wiring connection and for easy debugging if there happens to be a problem later. Also, I have used red, green and blue jumper cables for connecting the power/control signals on the Arduino PORT B sockets holes, 8 through 13.
You should note that, you don’t necessary have to
use two separate LED units like I have done, and you may instead use a
six-digits-in-one LED unit module (which is not available in our starter kit at the
moment), or six one-digit LED unit (this one would require a lot of parallel jumpers and would really be untidy and difficult to follow through).
Arduino setup
Next step, you download the Arduino IDE (Integrated Development Environment) software. If you have not downloaded before or you want to update/use the new/current IDE, you can download the Arduino IDE here. At the time of writing this article, version 1.6.6 is the latest version on Arduino main site.
Installation details
You can skip these steps if you are not a beginner
or have already been using the Arduino board before now.
Next, connect your Arduino USB cable to any port of your PC. (For Windows OS), the operating system automatically assigns a serial com port number for your Arduino device. You may see a brief message on the lower right region of your screen displaying the assigned number. If you don’t see anything displayed, you may need to check for the number from the device manager in the control panel (Usually, it is displayed at the lower right or status bar of the IDE software).
The assigned number is used to identify your connected device on your PC and the IDE uses it to upload your compiled project code to your device. To locate the assigned number from your device manager; click Start Menu -> right-click My Computer and click Properties to open Device Manager-> At the Upper left region under Control Panel click and open Device Manager -> check under Ports (COM & LPT) and find your Arduino UNO device listed with the assigned port number, for example, you will see, Arduino Uno (Com 42). Com 42 is your assigned port number for your device.
You will need to get this assigned number if you
are using more than one Arduino board on your PC.
Next, click to open the IDE, then copy and paste the codes on the code editor. Then click the Upload button or use keyboard shortcut, Control + U, to start the process of compilation of the source codes. The compiler compiles and next is a verification process for correctness and afterwards generates hex bytes codes which are then uploaded to the Atmel's AVR Atmega328P-microcontroller on the Arduino board.
Here is the Full Source Code
|
Source Code Explanation
The source code is explanatory enough
with comments describing functions used. The code begins with loading a message
or strings of character to a string variable which is to be displayed on the
seven segments LED unit.
Extending the Hardware
The code is designed to be scalable as
well as the hardware design to accommodate more cascades of segment LED
modules. Line 45, where a variable “noOfSegments” is used, can be incremented to
allow more LED seven segments unit to be added to the existing design.
To use the above code for Common Cathode seven segment LED units, all you need to do is to make minor changes to the source code above. The circuit architecture is the same for a Common Cathode as we have used for Common Anode.
To use the above code for Common Cathode seven segment LED units, all you need to do is to make minor changes to the source code above. The circuit architecture is the same for a Common Cathode as we have used for Common Anode.
Modifications to use
Common Cathode Segments LED
1. DisplayScreenFrame() function;
Change frameTemp = 0x01 to frameTemp
= 0xFE (inversion of 0x01) on line 113 of the source code above
2. In segmentScan() function;
change the whole function to the following:
void segmentScan()
{ // function scans each segments and loads segment
equiv on data pins (PORTD)
// scan six
(6) led 7 segments
frameCount = noOfSegments;
// point
to screen buffer location
// portB
pins are control signal byte
// portD
pins are data signal byte
// for
statement turns on one segment at a time for each of the six segments and also
// send
data to the data port (portD) one at a time
for
(frameCount = 0; frameCount < noOfSegments; frameCount++)//while (frameCount != 0)
{
// Turn off control pins
PORTB = 0xFF; // inverted to use Common Cathode (CC)
// Point to one character and get the segment equivalent for that character
// Afterwards, send the segment equivalent to data pins (portD).
PORTD = getSegmentEquiv(screenBufferString[frameCount]);
// send control signal to turn on one segment
PORTB = frameTemp;
// shift the “on” scan bit for each of the six segments to the right by 1
// to turn a specific segment
// e.g 111110
// 111101
// 111011
// 110111
// 101111
//
011111
frameTemp <<= 1; // shift once to the left
// clear last bit in frametemp to prevent noise or glitches when displaying
bitSet(frameTemp, 0); // bitClear has been changed to bitSet for CC
// call shortdelay
shortDelay();
// clear portB control signals
PORTB =
0xFF; // inverted to use with CC
} // end
for
} // end scan
|
3. SevenSegmentEquiv() function; invert all segment hex values to get the equivalent for a common cathode.
Conclusion
If you observe, the circuit does not use resistors for connecting the Arduino I/O control/signal port-B pins (8 through 13) to the LED units because the LEDs lights up considerably bright enough, but a little dimness would be observed.
In my future project, I guess either episodes 3 or 4, we address hardware issues – brightness, power consumption, etc., and follow best practices for the hardware design.
If you observe, the circuit does not use resistors for connecting the Arduino I/O control/signal port-B pins (8 through 13) to the LED units because the LEDs lights up considerably bright enough, but a little dimness would be observed.
In my future project, I guess either episodes 3 or 4, we address hardware issues – brightness, power consumption, etc., and follow best practices for the hardware design.
At the moment, I am not so overly concerned about
power consumption, because the circuit will fly and lights up bright and neat.
If you are doubtful of drawing too much current or concerned about your control
or signal port pins frying, I would recommend you use resistors in series
with your jumpers. 100 ohms for your resistor value would be just fine.
Blink, blink, scrolling.. That's all!
You can do well to let me know if you have got any challenges in building the project.
Blink, blink, scrolling.. That's all!
You can do well to let me know if you have got any challenges in building the project.
Please feel free to leave comments or suggestions to improve the project, and also remember to share with your friends!
Downloads
SevenSegmentDisplay_ca.zip, this source code is for common anode static (non-scroll) display on the seven segment display LED units:
SevenSegmentTextScroll_ca.zip, this source code is for common anode scrolling texts.
https://sites.google.com/site/herculestechs/products/SegmentDisplaysScroll.rar?attredirects=0&d=1
SevenSegmentDisplay_cc.zip, source code for common cathode static (non-scroll) display on the seven segment LED units.
SevenSegmentDisplay_cc.zip, source code for common cathode static (non-scroll) display on the seven segment LED units.
https://sites.google.com/site/herculestechs/products/SegmentDisplays_cc.rar?attredirects=0&d=1
SevenSegmentTextScroll_cc.zip, this source code is for common cathode scrolling texts.
SevenSegmentTextScroll_cc.zip, this source code is for common cathode scrolling texts.
https://sites.google.com/site/herculestechs/products/SegmentDisplaysScroll_cc.rar?attredirects=0&d=1
Reference:
"Persistence of Vision," Microsoft Encarta, 2008.
"Multiplexing 7 segment displays with Arduino and Shift Registers," Kev O., http://www.instructables.com/id/Multiplexing-7-Segment-displays-with-Arduino-and-S/, Date Accessed: November 15, 2015.
Project License
This project is released under creative common license (http://creativecommons.org/licenses/) type - Attribution CC BY - which allow others to distribute, remix, tweak, and build upon the authors work, even commercially, as long as they credit the author for the original creation.
Please note further, that different projects published on this blog would use different licensing type, so readers of the blog are encouraged to read and understand the type of licenses projects are published and released under, and to adhere strictly to the authors licensing specifications for each projects.
Disclaimer/Caveat Emptor
Please note that the author does not and would not take responsibility for using this project in critical applications. The project was published for learning purposes and is especially targeted to those new to electronics. The above system is far from perfect, in terms of performance, and may/may not be reliable, and so the reason for the advise to not feature in a real life application. You may need to contact a professional whose system has been tested and trusted by certified standard organizations. For shorts, if you are going to use this design in real life, you will be doing that at your own risk.
Upcoming Projects Later This Month
- Temperature Sensor and Seven Segments Display System
- Common Anode Seven Segment Display Text Scroll (Ep. 2)
- LED 8x8 Matrix Display (Ep. 1)
- Animations on 8 x 8 LED Dot Matrix Display (Ep. 2)
Reference:
"Persistence of Vision," Microsoft Encarta, 2008.
"Multiplexing 7 segment displays with Arduino and Shift Registers," Kev O., http://www.instructables.com/id/Multiplexing-7-Segment-displays-with-Arduino-and-S/, Date Accessed: November 15, 2015.
Project License
This project is released under creative common license (http://creativecommons.org/licenses/) type - Attribution CC BY - which allow others to distribute, remix, tweak, and build upon the authors work, even commercially, as long as they credit the author for the original creation.
Please note further, that different projects published on this blog would use different licensing type, so readers of the blog are encouraged to read and understand the type of licenses projects are published and released under, and to adhere strictly to the authors licensing specifications for each projects.
Disclaimer/Caveat Emptor
Please note that the author does not and would not take responsibility for using this project in critical applications. The project was published for learning purposes and is especially targeted to those new to electronics. The above system is far from perfect, in terms of performance, and may/may not be reliable, and so the reason for the advise to not feature in a real life application. You may need to contact a professional whose system has been tested and trusted by certified standard organizations. For shorts, if you are going to use this design in real life, you will be doing that at your own risk.
Nice piece... add some local price listing to give an idea of project cost
ReplyDeletepassword sketch
ReplyDeleteVery cool! I must do this. Thanks for posting such complete instructions.
ReplyDeletehere
Thanks for a very interesting blog. What else may I get that kind of info written in such a perfect approach? I’ve a undertaking that I am simply now operating on, and I have been at the look out for such info. Cover Pump
ReplyDeleteThank you because you have been willing to share information with us. we will always appreciate all you have done here because I know you are very concerned with our. TV BF Deals
ReplyDeleteplease share common cathode char set.
ReplyDeleteThanks
ReplyDeleteERROR 302 IN ARDUINO 😥
5. Thanks for the informative article This is one of the best resources I have found
ReplyDeleteIn quite some time. Nicely written and great info. I really cannot thank you enough
For sharing.
Visit this page
I like this information .I would like to ask one question that how can we quickly and easily do blog commenting .because with one blogger id it will go to approval with moderator
ReplyDeleteover here
I have read your blog it’s very attractive and impressive. I like it your blog.
ReplyDeleteClick for this