{"id":1714,"date":"2020-04-17T07:40:49","date_gmt":"2020-04-17T07:40:49","guid":{"rendered":"http:\/\/www.sabulo.com\/sb\/?p=1714"},"modified":"2025-05-24T09:50:17","modified_gmt":"2025-05-24T07:50:17","slug":"using-7-segment-led-displays-part-3","status":"publish","type":"post","link":"https:\/\/www.sabulo.com\/sb\/arduino\/using-7-segment-led-displays-part-3\/","title":{"rendered":"Using 7 Segment LED displays, Part 3"},"content":{"rendered":"\n<p>This part concludes my foray into segmented LEDs. <a rel=\"noreferrer noopener\" aria-label=\"Part 1 showed you  (opens in a new tab)\" href=\"http:\/\/www.sabulo.com\/sb\/arduino\/using-7-segment-led-displays-part-1\/\" target=\"_blank\">Part 1 showed you <\/a>how to work with single digits, <a rel=\"noreferrer noopener\" aria-label=\"part 2 expanded into four digit (opens in a new tab)\" href=\"http:\/\/www.sabulo.com\/sb\/excel\/using-7-segment-led-displays-part-2\/\" target=\"_blank\">part 2 expanded into four digit<\/a>, one unit displays, and this one handles a system where you have four single digits acting as the four digits of part 2, only in much bigger size and with external power.<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/HeikkiHietala\/large-7-segment-led-display\" target=\"_blank\" rel=\"noreferrer noopener\">All code is available at my Github account<\/a>. Do check around for other projects too while there.<\/p>\n\n\n\n<p>The 74HC595 chip is great when you have small digits that can be powered through the Arduino, but in case you need large format LEDs, you will have to power them separately. In my case, I wanted to build the same clock as in Part 2, but with 4 inch digits. This device is the countdown clock in the escape room that our Business teachers are building here at Haaga-Helia University of Applied Sciences.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1840\" height=\"3264\" src=\"https:\/\/i2.wp.com\/www.sabulo.com\/sb\/wp-content\/uploads\/2019\/09\/IMG_20190815_132848.jpg?fit=577%2C1024\" alt=\"\" class=\"wp-image-1718\" srcset=\"https:\/\/i0.wp.com\/www.sabulo.com\/sb\/wp-content\/uploads\/2019\/09\/IMG_20190815_132848.jpg?w=1840&amp;ssl=1 1840w, https:\/\/i0.wp.com\/www.sabulo.com\/sb\/wp-content\/uploads\/2019\/09\/IMG_20190815_132848.jpg?resize=169%2C300&amp;ssl=1 169w, https:\/\/i0.wp.com\/www.sabulo.com\/sb\/wp-content\/uploads\/2019\/09\/IMG_20190815_132848.jpg?resize=768%2C1362&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.sabulo.com\/sb\/wp-content\/uploads\/2019\/09\/IMG_20190815_132848.jpg?resize=577%2C1024&amp;ssl=1 577w, https:\/\/i0.wp.com\/www.sabulo.com\/sb\/wp-content\/uploads\/2019\/09\/IMG_20190815_132848.jpg?w=1650&amp;ssl=1 1650w\" sizes=\"auto, (max-width: 825px) 100vw, 825px\" \/><figcaption class=\"wp-element-caption\">The first digit lit up<\/figcaption><\/figure>\n\n\n\n<p>I thought it&#8217;d be a simple and straightforward project to move from the small digits to these big ones, but it wasn&#8217;t that clear. First of all, you cannot use the same shift registers. For something that can handle larger currents and a 9-12V voltage, <a rel=\"noreferrer noopener\" aria-label=\"you need to buy TPIC6B595N  (opens in a new tab)\" href=\"https:\/\/www.ebay.com\/itm\/10pcs-TPIC6B595N-TPIC6B595-POWER-LOGIC-8-BIT-SHIFT-IC-\/181847073230\" target=\"_blank\">you need to buy TPIC6B595N <\/a>or similar. These are readily available at eBay as linked. Second, you must do some soldering to a power supply that you plan to use.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Connecting the TPIC chip<\/h2>\n\n\n\n<p>The new chips have a different footprint and pin order. It&#8217;s a 20 pin chip, but it sits nicely on a breadboard. <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/protosupplies.com\/wp-content\/uploads\/2018\/09\/TPIC6B595-Pinout.jpg?w=825&#038;ssl=1\" alt=\"TPIC6B595 Pinout\"\/><figcaption class=\"wp-element-caption\">source: Protosupplies, inc<\/figcaption><\/figure>\n<\/div>\n\n\n<ul class=\"wp-block-list\">\n<li>The Drain pins are connected to the LED segments, with 0 corresponding to A and 7 to G segment. <\/li>\n\n\n\n<li>Pins 2 and 8 receive +5V from Arduino<\/li>\n\n\n\n<li>Pins 10, 11 and 19 are grounded. <\/li>\n\n\n\n<li>Pin 3 is for data in, Arduino pin 11 in my code<\/li>\n\n\n\n<li>Pin 18 is for data out to the next shift register. It will enter pin 3 at the next shift register. Bear in mind there will be four of these in a chain so the last one will be left empty. <\/li>\n\n\n\n<li>Pins 1 and 20 are not connected<\/li>\n\n\n\n<li>Pin 9 is Output Enable, connected to Arduino pin 9 in my code<\/li>\n\n\n\n<li>Pin 12 is Latch, Arduino pin 10<\/li>\n\n\n\n<li>Pin 13 is Clock, Arduino pin 13<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Wiring the LEDs<\/h2>\n\n\n\n<p>For this project you can recycle an old power adapter, mine came from an ADSL that died. It gives out 18V and 1.5A, so it is very suitable. To adjust the voltage, I added <a rel=\"noreferrer noopener\" aria-label=\"a buck down regulator (opens in a new tab)\" href=\"http:\/\/www.sabulo.com\/sb\/8mm-film\/single-input-multiple-output-power-source-for-a-variety-of-needs\/\" target=\"_blank\">a buck down regulator<\/a> to adjust the voltage to suit the LEDs. You must make sure the adapter you want to use is suitable for Arduino, as you will share the power supply. <\/p>\n\n\n\n<p>I then cut the lead close to the connector, added two pinned wires to the big ones so as to get the power out at 12 volts before it enters the Arduino and gets regulated to 5V. Of the small wires, the red is connected to the red rail of the breadboard, and the black to Arduino&#8217;s ground to make sure it is shared among the Arduino and the digits. Make sure the solder jobs are solid and that you use insulation around the connections.<\/p>\n\n\n\n<p>Each segment of each of the four digits needs to have a 220 ohm resistor in the segment wires, so I cut the female-male wires and added a resistor with insulation on each, so that&#8217;s a 32 x solder job. The segments from each display digits are led to the TPIC6B595 chips as shown above. The common anodes 3 and 8 are led to the red rail of the breadboard receiving the 12 volts.<\/p>\n\n\n\n<p>With this complete, let&#8217;s look at the code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Arduino program<\/h2>\n\n\n\n<p>This application works by sending numbers as bytes to the shift registers. The shift register is latched open, byte data is passed to it, and when the latch closes, the shift register turns the byte into lit and unlit segments, displaying a number. Since we are using four chained registers, we will send the bytes in a certain order, and the registers will overflow until all of them have one byte. <\/p>\n\n\n\n<p>For constructing the numbers, there are two byte tables. One is for the numbers without a decimal point, but the second number must show a decimal point to separate minutes from seconds. They look like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">const byte numTable[] =\n{\n  B11111100,  \/\/numeral 0\n  B01100000,  \/\/numeral 1\n  B11011010,  \/\/numeral 2\n  B11110010,  \/\/numeral 3\n  B01100110,  \/\/numeral 4\n  B10110110,  \/\/numeral 5\n  B10111110,  \/\/numeral 6\n  B11100000,  \/\/numeral 7\n  B11111110,  \/\/numeral 8\n  B11110110   \/\/numeral 9\n};<\/pre>\n\n\n\n<p>and the decimal point one is <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">const byte numTableDP[] =\n{\n  B11111101,  \/\/numeral 0\n  B01100001,  \/\/numeral 1\n  B11011011,  \/\/numeral 2\n  B11110011,  \/\/numeral 3\n  B01100111,  \/\/numeral 4\n  B10110111,  \/\/numeral 5\n  B10111111,  \/\/numeral 6\n  B11100001,  \/\/numeral 7\n  B11111111,  \/\/numeral 8\n  B11110111   \/\/numeral 9\n};<\/pre>\n\n\n\n<p>The difference is the final bit of the numerals, as you can see. If it&#8217;s 0, no decimal point, if a 1, there is a decimal point. Numbers are picked from the array much in <a aria-label=\"the same way as in the previous application (opens in a new tab)\" href=\"http:\/\/www.sabulo.com\/sb\/excel\/using-7-segment-led-displays-part-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">the same way as in the previous application<\/a>, indeed this is very close to that one, but the data is sent in a different way. You will send it in four bytes, using this function send7segs():<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">void send7segs(){ \n  digitalWrite(_7segLATCH,LOW);    \/\/Open shift registers for data\n  shiftOut(_7segDOUT,_7segCLK,LSBFIRST,numTable[q]);   \/\/send fourth digit\n  shiftOut(_7segDOUT,_7segCLK,LSBFIRST,numTable[z]);   \/\/send third digit\n  shiftOut(_7segDOUT,_7segCLK,LSBFIRST,numTableDP[y]); \/\/send second  \n                                                       \/\/digit with dp\n  shiftOut(_7segDOUT,_7segCLK,LSBFIRST,numTable[x]);   \/\/send first digit\n  digitalWrite(_7segLATCH,HIGH);                       \/\/end the transfer \n                                                       \/\/of data<\/pre>\n\n\n\n<p>The second digit needs to show the decimal point, hence the byte is picked from a different table. Of course, you could do some bit arithmetics here and use just one table, but this method came to my mind first and worked, so I decided to go with it. The values x, y, z and q are derived from the remaining seconds as seen here in the main loop:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">void loop(){\n if(digitalRead(doorPin)==LOW){  \/\/ while the switch at pin 3 is closed, this\n                                 \/\/ will run\n     second--;                   \/\/ second minus 1\n   if (second==0) {              \/\/ handling the time out issue\n     second = 2701;              \/\/ restarting at 45:01\n   }\n   mins = int(second\/60);        \/\/ minutes as 45, 44, 43\u2026\n   secs = int(second % 60);      \/\/ seconds of every minute\n   splitmins1 = int(mins \/ 10);  \/\/ first digit of minutes\n   splitmins2 = int(mins % 10);  \/\/ second digit of minutes\n   splitsecs1 = int(secs \/ 10);  \/\/ first digit of seconds\n   splitsecs2 = int(secs % 10);  \/\/ second digit of seconds\n\n   x = splitmins1; \/\/ index for first digit hexcode from num array\n   y = splitmins2; \/\/ index for second digit hexcode from num array\n   z = splitsecs1; \/\/ index for third digit hexcode from num array\n   q = splitsecs2; \/\/ index for fourth digit hexcode from num array\n   }\n   else {                          \/\/ switch opens, the clock \n                                   \/\/ shows the time left at opening\n     delay(10);\n   }\n   send7segs();\n   delay(1000);\n   }<\/pre>\n\n\n\n<p>The whole <a href=\"https:\/\/github.com\/HeikkiHietala\/large-7-segment-led-display\" target=\"_blank\" rel=\"noreferrer noopener\">code is available on Github<\/a>. The only thing I haven&#8217;t explained is a function called <strong>void clear_7segA()<\/strong>, but all it does is clear all the attached digits.<\/p>\n\n\n\n<p>I hope you will find this foray into segmented LEDs useful. I certainly learned a lot while doing this project.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"4 inch, single digit LED Countdown clock\" width=\"825\" height=\"619\" src=\"https:\/\/www.youtube.com\/embed\/i9dO-dGZF3w?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><figcaption class=\"wp-element-caption\">It works!<\/figcaption><\/figure>\n\n\n\n<p><\/p>\n<div class=\"pvc_clear\"><\/div><p id=\"pvc_stats_1714\" class=\"pvc_stats all  \" data-element-id=\"1714\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/i0.wp.com\/www.sabulo.com\/sb\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif?resize=16%2C16&#038;ssl=1\" border=0 \/><\/p><div class=\"pvc_clear\"><\/div>","protected":false},"excerpt":{"rendered":"<p>This part concludes my foray into segmented LEDs. Part 1 showed you how to work with single digits, part 2 &hellip; <a href=\"https:\/\/www.sabulo.com\/sb\/arduino\/using-7-segment-led-displays-part-3\/\" class=\"more-link\">More <span class=\"screen-reader-text\">Using 7 Segment LED displays, Part 3<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_1714\" class=\"pvc_stats all  \" data-element-id=\"1714\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/www.sabulo.com\/sb\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[80,48,61,79,88,90],"tags":[],"class_list":["post-1714","post","type-post","status-publish","format-standard","hentry","category-7-segment-display","category-arduino","category-buck-down-converters","category-led","category-shift-registers","category-tpic6b595n"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6vhqE-rE","_links":{"self":[{"href":"https:\/\/www.sabulo.com\/sb\/wp-json\/wp\/v2\/posts\/1714","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sabulo.com\/sb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sabulo.com\/sb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sabulo.com\/sb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sabulo.com\/sb\/wp-json\/wp\/v2\/comments?post=1714"}],"version-history":[{"count":7,"href":"https:\/\/www.sabulo.com\/sb\/wp-json\/wp\/v2\/posts\/1714\/revisions"}],"predecessor-version":[{"id":2179,"href":"https:\/\/www.sabulo.com\/sb\/wp-json\/wp\/v2\/posts\/1714\/revisions\/2179"}],"wp:attachment":[{"href":"https:\/\/www.sabulo.com\/sb\/wp-json\/wp\/v2\/media?parent=1714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sabulo.com\/sb\/wp-json\/wp\/v2\/categories?post=1714"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sabulo.com\/sb\/wp-json\/wp\/v2\/tags?post=1714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}