Raspberry Pi GPIO tutorial: 7 LED display



In this tutorial we'll learn how to manage a 7 LED Display 5161AS CC (Common Cathode) with our Raspberry Pi GPIO using Python. 

Materials:

- Raspberry Pi with Raspbian or similar

- 7 LED Display 5161AS CC (Common Cathode)

- 7x 1k resistors

- 8  wires male/female

- Breadboard

This is the code to control the 7 LED Display

import RPi.GPIO as GPIO
import time


# Segmentos:  a  b   c   d   e   f   g
PINS_LIST = [8, 11, 12, 13, 15, 16, 18]

GPIO.setmode(GPIO.BOARD)  # Configuramos el modo GPIO a BOARD para usar el número de PIN
GPIO.setup(PINS_LIST, GPIO.OUT, initial=GPIO.LOW)  # Preparamos todos los pins

char_dict = {
    0: (1, 1, 1, 1, 1, 1, 0),  # 0
    1: (0, 1, 1, 0, 0, 0, 0),  # 1
    2: (1, 1, 0, 1, 1, 0, 1),  # 2
    3: (1, 1, 1, 1, 0, 0, 1),  # 3
    4: (0, 1, 1, 0, 0, 1, 1),  # 4
    5: (1, 0, 1, 1, 0, 1, 1),  # 5
    6: (1, 0, 1, 1, 1, 1, 1),  # 6
    7: (1, 1, 1, 0, 0, 0, 0),  # 7
    8: (1, 1, 1, 1, 1, 1, 1),  # 8
    9: (1, 1, 1, 1, 0, 1, 1),  # 9
    'a': (1, 1, 1, 0, 1, 1, 1),  # A
    'c': (1, 0, 0, 1, 1, 1, 0),  # C
    'd': (0, 1, 1, 1, 1, 0, 1),  # d
    'e': (1, 0, 0, 1, 1, 1, 1),  # E
    'f': (1, 0, 0, 0, 1, 1, 1),  # F
    'h': (0, 1, 1, 0, 1, 1, 1),  # H
    'p': (1, 1, 0, 0, 1, 1, 1),  # P
    'u': (0, 1, 1, 1, 1, 1, 0),  # U
}

for key, value in sorted(char_dict.items()):
    GPIO.output(PINS_LIST, value)
    time.sleep(1)

GPIO.cleanup()  # Limpiamos el GPIO

Here you can see the circuit of the 7 LED Display

Here we can see the circuit between the 7 LED Display and the Raspberry PI GPIO

circuit_7led_cathode.png

Here you can see a video about how to assemble the circuit and run the code:

 

Remember! I use the GPIO mode BOARD, that means I always refer to the GPIO pins using their PIN number. If you uses GPIO in mode BCM you will need to translate the PIN numbers to GPIO number, you can use this GPIO pinout scheme to do that: Raspberry PI: GPIO pinout

Leave a comment

You have to wait to comment again. Wait Time: