Table of Contents
Raspberry Pi 7 segment display, Overview:
Raspberry Pi 7 Segment display interfacing and programming– In this article you will learn how to use a 7 segment display with Raspberry Pi. As this article is for the beginners, so I will try to explain each and every detail. I have a very detailed tutorial on how to use the common anode and common cathode type 7 segment displays with Arduino. So, the basic working of the 7 segment displays I have already explained, which covers how 7 segment displays work, how the LEDs are internally connected, how to interface the common anode and common cathode type 7 segment displays. I highly recommend you should read this article.
In this article, I will not use the single display 7 segment module, but I will use the multiplexed type 7 segment display module. For this article I selected the Adafruit 4-digit 7-Segment display Backpack. Before, I am going to explain the interfacing and Raspberry Pi code. First I would like to explain the 7 segment display module used in this article.
Amazon Purchase Links:
Other Tools and Components:
*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!
What’s better than a single LED? Lots of LEDs! A great method to make a little display is to utilize an 8×8 matrix or a 4-digit 7-segment display. Matrices like these are ‘multiplexed’ – so to control all the seven-segment LEDs you require 14 pins. That is a ton of pins, and there are driver chips like the MAX7219 that can control a matrix for you yet there’s a great deal of wiring to set up and they occupy a huge load of room, in simple words, takes the maximum I/O pins, which is something that we really don’t want. Here at Electronic Clinic we sympathize with your torment! All things considered, wouldn’t it be wonderful in the event that you could control a matrix without huge loads of wiring? That is the place where these cute LED matrix backpacks come in. We have them in two flavors – a mini 8×8 and a 4-digit 0.56″ 7-segment. They work impeccably with the matrices.
The matrices utilize a driver chip HT16K33 that does all the hard work for you: They have a built in clock so they multiplex the display. They utilize steady current drivers for ultra-bright, consistent color
The picture above is shot at the dimmest setting to try not to over-burden the camera!, 1/16 step display dimming, all through a straightforward I2C interface. The backpacks accompany address-selection jumpers so you can interface up to four mini 8×8’s or eight 7-segments (or a combination, for example, four mini 8×8’s and four 7-segments, and so on) on a single I2C bus. These display are available in different colors.
The item unit accompanies:
- A completely tried and assembled LED rucksack
- Ultra-bright 4-digit 0.56″ tall yellow seven-segment display
- 4-pin header
A bit of soldering is needed to join the matrix onto the backpack yet its extremely simple to do and just takes around 5 minutes.
Adafruit 4-digit 7-Segment display Backpack Pinout and Specs:
You can clearly see the top and bottom sides, the coin is only for the size comparison. As compared to the other multiplexed 7 segment displays, the Adafruit 7 segment display doesn’t require a lot of wires. This 7 segment display supports the I2C communication and you can connect multiple of these display modules with the Raspberry Pi, Arduino, ESP8266, ESP32, etc. So you need only two wires to interface this 7 segment display module with the Raspberry Pi.
This board/chip uses I2C 7-bit address between 0x70-0x77, selectable with jumpers
Backpack Dimensions: 27mm x 50mm x 4mm / 1.1″ x 2″ x 0.16″
Backpack Weight: 5.3g
7-Segment Display Dimensions: 19mm x 50mm x 14mm / 0.75″ x 2″ x 0.56″
7-Segment Display Weight: 8.4g
As this is a readymade 7 segment display module so you don’t need to be worried about, if the 7 segment displays are of the type Anode or Cathode. All you need is to connect the SCL and SDA wires, and of course the VCC and GND pins to power up the display.
it is possible to use seven LED segments to display any number and to represent every letter of the alphabet, excluding umlauts. We use the Adafruit 7-segment LED backpack. This display has four Digits. That means you can represent a maximum of four digits or letters. Additionally there is the option of adding a colon in the middle as well as after each post display a decimal point.
We chose the model above because it has an I2C interface. Older 7-segment displays mostly used a line for each segment. This often ends in a huge mess of wires. With four digits without port expansion – even run out of the available GPIOs of the Raspberry Pi. But as explained earlier the Adafruit 4-digit 7 segment display module needs only two wires in order to connect it with the Raspberry Pi and all this is possible just because of the HT16K33 controller which itself is developed by the Adafruit.
Before you can connect the display to the Raspberry Pi, solder the display on the controller board. You will easily find the correct orientation through the component print on the board. Likewise, solder the four header pinsinto the four Connection holes. The connection to the Raspberry Pi is simple.
- VCC with pin 3 (3.3 V)
- GND with pin 6
- SDA with pin 3
- SCL with pin 5
Do not be surprised: despite the supply voltage already present, this will Display nothing! However, check in a terminal window whether the Display was recognized at address 0x70 of the I2C bus. The output should be on the display at 0x70 (see Figure 1).
In order to use the above command and to operate the display. You should make sure that you have activated the I2C interface of the Raspberry Pi and have installed the smbus and i2ctools packages. If you don’t know how to activate the i2c on raspberry then read my previous articles.
To control via Python, you can again use a library from the extensive range Adafruit code collection. Download the code from GitHub, and then switch to the folder containing the library for the 7-segment display contains:
sudo apt – get install git
git clone https: // github. com / adafruit / Adafruit – Raspberry -Pi –
cd Adafruit – Raspberry -Pi – Python – Code
Now copy the two files Adafruit_LEDBackpack.py and Adafruit_7-Segment.py in the directory in which you will store your future Python program want. This is necessary so that you can easily import the two libraries into your program can. In the example program, we set the current CPU temperature on the 7-segment Display that updates every second. We’re using Python 2.x here, there the Adafruit code collection has not yet been adapted to Python 3.
#! / usr / bin / python # coding = utf -8 from Adafruit_7Segment import SevenSegment import commands, time segment = SevenSegment (address = 0x70) while True: temp = commands. getoutput ("/ opt / vc / bin / vcgencmd measure_temp") segment.writeDigit (0, int (temp )) segment.writeDigit (1, int (temp ), 1) segment.setColon (0) # colon segment.writeDigit (3, int (temp )) # segment.writeDigit (4, 5) time. sleep (1)
We would like to explain some of the basic functions of the program to you in the following.
segment = SevenSegment (address = 0x70) specifies the address at which the display can be addressed is. Characters are represented in the writeDigit () functions. Define them as follows:
segment.writeDigit (digit, character, period)
The Position parameter determines at which position on the display the character is shown shall be. Please note this order:
- 0 = position 1
- 1 = position 2
- 3 = colon
- 4 = position 3
- 5 = position 4
For you this means that you can only use the digits 0, 1, 4 and 5 in the writeDigit () function. The colon has its own function, which we will explain later. In the character parameter, pass the number to be displayed as an integer Value. In order to display a decimal point after one of the four digits, pass In the Point parameter you also add a 1. If you do not want a decimal point, so you can simply omit this value. The colon in the middle of the display can e.g. B. when displaying a time can be used. Use the segment.setColon (1) function for this. A 1 places the colon, a 0 or omitting the function makes it go out. However, the library only supports rendering in the manner described above the numbers 0 to 9. But you have the option of adding your own characters handcraft. To do this, use the function writeDigitRaw (position, character). this function now expects a specially assembled character shape. Like this works, we would like to explain to you.
Let’s start by depicting the letter A. Look at the seven segments of a digit, the following segments should light up for an A:
- top left
- top right
- bottom left
- bottom right
The addresses of the individual segments are arranged according to this scheme:
- 1 = above
- 2 = top right
- 4 = bottom right
- 8 = down
- 16 = bottom left
- 32 = top left
- 64 = middle
In order to represent the A, add the required segment addresses:
A = 1 + 2 + 4 + 16 + 32 + 64
The result of this calculation is 119. You pass this value in the parameter Character. The complete function for your self-built A on Digit 1 reads like this: segment.writeDigitRaw(0, 119). You can also transfer the address as a hex value, in this case it is 0x77. You can now display any character that can be created from seven segments.