LED - 5. Raspberry Pi 4 + DietPi Buster + Electrodragon HAT - Part 2(multi chain)
So far I've only used one chain to handle the RGB LED matrix on the Raspberry Pi. Adafruit's HAT and Bonnet only support one chain.
Even when multiple chains are used, the arrangement of the LED matrix can be adjusted and implemented as shown above. However, in this example, I will simply process, so you don't have to fsplit thw image for flipping:
But before you run the code, you should customize the code for the multi chain support. Of course, you can adjust this setting using runtime parameters.
Now chain length is 2 (number of horizontal matrices)
options.chain_length = args.horizontal
The parallel length is 2 (number of vertical matrices)
options.parallel = args.vertical
And I removed all the processes like image segmentation, flipping, and combination. The code looks much simpler than before.
I will run the above code on the Raspberry Pi 4 + DietPi Buster.
Note the 213.3 Hz in the far right of the results screen above. You can see that the refresh rate of the screen is higher than before. This is because the number of daisy connections per chain has been cut in half.
<Adafruit HAT/Bonnet that supports one HUB75 interface>
However, the PCB designed by Henner Zeller supports up to three chains.
This is the maximum number of chains that the Raspberry Pi's 40 GPIO can support.
<Henner Zeller's HAT and Electrodragon HAT those support 3 chains>
Why use multi chains
Use daisy connections to connect multiple LED matrices in a chain. I've explained daisy connectin in my other blog. Daisy connections are not infinitely possible. Since the signal must be delivered to adjacent LEDs, connecting more than a certain number will slow down the signal transmission and cause screen flicker. Henner Zeller recommends no more than 12 connections in a chain. However, this value depends on which LED matrix, Raspberry Pi you use. For example, using a 64X64 LED matrix will reduce the number of connections that can be made compared to using a 16X16 LED. In addition, reducing the number of colors that can be displayed can increase the number of connectable colors. So refer to Henner Zeller's guide and determine the exact number by testing it in your own environment. Using multiple such daisy connections simultaneously increases the number of connectable LED matrices by N times. Therefore, to maximize the number of available LED matrices, all three chains must be used.
<image from https://github.com/hzeller/rpi-rgb-led-matrix/blob/master/README.md>
Using two chains
Do not wonder if I use only 2 chains, not 3 chains. The number of LED matrices I have is insufficient and only two are connected. However, if you succeed in connecting the two, then using three chains should be no problem.
I will connect two 64X32 LED matrices in a chain. Therefore, all four LED matrices are used.
Using one chain, I went through the process of changing a part of the image to a symmetrical image, as shown in the following figure.
Using one chain, I went through the process of changing a part of the image to a symmetrical image, as shown in the following figure.
<Image in which the top half is flipped>
Even when multiple chains are used, the arrangement of the LED matrix can be adjusted and implemented as shown above. However, in this example, I will simply process, so you don't have to fsplit thw image for flipping:
Test
I'm going to use a code that I've used at https://iot-for-maker.blogspot.com/2020/02/led-5-raspberry-pi-4-dietpi-buster.html.But before you run the code, you should customize the code for the multi chain support. Of course, you can adjust this setting using runtime parameters.
Now chain length is 2 (number of horizontal matrices)
options.chain_length = args.horizontal
The parallel length is 2 (number of vertical matrices)
options.parallel = args.vertical
And I removed all the processes like image segmentation, flipping, and combination. The code looks much simpler than before.
import argparse import cv2 import numpy as np from PIL import Image from PIL import ImageDraw from rgbmatrix import RGBMatrix, RGBMatrixOptions import time parser = argparse.ArgumentParser(description="RGB LED matrix Example") parser.add_argument("--video", type=str, required = True, help="video file name") parser.add_argument("--horizontal", type=int, default = 1, help="horizontal count") parser.add_argument("--vertical", type=int, default = 1, help="vertical count") args = parser.parse_args() # Configuration for the matrix options = RGBMatrixOptions() options.cols = 64 options.rows = 32 options.chain_length = args.horizontal options.parallel = args.vertical options.brightness = 80 options.pwm_bits = 11 options.gpio_slowdown = 4.0 options.show_refresh_rate = 1 options.hardware_mapping = 'regular' # If you have an Adafruit HAT: 'adafruit-hat' #options.hardware_mapping = 'adafruit-hat' # If you have an Adafruit HAT: 'adafruit-hat' options.pwm_dither_bits = 0 matrix = RGBMatrix(options = options) canvas_w = args.horizontal * options.cols canvas_h = args.vertical * options.rows print('Matrix H:%d W:%d'%(matrix.height, matrix.width)) print('Image size H:%d W:%d'%(canvas_h, canvas_w)) cap = cv2.VideoCapture(args.video) double_buffer = matrix.CreateFrameCanvas() while cap.isOpened(): im_pils = [] start = time.time() for i in range(2): ret, im = cap.read() if(ret == False): break im = cv2.resize(im, (canvas_w, canvas_h)) im = cv2.cvtColor(im, cv2.COLOR_BGR2RGB) im_pil = Image.fromarray(im) im_pils.append(im_pil) if(ret == False): break double_buffer.SetImage(im_pils[0]) double_buffer.SetImage(im_pils[1], canvas_w) double_buffer = matrix.SwapOnVSync(double_buffer) elapsed = time.time() - start #print('elapsed:%f'%(elapsed)) time.sleep(max([0, 0.066 - elapsed]))
<nbym_video_multichain_pi4.py>
I will run the above code on the Raspberry Pi 4 + DietPi Buster.
root@DietPi:/usr/local/src/rpi-rgb-led-matrix/bindings/python/samples# python3 nbym_video_multichain_pi4.py --video=Frozen_s.y4m --horizontal=2 --vertical=2 Matrix H:64 W:128 Image size H:64 W:128 213.3Hz max: 4994usec
Note the 213.3 Hz in the far right of the results screen above. You can see that the refresh rate of the screen is higher than before. This is because the number of daisy connections per chain has been cut in half.
<display with 2 chains>
Wrapping up
You can see that a clean screen is displayed while maintaining a higher refresh rate than before. If your HAT supports three chains, using the maximum number of chains is a good way to get a good output. Using all three chains, up to 36 RGB LED matrices can be connected. Of course, the realistic number can be reduced during the test.
You can download the source codes here(https://github.com/raspberry-pi-maker/IoT)
댓글
댓글 쓰기