Text editor powered by tinymce.
Connecting a 16x32 RGB LED Matrix Panel to a Raspberry Pi
Overview
You Will Need
| 16x32 RGB LED Matrix Panel | |
| 5V 2A Power Supply | |
| Female/Female Jumper Wires | |
| Male/Male Jumper Wires | |
| 2.1mm to Screw Jack Adapter |
Text editor powered by tinymce.
Wiring the Display
Connect up the display to the GPIO connector using the female to female jumper wires as shown below:
If you prefer to make the connections using a list, they are as follow:
-
GND on display to GND on the Pi (blue or black)
-
R1 on display to GPIO 17 on the Pi (red)
-
G1 on display to GPIO 18 on the Pi (green)
-
B1 on display to GPIO 22 on the Pi (blue)
-
R2 on display to GPIO 23 on the Pi (red)
-
G2 on display to GPIO 24 on the Pi (green)
-
B2 on display to GPIO 25 on the Pi (blue)
-
A on display to GPIO 7 on the Pi (yellow or white)
-
B on display to GPIO 8 on the Pi (yellow or white)
-
C on display to GPIO 9 on the Pi (yellow or white)
-
OE on display to GPIO 2 on the Pi (brown)
-
CLK on display to GPIO 3 on the Pi (orange)
-
LAT on display to GPIO 4 on the Pi (yellow)
When all the data pins are connected, we can wire up the power supply.
Text editor powered by tinymce.
Testing
$ mkdir display16x32 $ cd display16x32
$ mkdir display16x32 $ cd display16x32
We now need to fetch the code from Henner Zeller's original project using the command:
$ git clone https://github.com/hzeller/rpi-rgb-led-matrix/
$ git clone https://github.com/hzeller/rpi-rgb-led-matrix/
This code is C source code, so we need to compile it before we can run it. It also requires a small change for the wiring layout we're using. Enter the following commands:
$ cd rpi-rgb-led-matrix/lib $ nano Makefile
$ cd rpi-rgb-led-matrix/lib $ nano Makefile
(Or substitute your editor of preference.)
Enable this line in the Makefile (it’s commented out by default):
Save the changes to the file, then exit the editor and type...
Text editor powered by tinymce.
A Scrolling Message
Run the command again, this time using the name that you gave the file:
Text editor powered by tinymce.
Experimental Python Code
As an experiment, I decided to see how practical it would be to try and drive the display from Python code, rather than using the much faster C code.
I had fairly limited success in this. The display refreshes with a bit of flicker, is rather uneven in light intensity and dimmer than the C code. So if anyone can improve the code and make it work better, we would love to hear from you and be happy to update this section with due credit.
The code is relatively compact. It is crude, doing nothing in the way of PWM and can therefore only display eight colors.
If you want to give it a go, the wiring is exactly the same as before, and you will just need to paste the following code into a file called test_display.py
import RPi.GPIO as GPIO
import time
delay = 0.000001
GPIO.setmode(GPIO.BCM)
red1_pin = 17
green1_pin = 18
blue1_pin = 22
red2_pin = 23
green2_pin = 24
blue2_pin = 25
clock_pin = 3
a_pin = 7
b_pin = 8
c_pin = 9
latch_pin = 4
oe_pin = 2
GPIO.setup(red1_pin, GPIO.OUT)
GPIO.setup(green1_pin, GPIO.OUT)
GPIO.setup(blue1_pin, GPIO.OUT)
GPIO.setup(red2_pin, GPIO.OUT)
GPIO.setup(green2_pin, GPIO.OUT)
GPIO.setup(blue2_pin, GPIO.OUT)
GPIO.setup(clock_pin, GPIO.OUT)
GPIO.setup(a_pin, GPIO.OUT)
GPIO.setup(b_pin, GPIO.OUT)
GPIO.setup(c_pin, GPIO.OUT)
GPIO.setup(latch_pin, GPIO.OUT)
GPIO.setup(oe_pin, GPIO.OUT)
screen = [[0 for x in xrange(32)] for x in xrange(16)]
def clock():
GPIO.output(clock_pin, 1)
GPIO.output(clock_pin, 0)
def latch():
GPIO.output(latch_pin, 1)
GPIO.output(latch_pin, 0)
def bits_from_int(x):
a_bit = x & 1
b_bit = x & 2
c_bit = x & 4
return (a_bit, b_bit, c_bit)
def set_row(row):
#time.sleep(delay)
a_bit, b_bit, c_bit = bits_from_int(row)
GPIO.output(a_pin, a_bit)
GPIO.output(b_pin, b_bit)
GPIO.output(c_pin, c_bit)
#time.sleep(delay)
def set_color_top(color):
#time.sleep(delay)
red, green, blue = bits_from_int(color)
GPIO.output(red1_pin, red)
GPIO.output(green1_pin, green)
GPIO.output(blue1_pin, blue)
#time.sleep(delay)
def set_color_bottom(color):
#time.sleep(delay)
red, green, blue = bits_from_int(color)
GPIO.output(red2_pin, red)
GPIO.output(green2_pin, green)
GPIO.output(blue2_pin, blue)
#time.sleep(delay)
def refresh():
for row in range(8):
GPIO.output(oe_pin, 1)
set_color_top(0)
set_row(row)
#time.sleep(delay)
for col in range(32):
set_color_top(screen[row][col])
set_color_bottom(screen[row+8][col])
clock()
#GPIO.output(oe_pin, 0)
latch()
GPIO.output(oe_pin, 0)
time.sleep(delay)
def fill_rectangle(x1, y1, x2, y2, color):
for x in range(x1, x2):
for y in range(y1, y2):
screen[y][x] = color
def set_pixel(x, y, color):
screen[y][x] = color
fill_rectangle(0, 0, 12, 12, 1)
fill_rectangle(20, 4, 30, 15, 2)
fill_rectangle(15, 0, 19, 7, 7)
while True:
refresh()
import RPi.GPIO as GPIO
import time
delay = 0.000001
GPIO.setmode(GPIO.BCM)
red1_pin = 17
green1_pin = 18
blue1_pin = 22
red2_pin = 23
green2_pin = 24
blue2_pin = 25
clock_pin = 3
a_pin = 7
b_pin = 8
c_pin = 9
latch_pin = 4
oe_pin = 2
GPIO.setup(red1_pin, GPIO.OUT)
GPIO.setup(green1_pin, GPIO.OUT)
GPIO.setup(blue1_pin, GPIO.OUT)
GPIO.setup(red2_pin, GPIO.OUT)
GPIO.setup(green2_pin, GPIO.OUT)
GPIO.setup(blue2_pin, GPIO.OUT)
GPIO.setup(clock_pin, GPIO.OUT)
GPIO.setup(a_pin, GPIO.OUT)
GPIO.setup(b_pin, GPIO.OUT)
GPIO.setup(c_pin, GPIO.OUT)
GPIO.setup(latch_pin, GPIO.OUT)
GPIO.setup(oe_pin, GPIO.OUT)
screen = [[0 for x in xrange(32)] for x in xrange(16)]
def clock():
GPIO.output(clock_pin, 1)
GPIO.output(clock_pin, 0)
def latch():
GPIO.output(latch_pin, 1)
GPIO.output(latch_pin, 0)
def bits_from_int(x):
a_bit = x & 1
b_bit = x & 2
c_bit = x & 4
return (a_bit, b_bit, c_bit)
def set_row(row):
#time.sleep(delay)
a_bit, b_bit, c_bit = bits_from_int(row)
GPIO.output(a_pin, a_bit)
GPIO.output(b_pin, b_bit)
GPIO.output(c_pin, c_bit)
#time.sleep(delay)
def set_color_top(color):
#time.sleep(delay)
red, green, blue = bits_from_int(color)
GPIO.output(red1_pin, red)
GPIO.output(green1_pin, green)
GPIO.output(blue1_pin, blue)
#time.sleep(delay)
def set_color_bottom(color):
#time.sleep(delay)
red, green, blue = bits_from_int(color)
GPIO.output(red2_pin, red)
GPIO.output(green2_pin, green)
GPIO.output(blue2_pin, blue)
#time.sleep(delay)
def refresh():
for row in range(8):
GPIO.output(oe_pin, 1)
set_color_top(0)
set_row(row)
#time.sleep(delay)
for col in range(32):
set_color_top(screen[row][col])
set_color_bottom(screen[row+8][col])
clock()
#GPIO.output(oe_pin, 0)
latch()
GPIO.output(oe_pin, 0)
time.sleep(delay)
def fill_rectangle(x1, y1, x2, y2, color):
for x in range(x1, x2):
for y in range(y1, y2):
screen[y][x] = color
def set_pixel(x, y, color):
screen[y][x] = color
fill_rectangle(0, 0, 12, 12, 1)
fill_rectangle(20, 4, 30, 15, 2)
fill_rectangle(15, 0, 19, 7, 7)
while True:
refresh()
The display refreshing should really take place in a separate thread of execution, but as I said, this is more of an experiment than anything else.
Text editor powered by tinymce.
Next Steps
Text editor powered by tinymce.




