Some links in this post may be affiliate links. We may get paid if you buy something or take an action after clicking one of these, but without addictional costs for you compared to direct buying.

7 Segment Display And Raspberry PI Pico: Wiring and Setup with MicroPython

Raspberry PI Pico 7 segment display featured image
5
(1)

7 segment display can be controlled with a few Micropython lines from Raspberry PI Pico. It is one of simplest projects and a funny way to start coding and cabling

7 digit display

In this tutorial, I’m going t show you how to connect and configure a 7 segment display with a Raspberry PI Pico. If you are interested in how to get it working with Raspberry PI computer boards (like RPI Zero, RPI 4 model B, RPI 3 model A/B, and so on), please refer to my Control a 7 Segment Display from Raspberry PI with Python.

7 segment display is used within a wide number of applications, usually to single a display number. These devices have simple internal wiring diagrams, which maps one by one LEDs to its pins:

7 digit display pin

Please note that this tutorial uses a common cathode 7 segment display. This means that the common pins (3 and 8) go to the ground and each led segment is turned on when a positive value comes from RPI Pico. With common anode, the common Pind go to 3,3V and each led segment is turned on when a negative value comes from RPI Pico. In the second case, compared to my tutorial you will have to change 3 and 8 pins wiring them to Raspberry PI Pico physical pin 36 (3v3 OUT) and invert my code logic.

What We Need

As usual, I suggest adding from now to your favorite e-commerce shopping cart all needed hardware, so that at the end you will be able to evaluate overall costs and decide if continue with the project or remove them from the shopping cart. So, hardware will be only:

raspberry pi pico microcontroller

Many of the listed hardware (except Raspberry PI Pico) can be bought alone or can be also found in the useful Elegoo starter kit.

Check hardware prices with the following links:

Amazon raspberry pi boards box
amazon raspberry pi pico box
Amazon Resistors box
Amazon Breadboard box
Amazon Dupont Wiring box

Step-by-Step Procedure

Wiring Diagram

Prepare cabling according to the following wiring diagram. Regarding Raspberry PI Pico pinout, you can refer my guide showing it: Raspberry PI Pico pinout

Raspberry PI Pico 7 segment display wiring diagram

This wiring produces the following mapping between Display and Raspberry PI:

Display SegmentDisplay PinRaspberry PI Pico GP pin
A717
B616
C414
D213
E112
F918
G1019
DP515
GRD3GND
GRD8GND

So, each Raspberry PI Pico pin powers a specific Led segment. Powering together a defined sequence of segments will display the number we want to show.

Please find below some pictures from my home lab:

Raspberry PI Pico 7 segment display details 01
Raspberry PI Pico 7 segment display details 02
Raspberry PI Pico 7 segment display details 03
Raspberry PI Pico 7 segment display details 04
Raspberry PI Pico 7 segment display details 05

Prepare cabling according to the previous paragraph.

Get and Understand my rpiPicoSegDisplay.py Code

Connect RPI Pico to Thonny (you can refer to my tutorial about the First steps with Raspberry PI Pico).

Now download the following file to use your passive buzzer:

You can both load it in your Raspberry PI Pico storage or run it from your computer.

I’ll explain all code lines in the following paragraphs.

First of all, we import required libraries:

from machine import Pin

Then we define 2 variables with Pin numbers. This is a convenient way as, if you need to change wirings, you can set new GP numbers here instead of spreading around in our code. display_list collects all segments pins, ordered so that they will match A, B, C, D, E, F and G LED segments:

display_list = [17,16,14,13,12,18,19]
dotPin=15

We’ll use arrays to make our code as shorter as possible. One of these arrays will collect the PIN objects. This array is first declared and then filled with a for loop which also set pins to out mode:

display_obj = []

for seg in display_list:
    display_obj.append(Pin(seg, Pin.OUT))

Same PIN setting also for the one connected to the dot LED:

dot_obj=Pin(dotPin, Pin.OUT)

Another array variable keeps a mapping of numbers with their LED configuration. For example, the number 0 (zero) has all the LED on, except the central segment (G). This will be represented by the arrSeg[0] that maps the “1,1,1,1,1,1,0” as A=1,B=1,C=1,D=1,E=1,F=1,G=0. Same logic for all other numbers:

arrSeg = [[1,1,1,1,1,1,0],\ # -> arrSeq[0] displays 0
          [0,1,1,0,0,0,0],\ # -> arrSeq[1] displays 1
          [1,1,0,1,1,0,1],\ # -> arrSeq[2] displays 2
          [1,1,1,1,0,0,1],\ # -> arrSeq[3] displays 3
          [0,1,1,0,0,1,1],\ # -> arrSeq[4] displays 4
          [1,0,1,1,0,1,1],\ # -> arrSeq[5] displays 5
          [1,0,1,1,1,1,1],\ # -> arrSeq[6] displays 6
          [1,1,1,0,0,0,0],\ # -> arrSeq[7] displays 7
          [1,1,1,1,1,1,1],\ # -> arrSeq[8] displays 8
          [1,1,1,1,0,1,1]]  # -> arrSeq[9] displays 9

Here I use a function to control the 7 segment display so that calling this function with a string representing what number we want to show (with or without the dot). This function starts converting what is received into a number (int() function) and removing the trailing dot (“.”), if present. In this way the numDisplay variable is an integer number and can be used in following for loop to configure pins output:

def SegDisplay(toDisplay):
    numDisplay = int(toDisplay.replace(".", ""))
    for a in range(7):
        display_obj[a].value(arrSeg[numDisplay][a])

Still inside the SegDisplay() function, we also manage the dot led activation by checking if the “.” is present in the input value:

    if toDisplay.count(".") == 1:
        dot_obj.value(1)
    else:
        dot_obj.value(0)

Finally, we use our function by calling it with the desired output. For example, number five with the dot led on will be call with following:

SegDisplay("5.")

If we don’t want the dot, simply call in this way:

SegDisplay("5")

The number can vary from 0 to 9 and the parameter needs to be a string. If you have integer numbers, you can use the str() function to convert them. An example:

SegDisplay(str(5))

Enjoy!

How useful was this post?

Click on a star to rate it anonymously!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Leave a Reply

Your email address will not be published. Required fields are marked *

I accept the Privacy Policy