Raspberry Pi LED Scrolling Text Display

Published

Introduction: Raspberry Pi LED Scrolling Text Display

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

    • Clocks Contest

      Clocks Contest
    • Oil Contest

      Oil Contest
    • Water Contest

      Water Contest

    7 Discussions

    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

    1 more answer

    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.

    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?

    Also,

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

    1 reply

    Try:

    fc-list

    shows my fonts to be in

    /usr/share/fonts/

    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