← Back to list

How to Use a 7-Segment Display with Raspberry Pi Pico and MicroPython

Introduction

Bruno Vilardi Bueno · 2026-03-11 21:59 · 3 claps · 6.7 min read
#micropython #7-segment-display #raspberry-pi-pico #upython #python
Open on Medium ↗
Wiki topics: 📟 · Gadgets & IoT

How to Use a 7-Segment Display with Raspberry Pi Pico and MicroPython

Introduction

7-segment displays are widely used electronic components for showing numbers and, in some cases, a few alphanumeric characters in all kinds of electronics projects. In this article, you will learn how to configure one using the Raspberry Pi Pico, including the different types of displays and a Python implementation for driving a numeric display.

What Is a 7-Segment Display?

A 7-segment display is made up of seven LEDs arranged in the shape of the number 8, where each LED represents a “segment” that can be turned on or off to form different characters. These LEDs are usually labeled from a to g.

7-segment display pinout

7-segment display pinout

In addition, some displays also include a decimal point (DP), which is useful when combining multiple displays to show decimal numbers. For example, by connecting 3 displays together, you could show values from 00 to 99 with one decimal place (such as 25.6, 99.4, or 01.5).

Common Anode vs. Common Cathode

7-segment displays are generally classified as either common anode or common cathode, depending on how the LEDs are internally connected:

Common Anode: all LED anodes (positive terminals) are tied together in a single pin, while the cathodes (negative terminals) are controlled individually.

Common Cathode: all LED cathodes (negative terminals) are tied together in a single pin, while the anodes are controlled individually.

Why Is It Important to Identify Your Display Type?

Knowing whether your display is common anode or common cathode is essential for wiring the circuit and programming the Raspberry Pi Pico correctly. If you use the wrong connection type, the display may not work as expected or could even be damaged.

The main differences are summarized below:

Comparison table: Common Anode vs. Common Cathode

Comparison table: Common Anode vs. Common Cathode

In other words, it is extremely important to identify the correct type of your 7-segment display before making the connections.

How to Identify the Display Type

The easiest way is to check the display’s datasheet.

If you do not have access to the datasheet, you can still identify the display safely through testing by following these steps.

Prepare the equipment

Use a low-voltage source (3.3V or 5V) and 220 Ω resistors to limit current and protect the display LEDs.

Test the pins

Choose one of the common pins (usually labeled COM) and connect it either to VCC or GND, depending on the test.

Then, using the other terminal of the power source, touch the segment pins (a, b, c, and so on).

Whenever you test a connection between a pin and GND, you should always use a resistor.

Observe the behavior

  • If the segments light up when the common pin is connected to VCC, the display is common anode
  • If the segments light up when the common pin is connected to GND, the display is common cathode

How Do You Display Numbers on a 7-Segment Display?

A 7-segment display is nothing more than a group of LEDs. That means that, to form numbers, you simply turn on the correct segments for each digit, as shown below.

Enabled segments used to form numbers

Enabled segments used to form numbers

To make things easier, you can use a truth table that defines which segments must be active for each number.

For example, if you want to display the number 9, you need to activate segments a, b, c, f, and g, while leaving d and e turned off.

Keep in mind that whether 1 or 0 means “on” or “off” depends on whether the display is common anode or common cathode.

Wiring the Circuit with Raspberry Pi Pico

The Raspberry Pi Pico is a microcontroller with 29 GPIO pins, numbered from GP0 to GP28, in addition to power and ground pins. In this project, we will use GPIO pins to control each segment of the display.

Raspberry Pi Pico pinout

Raspberry Pi Pico pinout

In practice, you just need to connect each display segment to a GPIO pin and connect the common pins to GND or VCC, depending on the display type.

In my case, I used a common anode 7-segment display, so the COM pins were connected to VCC, and each segment was connected to a Raspberry Pi Pico GPIO pin through a resistor.

Circuit wiring with Raspberry Pi Pico, 5011BS 7-segment display, and 220-ohm resistors. On the right is the pin mapping used.

Circuit wiring with Raspberry Pi Pico, 5011BS 7-segment display, and 220-ohm resistors. On the right is the pin mapping used.

Code Implementation to Control the Display

The code is basically a Python class that defines the pins and, when given a number as input, turns the correct segments on and off.

from machine import Pin
class SSD_5011BS:
  """Seven Segment Display 5011BS.
  This is a display that has each connection to a segment of the display (a-g) and the dot.
  """
  NUMBER_MAP = {
        0: {"a": 1, "b": 1, "c": 1, "d": 1, "e": 1, "f": 1, "g": 0, "dot": 0},
        1: {"a": 0, "b": 1, "c": 1, "d": 0, "e": 0, "f": 0, "g": 0, "dot": 0},
        2: {"a": 1, "b": 1, "c": 0, "d": 1, "e": 1, "f": 0, "g": 1, "dot": 0},
        3: {"a": 1, "b": 1, "c": 1, "d": 1, "e": 0, "f": 0, "g": 1, "dot": 0},
        4: {"a": 0, "b": 1, "c": 1, "d": 0, "e": 0, "f": 1, "g": 1, "dot": 0},
        5: {"a": 1, "b": 0, "c": 1, "d": 1, "e": 0, "f": 1, "g": 1, "dot": 0},
        6: {"a": 1, "b": 0, "c": 1, "d": 1, "e": 1, "f": 1, "g": 1, "dot": 0},
        7: {"a": 1, "b": 1, "c": 1, "d": 0, "e": 0, "f": 0, "g": 0, "dot": 0},
        8: {"a": 1, "b": 1, "c": 1, "d": 1, "e": 1, "f": 1, "g": 1, "dot": 0},
        9: {"a": 1, "b": 1, "c": 1, "d": 1, "e": 0, "f": 1, "g": 1, "dot": 0}
    }
  segments: dict
  def __init__(self, a: int = 19, b: int = 18, c: int = 12, d: int = 15, e: int = 14, f: int = 16, g: int = 17, dot: int = 13, common_cathode: bool = True):
      """Constructor
      @param a: The number of the pin where the a segment is connected.
      @param b: The number of the pin where the b segment is connected.
      @param c: The number of the pin where the c segment is connected.
      @param d: The number of the pin where the d segment is connected.
      @param e: The number of the pin where the e segment is connected.
      @param f: The number of the pin where the f segment is connected.
      @param g: The number of the pin where the g segment is connected.
      @param dot: The number of the pin where the dot is connected.
      """
      self.segments = {
          "a": Pin(a, Pin.OUT),
          "b": Pin(b, Pin.OUT),
          "c": Pin(c, Pin.OUT),
          "d": Pin(d, Pin.OUT),
          "e": Pin(e, Pin.OUT),
          "f": Pin(f, Pin.OUT),
          "g": Pin(g, Pin.OUT),
          "dot": Pin(dot, Pin.OUT)
      }
      self.common_cathode = common_cathode
      self.set_number(0)  # default value

  def set_number(self, number: int):
      """Set the number to display
      @param number: The number to display. Must be between 0 and 9.
      """
      if number < 0 or number > 9:
          raise ValueError("Number must be between 0 and 9")
      for i in self.segments:
          # Get correct value
          value = self.NUMBER_MAP[number][i]
          # Invert the value if it is common anode
          value = value if self.common_cathode else not value
          # Set the value
          self.segments[i].value(value)

  def get_state(self):
      sorted_segments = list(self.segments.keys())
      sorted_segments.sort()
      for seg in sorted_segments:
          print(f"{seg} = {self.segments[seg].value()}")
  def set_decimal_point(self, state: bool):
      """Set the state of the decimal point
      @param state: True to turn the decimal point on, False to turn it off
      """
      self.segments["dot"].value(state if self.common_cathode else not state)

After that, you just need to instantiate the class:

display = SSD_5011BS(common_cathode=False)
for i in range(10):
    display.set_number(i)
    time.sleep(1)

One important detail is the common_cathode argument in the class constructor. It indicates whether the display is common cathode, allowing the code to invert the logic levels when necessary so the correct number is displayed.

The final result looks like this:

Final result

Final result

Conclusion

In this article, you learned how to identify the type of your 7-segment display, configure the Raspberry Pi Pico pins, and implement a simple MicroPython script to display numbers on the screen.

With this foundation, you can expand the project to show counters, timers, or other types of numeric data.

One important note is that, in real-world applications, it is very common to use more than one 7-segment display to show larger numbers. Because of that, I am already working on a follow-up article about it, which should be published soon.

If you have any questions or ideas for improving this project, feel free to leave a comment.

uPython Project

This is the first device in the uPython project I am developing. uPython will basically be a library containing code for controlling different electronic devices using MicroPython on the Raspberry Pi Pico.

If you want to learn more or contribute, the entire codebase is open source and available here:

[https://github.com/Brvilardi/uPython](https://github.com/Brvilardi/uPython)

References

[https://www.electronics-tutorials.ws/blog/7-segment-display-tutorial.html](https://www.electronics-tutorials.ws/blog/7-segment-display-tutorial.html)


메타데이터
post_id
7b7fa313fcc7
slug
how-to-use-a-7-segment-display-with-raspberry-pi-pico-and-micropython-7b7fa313fcc7
url
https://medium.com/@brunovilardibueno/how-to-use-a-7-segment-display-with-raspberry-pi-pico-and-micropython-7b7fa313fcc7
canonical_url
https://medium.com/@brunovilardibueno/how-to-use-a-7-segment-display-with-raspberry-pi-pico-and-micropython-7b7fa313fcc7
author_url
https://medium.com/@brunovilardibueno
status
ok
fetched_at
2026-07-14 07:42:55