# Matrix and 7-Segment LED Backpack with the Raspberry Pi

## Overview

Info: 

LED backpack displays are a great way to add a simple, bright LED display to your project. These displays get their name because of the controller chip attached to the back of them like a 'backpack'. This HT16K33 controller can drive up to 128 multiplexed LEDs in matrix, bar graph, 7-segment numeric, and even 14-segment alpha-numeric configurations. It handles the LEDs with a constant-current driver so the light is bright and consistent even if the power supply varies.

While we already have a&nbsp;[great tutorial](http://learn.adafruit.com/adafruit-led-backpack)&nbsp;and&nbsp;[Arduino library](https://github.com/adafruit/Adafruit-LED-Backpack-Library "Link: https://github.com/adafruit/Adafruit-LED-Backpack-Library")&nbsp;for&nbsp;our handy and easy to use LED backpacks, if you're wondering how you can make use of backpack-enabled LED&nbsp;displays on the Pi, this guide will help you get started!

![](https://cdn-learn.adafruit.com/assets/assets/000/001/857/medium800/raspberry_pi_LEDBackpack_Setup_1000w.jpg?1396776852)

# What You'll Need

1. A [Raspberry Pi](https://www.adafruit.com/product/3775)
2. A [Pi Cobbler Plus](https://www.adafruit.com/product/2029)
3. One of our many [8x8](https://www.adafruit.com/category/37_88) or [4-Digit 7-Segment](https://www.adafruit.com/category/37_103) backpack-enabled displays

# Related Information

If you're looking for help on&nbsp;how to assemble one of our&nbsp;backpack-enabled LED&nbsp;displays, have a look at our earlier guide, [Adafruit LED Backpacks](http://learn.adafruit.com/adafruit-led-backpack). &nbsp;It contains a lot of complimentary information on these displays, including step by step soldering and assembly instructions.

# Matrix and 7-Segment LED Backpack with the Raspberry Pi

## Hooking Everything Up

Info: 

The LED backpack displays are wonderfully easy to connect to the Pi. Each module type is connected the same way. The following types are covered for wiring and example code in this guide.

- 8x8 matrix
- 4-character 7-segment
- 4-character 14 segment (alphanumeric)
- bicolor matrix
- bicolor24 bar

Two digital pins for I2C (SDA and SCL) and two power pins (VCC and GND), as follows.  
  
If you're using a red, yellow or green backpack, you can power the backpack from 3.3V which will keep the I2C levels at 3.3V. If you have a blue or white backpack, the LEDs will be dim if powered from 3.3V.   
  
If you want them a little brighter, connect the VCC pin of the backpack to 5V. There are 10K pullups on the backpack to 5V. **As long as the backpack is the only i2c device on the i2c bus with pullups to 5V this is perfectly safe for the Pi. If you have 2 or more 5V i2c devices, the 5V pullups may 'overpower' the Pi's strong 3.3v pullups, in this case you'll want to use a proper level shifter: [https://www.adafruit.com/products/757](https://www.adafruit.com/products/757)**

## 40-Pin (A, B, B+ and Zero) Cobbler Plus Schematic
![](https://cdn-learn.adafruit.com/assets/assets/000/079/536/medium800/led_matrices_Matrix_8x8_LED_Backpack-40-pin_bb.png?1565996393)

## 26-Pin (Raspberry Pi Rev 1 and Rev 2) Cobbler Schematic
![](https://cdn-learn.adafruit.com/assets/assets/000/001/869/medium800/raspberry_pi_LEDBackpackSetup.png?1396777005)

## BeagleBone Black
Wire up the LED backpack display to the BeagleBone Black as follows (note the image below shows a matrix display, however the wiring is the same for any backpack):

![](https://cdn-learn.adafruit.com/assets/assets/000/080/311/medium800/led_matrices_bbb-i2c-led-backpack.png?1567366875)

- Connect&nbsp;**display + (power)**&nbsp;to&nbsp; **BeagleBone Black 3.3V&nbsp;**** or 5V power&nbsp;(red wire). 5V is brighter but if you have other devices on the I2C bus its better to go with 3.3V**
- Connect&nbsp;**display - (ground)**&nbsp;to&nbsp; **BeagleBone Black ground** &nbsp;(black wire).
- Connect&nbsp;**display D (data/SDA)**&nbsp;to&nbsp; **BeagleBone Black&nbsp;**** I2C2\_SDA pin P9\_20**&nbsp;(orange wire).
- Connect&nbsp;**display C (clock/SCL)**&nbsp;to&nbsp; **BeagleBone Black&nbsp;**** I2C2\_SCL pin P9\_19**&nbsp;(purple wire).
- If there's a&nbsp; **Vi2c** &nbsp;or&nbsp; **IO** &nbsp;pin, connect that to 3.3V as well

Note that the BeagleBone Black has two I2C interfaces and this wiring will use the **/dev/i2c-1** &nbsp;interface. Make sure there aren't any&nbsp;[device tree overlays loaded](https://learn.adafruit.com/introduction-to-the-beaglebone-black-device-tree/overview "Link: https://learn.adafruit.com/introduction-to-the-beaglebone-black-device-tree/overview")&nbsp;which use these I2C pins for other purposes. The default BeagleBone Black device tree configuration with no overlays loaded will expose the necessary I2C interface for the wiring above.

# Matrix and 7-Segment LED Backpack with the Raspberry Pi

## Pi Prep

## Update Your Pi to the Latest Raspbian

Your Pi will need to be running the latest version of Raspbian. This tutorial was written using Raspbian Buster (July 2019). Checkout our guide for&nbsp;[Preparing an SD Card for your Raspberry Pi](https://learn.adafruit.com/adafruit-raspberry-pi-lesson-1-preparing-and-sd-card-for-your-raspberry-pi)&nbsp;if you have not done so already. After the installation is complete be sure and run the following commands to make confirm your installation packages are up to date.&nbsp;

```
sudo apt-get update -y
sudo apt-get upgrade -y
```

![](https://cdn-learn.adafruit.com/assets/assets/000/079/532/medium800/led_matrices_pi-prep-update.jpeg?1565990763)

## Install adafruit-blinka

Run the following command to install the&nbsp;adafruit\_blinka CircuitPython Libraries.

```
pip3 install adafruit-blinka
```

![](https://cdn-learn.adafruit.com/assets/assets/000/079/533/medium800/led_matrices_pi-prep-blinka.jpg?1565995380)

## Enable the I2C Interface
The [Holtek HT16K33](http://www.adafruit.com/datasheets/ht16K33v110.pdf) chip used in all of our backpacks communicates using the common I2C bus. &nbsp;The I2C bus allows multiple devices to be connected to your Raspberry Pi, each with a unique address, that can often be set by changing jumper settings on the module.&nbsp;Linux and the Pi both have native support for I2C, but&nbsp;you'll need to run through a couple quick steps from the console before you can use it in Python.&nbsp;&nbsp;  
  
To see a detailed screen by screen tutorial about how to&nbsp;setup I2C with Raspbian, take a minor diversion to this Adafruit Tutorial:&nbsp;[Raspberry Pi Lesson 4. GPIO Setup](http://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c). We will provide a brief summary below for those somewhat familiar with the **raspi-config** utility.

```
sudo raspi-config
&lt;Interfacing Options&gt;
&lt;I2C&gt; Enable/Disable
&lt;Enable&gt;
&lt;Back&gt;
&lt;Finish&gt;
```

![](https://cdn-learn.adafruit.com/assets/assets/000/079/534/medium800/led_matrices_pi-prep-i2c.png?1565995809)

## Test the I2C Bus
Now that our Pi has rebooted we can confirm that the correct I2C modules have loaded with the following command.

```
lsmod | grep -i i2c
```

![](https://cdn-learn.adafruit.com/assets/assets/000/079/535/medium800/led_matrices_pip-prep-i2c-test.jpg?1565995889)

```
sudo i2cdetect -y 1
```

This will search I2C for all address, and if a Holtek HT16K33&nbsp;breakout is properly connected and it's set to it's default address it should show up as follows (the exact address will vary depending on whether or not you have any of the address solder jumpers set).  
  
If you happen to have one of the original first batch of Raspberry Pis, you will need to change the 1 to a 0 in the command above.

![](https://cdn-learn.adafruit.com/assets/assets/000/001/867/medium800/raspberry_pi_i2cdetect_leds.png?1396776968)

Recent Raspbian releases includes the i2cdetect command, but if it is not found on your system please use the following syntax to install the necessary packages.

```
sudo apt-get install -y python-smbus i2c-tools
```

# Install the HT16K33 Library

The software for this project uses the Adafruit code for driving the 7-segment and matrix displays.

```
pip3 install adafruit-circuitpython-ht16k33

```

![](https://cdn-learn.adafruit.com/assets/assets/000/079/537/medium800/led_matrices_pi-prep-ht16k33.png?1566000872)

# Matrix and 7-Segment LED Backpack with the Raspberry Pi

## Matrix 8x8 Pixel

![](https://cdn-learn.adafruit.com/assets/assets/000/080/626/medium800/led_matrices_matrix8x8.jpg?1567813528)

## CircuitPython Code
The following example will illuminate the matrix rows and columns one pixel at a time.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Matrix_7-Segment_LED_Backpack_Raspberry_Pi/matrix8x8_test/code.py

## Download and Run the Code
We can easily copy this code onto our Pi's home directory using the 'wget' command and then run it using the following commands.

```
cd
wget https://raw.githubusercontent.com/adafruit/Adafruit_Learning_System_Guides/Matrix_7-Segment_LED_Backpack_Raspberry_Pi/Matrix_7-Segment_LED_Backpack_Raspberry_Pi/matrix8x8_test.py
python3 ./matrix8x8_test.py
```

Which should result in something like the following:

http://www.youtube.com/watch?v=AYArwe-OkdQ

# Matrix and 7-Segment LED Backpack with the Raspberry Pi

## Matrix Bicolor

![](https://cdn-learn.adafruit.com/assets/assets/000/080/627/medium800/led_matrices_bicolor-matrix.jpg?1567813815)

The bicolor matrix display is demonstrated in the **matrix\_bicolor\_test.py** example below. This code demonstrates using the&nbsp; **Matrix8x8x2** &nbsp;class in a very similar way to the&nbsp; **Matrix8x8** &nbsp;class. The key difference is that are assigning color value and are not limited to a 1 or 0 value like with the&nbsp; **Matrix8x8** &nbsp;class.

## CircuitPython Code
https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Matrix_7-Segment_LED_Backpack_Raspberry_Pi/matrix_bicolor_test/code.py

## Download and Run the Code
We can easily copy this code onto our Pi's home directory using the 'wget' command and then run it using the following commands.

```
cd
wget https://raw.githubusercontent.com/adafruit/Adafruit_Learning_System_Guides/master/Matrix_7-Segment_LED_Backpack_Raspberry_Pi/matrix_bicolor_test.py
python3 matrix_bicolor_test.py
```

# Matrix and 7-Segment LED Backpack with the Raspberry Pi

## 7-Segment

![](https://cdn-learn.adafruit.com/assets/assets/000/080/625/medium800/led_matrices_7segment.jpeg?1567813004)

## CircuitPython Code
The following code illustrates how to display integers, characters, floating point, hex values and toggle the colon on a 7-segment display.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Matrix_7-Segment_LED_Backpack_Raspberry_Pi/sevensegment_test/code.py

## Download and Run the Code
We can easily copy this code onto our Pi's home directory using the 'wget' command and then run it using the following commands.

```
cd
wget https://raw.githubusercontent.com/adafruit/Adafruit_Learning_System_Guides/master/Matrix_7-Segment_LED_Backpack_Raspberry_Pi/sevensegment_test.py
python3 ./sevensegment_test.py
```

This will briefly scroll through printing&nbsp; integers, floating point values, some text characters and hex values on a seven segment display.

# Matrix and 7-Segment LED Backpack with the Raspberry Pi

## Bicolor Bar Graph 24

![](https://cdn-learn.adafruit.com/assets/assets/000/080/623/medium800/led_matrices_bargraph.jpg?1567812785)

## CircuitPython Code
The bicolor bar graph display is demonstrated in the&nbsp; **bicolor24\_test.py&nbsp;** script.&nbsp;This code will light up 3 bars in different colors and then loop through full color all on and all off modes.&nbsp;

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Matrix_7-Segment_LED_Backpack_Raspberry_Pi/bicolor24_test/code.py

## Download and Run the Code
We can easily copy this code onto our Pi's home directory using the 'wget' command and then run it using the following commands.

```
cd
wget https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/master/Matrix_7-Segment_LED_Backpack_Raspberry_Pi/bicolor24_test.py
python3 bicolor24_test.py
```

# Matrix and 7-Segment LED Backpack with the Raspberry Pi

## 7-Segment Clock

![](https://cdn-learn.adafruit.com/assets/assets/000/080/624/medium800/led_matrices_clock.jpg?1567812948)

## CircuitPython Code
Display the system time on a four digit seven segment display.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Matrix_7-Segment_LED_Backpack_Raspberry_Pi/sevensegment_clock/code.py

## Download and Run the Code
We can easily copy this code onto our Pi's home directory using the 'wget' command and then run it using the following commands.

```
cd
wget https://raw.githubusercontent.com/adafruit/Adafruit_Learning_System_Guides/master/Matrix_7-Segment_LED_Backpack_Raspberry_Pi/sevensegment_clock.py
python3 ./sevensegment_clock.py
```

You should see the time appear on your 7-segment display in 24-hour format with a slow blinking colon. It should look like this:

http://www.youtube.com/watch?v=AAgTe27reIk

# Matrix and 7-Segment LED Backpack with the Raspberry Pi

## 14-Segment Alphanumeric Display

![](https://cdn-learn.adafruit.com/assets/assets/000/080/622/medium800/led_matrices_alpha.jpg?1567810579)

## CircuitPython Code
The 14 segment alphanumeric display is demonstrated in the&nbsp; **alphanum4\_test.py** &nbsp;script in the examples folder. If you run this example it will scroll a text message across the display. The message if followed by a run down of various integer, decimal, hex and character values. This display is great for showing complete text messages because the 14 segment displays are very flexible.  
  
With the 14 segment display the usage is very similar to the 7 segment display above.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Matrix_7-Segment_LED_Backpack_Raspberry_Pi/alphanum4_test/code.py

## Download and Run the Code
We can easily copy this code onto our Pi's home directory using the 'wget' command and then run it using the following commands.

```
cd
wget https://raw.githubusercontent.com/adafruit/Adafruit_Learning_System_Guides/master/Matrix_7-Segment_LED_Backpack_Raspberry_Pi/alphanum4_test.py
python3 alphanum4_test.py
```


## Featured Products

### Adafruit 0.56" 4-Digit 7-Segment Display w/ I2C Backpack - Blue

[Adafruit 0.56" 4-Digit 7-Segment Display w/ I2C Backpack - Blue](https://www.adafruit.com/product/881)
What's better than a single LED? Lots of LEDs! A fun way to make a small display is to use an [8x8 matrix](https://www.adafruit.com/category/37_88) or a [4-digit 7-segment display](https://www.adafruit.com/category/37_103). Matrices like these are...

In Stock
[Buy Now](https://www.adafruit.com/product/881)
[Related Guides to the Product](https://learn.adafruit.com/products/881/guides)
### Adafruit Mini 0.8" 8x8 LED Matrix w/I2C Backpack - Yellow-Green

[Adafruit Mini 0.8" 8x8 LED Matrix w/I2C Backpack - Yellow-Green](https://www.adafruit.com/product/872)
What's better than a single LED? Lots of LEDs! A fun way to make a small display is to use an [8x8 matrix](https://www.adafruit.com/category/37_88) or a [4-digit 7-segment display](https://www.adafruit.com/category/37_103). Matrices like these are...

In Stock
[Buy Now](https://www.adafruit.com/product/872)
[Related Guides to the Product](https://learn.adafruit.com/products/872/guides)
### Adafruit Bicolor LED Square Pixel Matrix with I2C Backpack

[Adafruit Bicolor LED Square Pixel Matrix with I2C Backpack](https://www.adafruit.com/product/902)
What's better than a single LED? Lots of LEDs! A fun way to make a small colorful display is to use a [1.2" Bi-color 8x8 LED Matrix](http://www.adafruit.com/products/458). Matrices like these are 'multiplexed' - so to control all the 128 LEDs you need 24 pins....

Out of Stock
[Buy Now](https://www.adafruit.com/product/902)
[Related Guides to the Product](https://learn.adafruit.com/products/902/guides)
### Quad Alphanumeric Display - Blue 0.54" Digits w/ I2C Backpack

[Quad Alphanumeric Display - Blue 0.54" Digits w/ I2C Backpack](https://www.adafruit.com/product/1912)
Display, elegantly, 012345678 or 9! Gaze, hypnotized, at ABCDEFGHIJKLM - well it can display the whole alphabet. You get the point. This is a nice, bright alphanumeric display that shows letters and numbers in a beautiful blue hue. It's super bright and designed for viewing from distances...

In Stock
[Buy Now](https://www.adafruit.com/product/1912)
[Related Guides to the Product](https://learn.adafruit.com/products/1912/guides)
### Bi-Color (Red/Green) 24-Bar Bargraph w/I2C Backpack Kit

[Bi-Color (Red/Green) 24-Bar Bargraph w/I2C Backpack Kit](https://www.adafruit.com/product/1721)
What's better than a single LED? Lots of LEDs! A fun way to make a small linear display is to use two 12-bar Bi-color bar-graphs. However, this LED bargraph is 'multiplexed' - so to control all the 48 LEDs you need a lot of pins. <a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/1721)
[Related Guides to the Product](https://learn.adafruit.com/products/1721/guides)
### Raspberry Pi 3 - Model B+ - 1.4GHz Cortex-A53 with 1GB RAM

[Raspberry Pi 3 - Model B+ - 1.4GHz Cortex-A53 with 1GB RAM](https://www.adafruit.com/product/3775)
The Raspberry Pi 3 Model B is the most popular Raspberry Pi computer made, and the Pi Foundation knows you can always make a good thing _better_! And what could make the Pi 3 better? How about a&nbsp;_faster_ processor, 5 GHz WiFi, and updated Ethernet chip with PoE capability?...

In Stock
[Buy Now](https://www.adafruit.com/product/3775)
[Related Guides to the Product](https://learn.adafruit.com/products/3775/guides)
### Assembled Pi Cobbler Plus - Breakout Cable

[Assembled Pi Cobbler Plus - Breakout Cable](https://www.adafruit.com/product/2029)
The Raspberry Pi B+ / Pi 2 / Pi 3 / Pi 4&nbsp;has landed on the Maker World like a 40-GPIO pinned, quad-USB ported, credit card sized bomb of DIY joy. And while you can use most of our great Model B accessories by hooking up our [downgrade...](https://www.adafruit.com/product/1986)

In Stock
[Buy Now](https://www.adafruit.com/product/2029)
[Related Guides to the Product](https://learn.adafruit.com/products/2029/guides)

## Related Guides

- [Adafruit LED Backpacks](https://learn.adafruit.com/adafruit-led-backpack.md)
- [Adafruit's Raspberry Pi Lesson 12. Sensing Movement](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-12-sensing-movement.md)
- [LED Backpack Displays on Raspberry Pi and BeagleBone Black](https://learn.adafruit.com/led-backpack-displays-on-raspberry-pi-and-beaglebone-black.md)
- [Moonshine Voice Control on Raspberry Pi](https://learn.adafruit.com/moonshine-voice-control-on-raspberry-pi.md)
- [Arduino GPS Clock](https://learn.adafruit.com/arduino-clock.md)
- [Program an AVR or Arduino Using Raspberry Pi GPIO](https://learn.adafruit.com/program-an-avr-or-arduino-using-raspberry-pi-gpio-pins.md)
- [Trinket-Powered Conference Room Occupancy Display](https://learn.adafruit.com/trinket-powered-room-conference-occupancy-display.md)
- [Basic Resistor Sensor Reading on Raspberry Pi](https://learn.adafruit.com/basic-resistor-sensor-reading-on-raspberry-pi.md)
- [Adafruit's Raspberry Pi Lesson 11. DS18B20 Temperature Sensing](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-11-ds18b20-temperature-sensing.md)
- [Scrolling Countdown Timer](https://learn.adafruit.com/scrolling-countdown-timer.md)
- [Capacitive Touch Sensors on the Raspberry Pi](https://learn.adafruit.com/capacitive-touch-sensors-on-the-raspberry-pi.md)
- [CircuitPython Hardware: LED Backpacks & FeatherWings](https://learn.adafruit.com/micropython-hardware-led-backpacks-and-featherwings.md)
- [CircuitPython on Raspberry Pi (Bare Metal / No OS)](https://learn.adafruit.com/circuitpython-on-raspberry-pi-bare-metal-no-os.md)
- [LED Matrix Alarm Clock](https://learn.adafruit.com/led-matrix-alarm-clock.md)
- [Pi-Top Assembly ](https://learn.adafruit.com/pi-top-assembly.md)
