Raspberry Pi LED Scrolling Text Display

16,738

31

9

Hi I'll be showing you how to use a Raspbery Pi and an LED matrix to display some scrolling text.

Step 1: Gather Materials

Parts

Tools

  • Soldering Iron + Solder

Step 2: Solder HAT Together

There are three small pieces that come with the Matrix HAT kit, which should be soldered to the top of the HAT itself.

Step 3: Connect Everything Together

This step is pretty straight forward.

  1. You should first connect the HAT itself to the Pi, using the 20x8 header bridge.
  2. Then connect the data cable between the HAT and the LED matrix.
  3. After that, The matrix itself needs power, which can be supplied by plugging a power cable into the HAT or using a different connector to bypass the HAT.

After this, everything should be connected, and once you supply power to both the Pi and the matrix, you should be good to go!

Step 4: Setup Pi + Python

Connect your PI to a monitor or a laptop and ssh in.

Then you'll need to install Python with these commands:

sudo apt-get update
sudo apt-get install python-dev python-imaging

Then download the code for driving the matrices:

wget https://github.com/adafruit/rpi-rgb-led-matrix/archive/master.zip 
unzip master.zip

Now you'll need to cd into the directory you just unzipped, and build the driver

cd rpi-rgb-led-matrix-master/
make

Now you can run the test demo led-matrix with this command, where D is any number from 1-9

sudo ./led-matrix -D 4

In the next step, I'll be showing you how to write your own program!

Step 5: Programming the Matrix

Use the following code, replacing the message with whatever you want, along with the colors for each part.

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")

Share

    Recommendations

    • Trash to Treasure

      Trash to Treasure
    • Arduino Contest 2019

      Arduino Contest 2019
    • Tape Contest

      Tape Contest

    9 Discussions

    0
    None
    AndrewS591

    Question 1 year ago on Step 5

    Where do I insert the code this code below at? Is it in the LX terminal?? Can I just copy this code into the terminal? Also how do you skip a line like what you have done after line 4 in your code below? Thanks for you help.

    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")

    Add Tip

    3 answers
    1
    None
    tcvvAndrewS591

    Answer 1 year ago

    So, first, this tutorial is outdated. Now you will find the C++ demos in rpi-rgb-led-matrix/examples-api-use and you can put the text you copied into a python file of any name ending with .py (for example, browncoat.py) in that folder. Since it is outdated, you also have to change the last line of the file from:

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

    to:

    os.system("./demo -D 1 test.ppm")

    Then you can run it with the command:

    sudo python browncoat.py

    Unfortunately Step 5 (which was the most important part to me) was really poorly written and, for some reason, the author just chose to stop explaining what they were doing at that crucial point. Hopefully instructables will update it.

    0
    None
    AndrewS591tcvv

    Reply 2 months ago

    Thanks TCVV. I changed the code in a program called thonny and saved it. When I go into the raspberry pi terminal to run the code i get a error message that says. invalid syntax. Also inside the rpi-rgb-led-matrix file i don't see any folders that say examples-api-use. Thanks for your help

    0
    None
    youngrg14tcvv

    Reply 2 months ago

    tcvv, we pasted the code with your recommended change to the last line into a .py file. We edited it in a program call Thonny. I also do not see the "examples-api-use" folder you were talking about. We then tried to use the command sudo python scrollingtext.py but this did not work. Any thoughts? I feel like we are very close to getting our custom text to scroll.

    0
    None
    SeanM351

    Question 1 year ago on Step 5

    Hi! I want to use your code to create a system that is able to display an sms message into the LED matrix. My problem is it keeps asking for a character in order to proceed to next message. I tried disabling the getchar() line but the display won't turn on. Do you have any tips?

    0
    None
    pkilcoyne

    3 years ago

    Also,

    I cannot find the "fonts" directory on my Raspbian install :(

    1 reply
    0
    None
    richardw151pkilcoyne

    Reply 3 years ago

    Try:

    fc-list

    shows my fonts to be in

    /usr/share/fonts/

    0
    None
    pkilcoyne

    3 years ago

    Hi there,

    nice project.

    Question, is the RGB matrix HAT absolutely necessary, can you not just connect LED panel directly to the RPi GPIO?

    Also, could you comment your python code please? I'm new to python so can get confused easily and often :(

    Great work though, thank you,

    Paul