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
- 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.
- You should first connect the HAT itself to the Pi, using the 20x8 header bridge.
- Then connect the data cable between the HAT and the LED matrix.
- 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
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.
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 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 c = text_color_pair print("t=" + t + " " + str(c) + " " + str(x)) draw.text((x, 0), t, c, font=font) x = x + font.getsize(t) im.save("test.ppm") os.system("./led-matrix 1 test.ppm")