element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
7-Segment Display
  • Challenges & Projects
  • Project14
  • 7-Segment Display
  • More
  • Cancel
7-Segment Display
Blog Pi Pico with 7-segment display and 74LS47 chip
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: ntewinkel
  • Date Created: 27 May 2022 10:23 PM Date Created
  • Views 14892 views
  • Likes 5 likes
  • Comments 0 comments
  • raspberry pi pico
  • 7-segment display
  • 74ls47
  • 7segmentdisplaysch
  • pi pico
Related
Recommended

Pi Pico with 7-segment display and 74LS47 chip

ntewinkel
ntewinkel
27 May 2022

As I mentioned in my previous blog post, Pi Pico with 7-segment display, I decided to try using a 74LS47 chip to handle the logic of converting a number in code into a 7-segment digit.

7-segment pi pico 74ls47

Newark Canada sells these chips. I think the 2 types might give different "fonts" - the one I have doesn't have the extra tail on the 6 and 9, for example... I'm not 100% sure, but I think I saw a little detail saying it's a chip-variation thing rather than a chip-pin-selection.
Here's one: https://canada.newark.com/texas-instruments/sn74ls47n/logic-bcd-7-seg-decod-drvr-16dip/dp/37AJ1160?st=74ls47

Texas Instruments has the spec sheet on their website: https://www.ti.com/lit/ds/symlink/sn5447a.pdf

But really, these things have been around for so long that a quick online search will give you all the information you need very quickly.

So I won't bother repeating all those details :D

In a nutshell, the 7 wires that were originally going from the Pi Pico to the 7-segment display are now going from the corresponding pins on the 74ls47 chip to the display, and the Pi Pico now only has to use 4 wires to display a digit, plus 1 wire to blank the display if desired.
This means that the hardware portion of this project has just gotten a little more complicated - an extra chip and 5 extra wires to figure out.
However, the big gains are in the software: the code can now quite easily convert a digit into the 4 bits that the 74LS47 expects, and we save a lot of extra table effort. But it does require some extra math for that conversion.

#
# Basic 7-segment display test
#

from machine import Pin
import time


# For my 7-segment display, the common wire connects to VCC
#  -> Note that this means we have to turn a pin "off" to light the segment LED, and "on" to turn it off
# The 3.3v pin 36, combined with 220R resistors light the segments well enough
# You can test the display by using a small 3.3v button battery (CR2032 seems cheap and plentiful)
# Hopefully the display you have will have a model number you can look up to find the pinout.

# We are using a 74LS47 decoder chip to run the 7 segment display
# That means the Pi Pico only needs to send a binary number to the decoder chip to show a digit.

# Define the segment GPIO connections
# hook up the wires to the decoder chip as per the defined constants below
# Use a current limiting resistor for each segment (you'll need 7!) between the decoder chip and the display.
# The resistors are also necessary to keep a constant brightness on the display
INPUT_A_PIN = 12
INPUT_B_PIN = 13
INPUT_C_PIN = 14
INPUT_D_PIN = 15

BLANK_DISPLAY_PIN = 16


# I'm not using the 2 dots for this example, but they would simply add another GPIO pin each.
# The dots would need to be directly controlled, same as without the decoder chip.

def setup():
    # Define each segment
    global INPUT_A, INPUT_B, INPUT_C, INPUT_D, BLANK_DISPLAY
    
    INPUT_A = Pin(INPUT_A_PIN, Pin.OUT)
    INPUT_B = Pin(INPUT_B_PIN, Pin.OUT)
    INPUT_C = Pin(INPUT_C_PIN, Pin.OUT)
    INPUT_D = Pin(INPUT_D_PIN, Pin.OUT)
    
    BLANK_DISPLAY = Pin(BLANK_DISPLAY_PIN, Pin.OUT)
    
def getBits(digit):
    #if digit > 9 or digit < 0
    #    return [] #error - blank array
    d = digit
    bit1 = d % 2
    d = d // 2
    bit2 = d % 2
    d = d // 2
    bit3 = d % 2
    d = d // 2
    bit4 = d % 2

    return [bit1, bit2, bit3, bit4]

def displayDigit(digit):
    # A is the least significant digit (aka, 1)
    bits = getBits(digit)
    
    INPUT_A.off()
    INPUT_B.off()
    INPUT_C.off()
    INPUT_D.off()

    if bits[0] > 0: INPUT_A.on()
    if bits[1] > 0: INPUT_B.on()
    if bits[2] > 0: INPUT_C.on()
    if bits[3] > 0: INPUT_D.on()
    
    BLANK_DISPLAY.on()


def displayOff():
    BLANK_DISPLAY.off()


# Start main code
setup()
        
while True:
    
    for digit in range(10):
        displayDigit(digit)
        time.sleep(0.5)

    displayOff()
    time.sleep(1)

I probably could have named that "BLANK_DISPLAY" pin a bit better - turning it "on" turns on the display, it doesn't blank it... so maybe "ACTIVATE_DISPLAY" would have been more clear? On the other hand, that's what they call the corresponding pin on the 74ls47 chip. I kind of think the chip might already also include a blank character allowance... like if you set all bits to 1 it might do that... I didn't play with it a whole lot.

Here is a little video of it running through the digits. Note that the digits look different than in my previous example, and I don't think there's a way to adjust the "font" without getting a different version of that chip.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

For my preference, and given the power of the Pi Pico, I prefer to just do the work in code and use the few extra GPIO pins - the Pi Pico has plenty of extra pins for this project, and I find the extra hardware is harder for me to deal with than the extra code, and the extra chip would ultimately also require a larger project case if I were to build it into a proper looking project.
I also prefer the straight-forward direct control rather than doing what is essentially bitwise math. That also allows me to control the digit font and gives me the extra benefit of expanding to include alphabetical characters if desired. But I've been a software guy for my entire life, so my bias will be towards using software wherever possible! Your mileage may vary, so do what feels best for you Slight smile

For my next step, that chip will be leaving the show, and I'll go back to the direct control way of my previous blog post - and I'll see about expanding this to a clock display with 4x 7-segment displays plus whatever extra that clock display has.

Stay tuned!

-Nico

Next: Testing the Clock Display (manually, no microcontroller needed)

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube