Follow the instructions here 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:
$ cd ~/display16x32/rpi-rgb-led-matrix
Then edit the file led-matrix.h using nano:
$ 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.
  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.
 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”.
You can now run the original demo program, to check that everything is working, using the command:
$ 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:
$ 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.
$ sudo apt-get update
$ sudo apt-get install python-imaging
Type the command below to create the Python program file:
$ nano
.. and then paste in the following code.
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

width, ignore = font.getsize(all_text)

im ="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]"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.
("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.

This guide was first published on Apr 02, 2014. It was last updated on Apr 02, 2014.

This page (Software) was last updated on Apr 21, 2021.

Text editor powered by tinymce.