# 16x32 RGB Display with Raspberry Pi - part 2

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/015/707/medium800thumb/raspberry_pi_adafruitandpi.jpg?1448311598)

In the [first tutorial](http://learn.adafruit.com/connecting-a-16x32-rgb-led-matrix-panel-to-a-raspberry-pi) using the 16x32 RGB display, we used just one of these displays with the software developed by [Henner Zeller](https://github.com/Boomerific/rpi-rgb-led-matrix)   
In this tutorial, we will look at daisy chaining together two or three of these displays and also wrapping Henner’s fast and efficient C code in some Python that will create images on the fly and populate them with text before handing them over to the C code to handle the refreshing of the display.![](https://cdn-learn.adafruit.com/assets/assets/000/015/701/medium800/raspberry_pi_overview_web.jpg?1396432529)

# 16x32 RGB Display with Raspberry Pi - part 2

## You Will Need

To build this project, you will need the following items:

[Raspberry Pi (we're using the Model B)](http://www.adafruit.com/products/998 "Link: http://www.adafruit.com/products/998")  
![raspberry_pi_998_LRG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/015/710/medium640/raspberry_pi_998_LRG.jpg?1396459912)

[Adafruit 16x32 RGB LED Matrix](http://www.adafruit.com/products/420) - we're using 3 of them!  
![raspberry_pi_rgbmatrixpanel_LRG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/015/711/medium640/raspberry_pi_rgbmatrixpanel_LRG.jpg?1396461444)

[5V 4A](http://www.adafruit.com/products/1466) (2 panels any design, or 3 panels with text or otherwise not filling up all the pixels with bright color) or   
[5V 10A Power Supply (any number of panels, any designs)](http://www.adafruit.com/products/658 "Link: http://www.adafruit.com/products/658")![raspberry_pi_1466_LRG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/015/706/medium640/raspberry_pi_1466_LRG.jpg?1396454001)

[2.1mm to Screw Jack Adapter - to connect the 5V power adapter to the panels  
](http://www.adafruit.com/products/368 "Link: http://www.adafruit.com/products/368")![raspberry_pi_female21terminal_LRG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/015/714/medium640/raspberry_pi_female21terminal_LRG.jpg?1396461627)

14 x Female-Female jumper wires. [You can use 6" ones](http://www.adafruit.com/products/266) or [12" ones.](http://www.adafruit.com/products/793 "Link: http://www.adafruit.com/products/793")

![raspberry_pi_ffjumpers_LRG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/015/712/medium640/raspberry_pi_ffjumpers_LRG.jpg?1396461499)

6 x Male-Male jumper wires - you can also just use wire.

![raspberry_pi_ID758_LRG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/015/713/medium640/raspberry_pi_ID758_LRG.jpg?1396461590)

[Raspberry Leaf - helps make wiring easier  
](http://www.adafruit.com/products/1772)![raspberry_pi_1772_LRG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/015/715/medium640/raspberry_pi_1772_LRG.jpg?1396461655)

# 16x32 RGB Display with Raspberry Pi - part 2

## Wiring the Displays

If you have not already done so, refer back to [this tutorial](http://learn.adafruit.com/connecting-a-16x32-rgb-led-matrix-panel-to-a-raspberry-pi) to wire up the first of the displays as shown below.

![](https://cdn-learn.adafruit.com/assets/assets/000/015/697/medium800/raspberry_pi_wiring_1.png?1396384408)

Each of the displays comes with both data and power connectors. Use the data connectors to bridge from the connector labelled OUTPUT on the first display to INPUT of the next display. If you have three displays then also bridge the data to the final display.

![](https://cdn-learn.adafruit.com/assets/assets/000/015/702/medium800/raspberry_pi_wiring.png?1396432562)

Attach the power connectors for all the displays to the displays and then use male to male jumper wires as shown above to connect all the red +5V connectors together and all the black negative connections together. Note that as long as you are connecting red-wired terminals on the power leads to other red-wired connections and black connections to the other black connections, it does not matter which of the connections on the four pin power connectors you use.

  
Finally use male to male jumper wires on the final display to connect it to the screw terminals of the 2.1mm to Screw Jack Adapter.

  

Info: 

# 16x32 RGB Display with Raspberry Pi - part 2

## Software

Follow the instructions [here](http://learn.adafruit.com/connecting-a-16x32-rgb-led-matrix-panel-to-a-raspberry-pi/testing) to install the software, but before you type the command “make”, there are a couple of changes that need to be made to the code.  
  
Change to the directory using the command:

```auto
$ cd ~/display16x32/rpi-rgb-led-matrix
```

Then edit the file led-matrix.h using nano:

```auto
$ nano led-matrix.h
```

Look for the line below, that sets the pixel width. Its near the top of the file. Change the value of width from 32 to either 64 (if you have two displays) or 96 if you have three.

```auto
  int width() const { return 96; }  
```

Next, look a little further down the same file and modify the value of kChainedBoards to the number of boards you have. In this case 3.

```auto
 enum {
   kDoubleRows = 8,     // Physical constant of the used board.
   kChainedBoards = 3,   // Number of boards that are daisy-chained.
   kColumns = kChainedBoards * 32,
   kPWMBits = 4          // maximum PWM resolution.
 };
```

Having changed the code, you now need to rebuild the project, so type the command “make”.

![](https://cdn-learn.adafruit.com/assets/assets/000/015/699/medium800/raspberry_pi_running_make.png?1396384742)

You can now run the original demo program, to check that everything is working, using the command:

```auto
$ sudo ./led-matrix
```

The square pattern will disappear of the screen some of the time, as it was designed for the 32x32 matrix. You can also use scrolling image example by running:

```auto
$ sudo ./led-matrix 1 runtext.ppm
```

or use an image of your own creation.

 **Using Python**  
  

To be able to display any text we want on the displays without having to design an image, you can use the following Python program that first creates an image containing the text and then runs the “led-matrix” C program to display it.

  

This program uses the Python Imaging Library (PIL). To install PIL, enter the following commands.
```auto
$ sudo apt-get update
$ sudo apt-get install python-imaging
```

Type the command below to create the Python program file:

```auto
$ nano message.py
```

.. and then paste in the following code.

```auto
import os
from PIL import ImageFont
from PIL import Image
from PIL import ImageDraw

text = (("Raspberry Pi ", (255, 0, 0)), ("and ", (0, 255, 0)), ("Adafruit", (0, 0, 255)))


font = ImageFont.truetype("/usr/share/fonts/truetype/freefont/FreeSans.ttf", 16)
all_text = ""
for text_color_pair in text:
    t = text_color_pair[0]
    all_text = all_text + t

print(all_text)
width, ignore = font.getsize(all_text)
print(width)


im = Image.new("RGB", (width + 30, 16), "black")
draw = ImageDraw.Draw(im)

x = 0;
for text_color_pair in text:
    t = text_color_pair[0]
    c = text_color_pair[1]
    print("t=" + t + " " + str(c) + " " + str(x))
    draw.text((x, 0), t, c, font=font)
    x = x + font.getsize(t)[0]

im.save("test.ppm")

os.system("./led-matrix 1 test.ppm")
```

Now run the program and you should see the message scroll across your displays.  
  
You can change the message and its use of colors by editing the variable "text". This contains a collection of entries, each in the form of a piece of text followed by the color for that text.

```auto
("Raspberry Pi ", (255, 0, 0))
```

You can change the colour of the text, by changing the color tuple which is set to (255, 0, 0) in the example above. There three values corresponding to the amount of red, green and blue in the color, with 0 being none 255 being full brightness. For white, use (255, 255, 255).  
  
Although this example has three sections of differently colored text, you can add as many as you like, to create longer messages.

# 16x32 RGB Display with Raspberry Pi - part 2

## Next Steps

If you want use a different font to display your text, then you can find the fonts available on your Raspberry Pi using the command:

```auto
$ fc-list
```

To use the font, edit message.py changing the path to the font.   
  
As well as text, the Python Imaging Library also allows you to draw shapes etc on the image. Take a look at the [documentation for PIL](http://effbot.org/imagingbook/imagedraw.htm) here for ideas on how to do this.

 **About the Author**  
  
As well as contributing lots of tutorials about Raspberry Pi, Arduino and now BeagleBone Black, Simon Monk writes books about open source hardware including 'The Raspberry Pi Cookbook' and 'Programming Rasppberry Pi'. You will find his books for sale [here](http://www.adafruit.com/index.php?main_page=adasearch&q=simon+monk) at Adafruit.  

  


## Featured Products

### Raspberry Pi Model B 512MB RAM

[Raspberry Pi Model B 512MB RAM](https://www.adafruit.com/product/998)
Adafruit ships the **Raspberry Pi Model B 512MB RAM** as of 10/18/2012.  
  
The Raspberry Pi® is a single-board computer developed in the UK by the Raspberry Pi Foundation with the intention of stimulating the teaching of basic computer science in schools. The Raspberry...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/998)
[Related Guides to the Product](https://learn.adafruit.com/products/998/guides)
### Medium 16x32 RGB LED matrix panel - 6mm Pitch

[Medium 16x32 RGB LED matrix panel - 6mm Pitch](https://www.adafruit.com/product/420)
Bring a little bit of Times Square into your home with this 16 x 32 RGB LED matrix panel. These panels are normally used to make video walls, here in New York we see them on the sides of busses and bus stops, to display animations or short video clips. We thought they looked really cool so we...

In Stock
[Buy Now](https://www.adafruit.com/product/420)
[Related Guides to the Product](https://learn.adafruit.com/products/420/guides)
### 5V 10A switching power supply

[5V 10A switching power supply](https://www.adafruit.com/product/658)
This is a beefy switching supply, for when you need a lot of power! It can supply 5V DC up to 10 Amps, running from 110V or 220V power (the plug it comes with is for US/Canada/Japan but you can use any plug adapter for your country, or just replace the cable with a standard computer/appliance...

In Stock
[Buy Now](https://www.adafruit.com/product/658)
[Related Guides to the Product](https://learn.adafruit.com/products/658/guides)
### 5V 4A (4000mA) switching power supply - UL Listed

[5V 4A (4000mA) switching power supply - UL Listed](https://www.adafruit.com/product/1466)
Need a lot of 5V power? This switching supply gives a clean regulated 5V output at up to **4 Amps** (4000mA). 110 or 240 input, so it works in any country. The plugs are "US 2-prong" style so you may need a plug adapter, but you can pick one up at any hardware store for $1 or so,...

In Stock
[Buy Now](https://www.adafruit.com/product/1466)
[Related Guides to the Product](https://learn.adafruit.com/products/1466/guides)
### 5V 2A (2000mA) switching power supply - UL Listed

[5V 2A (2000mA) switching power supply - UL Listed](https://www.adafruit.com/product/276)
This is an FCC/CE certified and UL listed power supply. Need a lot of 5V power? This switching supply gives a clean regulated 5V output at up to 2000mA. 110 or 240 input, so it works in any country. The plugs are "US 2-prong" style so you may need a plug adapter, but you can pick one...

In Stock
[Buy Now](https://www.adafruit.com/product/276)
[Related Guides to the Product](https://learn.adafruit.com/products/276/guides)
### Premium Female/Female Jumper Wires - 40 x 6"

[Premium Female/Female Jumper Wires - 40 x 6"](https://www.adafruit.com/product/266)
Handy for making wire harnesses or jumpering between headers on PCB's. These premium jumper wires approximately 6" (150mm) long and come in a 'strip' of 40 (4 pieces of each of ten colors). They have 0.1" sockets on either end and fit cleanly next to each other on...

In Stock
[Buy Now](https://www.adafruit.com/product/266)
[Related Guides to the Product](https://learn.adafruit.com/products/266/guides)
### Premium Male/Male Jumper Wires - 40 x 6" (150mm)

[Premium Male/Male Jumper Wires - 40 x 6" (150mm)](https://www.adafruit.com/product/758)
Handy for making wire harnesses or jumpering between headers on PCB's. These premium jumper wires are 6" (150mm) long and come in a 'strip' of 40 (4 pieces of each of ten rainbow colors). They have 0.1" male header contacts on either end and fit cleanly next to each other...

In Stock
[Buy Now](https://www.adafruit.com/product/758)
[Related Guides to the Product](https://learn.adafruit.com/products/758/guides)
### Female DC Power adapter - 2.1mm jack to screw terminal block

[Female DC Power adapter - 2.1mm jack to screw terminal block](https://www.adafruit.com/product/368)
If you need to connect a DC power wall wart to a board that doesn't have a DC jack - this adapter will come in very handy! There is a 2.1mm DC jack on one end, and a screw terminal block on the other. The terminals are labeled with positive/negative assuming a positive-tip configuration...

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

## Related Guides

- [Using a Mini PAL/NTSC Display with a Raspberry Pi](https://learn.adafruit.com/using-a-mini-pal-ntsc-display-with-a-raspberry-pi.md)
- [LED Matrix Sports Scoreboard](https://learn.adafruit.com/led-matrix-sports-scoreboard.md)
- [DIY WiFi Raspberry Pi Touchscreen Camera](https://learn.adafruit.com/diy-wifi-raspberry-pi-touch-cam.md)
- [The Pixif](https://learn.adafruit.com/the-pixif.md)
- [MatrixPortal CircuitPython Animated Message Board](https://learn.adafruit.com/matrixportal-circuitpython-animated-message-board.md)
- [Adafruit's Raspberry Pi Lesson 3. Network Setup](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-3-network-setup.md)
- [Adafruit 15x7 CharliePlex FeatherWing](https://learn.adafruit.com/adafruit-15x7-7x15-charlieplex-led-matrix-charliewing-featherwing.md)
- [DIY LED Video Cube](https://learn.adafruit.com/diy-led-video-cube.md)
- [Raspberry Pi Pipboy 3000](https://learn.adafruit.com/raspberry-pi-pipboy-3000.md)
- [LED Protest Sign](https://learn.adafruit.com/led-protest-sign.md)
- [Networked Thermal Printer using Raspberry Pi and CUPS](https://learn.adafruit.com/networked-thermal-printer-using-cups-and-raspberry-pi.md)
- [itsaSNAP Apple Health Status Board](https://learn.adafruit.com/itssnap-apple-fitness-status-board.md)
- [MAX31855 Thermocouple Sensor Python Library](https://learn.adafruit.com/max31855-thermocouple-python-library.md)
- [Raspberry Pi Care and Troubleshooting](https://learn.adafruit.com/raspberry-pi-care-and-troubleshooting.md)
- [User-space SPI TFT Python Library - ILI9341](https://learn.adafruit.com/user-space-spi-tft-python-library-ili9341-2-8.md)
