LED-10. Make 256 X 126 size RGB Matrix
A few days ago I received four P2.5 126x64 RGB LED matrix ordered from AliExpress. In this blog, I will connect four LED Matrixes to create a 256X 128-sized display.
Preparations are as follows.
Materials
- Raspberry Pi 4 : 1
- P2.5 128X64 RGB LED Matrix : 4
- Electrodragon RGB LED Matrix HAT :1
- Hub74 cable : 4
- LED Power cable:2
- 5V power supply : 1
<P2.5 128X64 4EA RGB LED Matrix>
<hub75 cable LED power cable 5V Power supply>
RGB LED Matrix HAT setup
The 126X64 size RGB LED Matrix is mostly 1/32 multiplexed. Be sure to check the manual of the LED matrix you use for exact details. If you're in 1/32 multiplexing mode, you'll need to tweak some of the Electrodragon HAT's jumper settings.
<Electrodragon HAT jumper settings for 1/32 multiplexing>
And I'm going to use 2 Hub74 sockets at the same time. Therefore, I will connect the HUB 74 sockets P1, P2 of Electro Dragon HAT together to the LED matrix.
<Electrodragon HAT HUB 74 socket P1, P2 are connected to the RGB LED Matrix >
Installing DietPi Buster
I described in my other post(https://opencvcooking.blogspot.com/2020/02/opencv-installation-rasbian-buster.html) how to install DietPi Buster and how to install OpenCV.Today's post is very similar to the previously written LED - 5. Raspberry Pi 4 + DietPi Buster + Electrodragon HAT - Part 1 except that the display size has changed.
.
Required Software Installation
sudo apt-get update -y sudo apt-get dist-upgrade -y sudo apt install build-essential libgraphicsmagick++-dev libwebp-dev -y sudo apt install python-dev python3-dev python3-pil git -y
Download the Henner Zeller's project
I always use python3, so I'm going to bind for the Python3.git clone https://github.com/hzeller/rpi-rgb-led-matrix # build the project using the standard hardware profile (change based on your hardware) cd rpi-rgb-led-matrix sudo HARDWARE_DESC=regular make install-python cd utils/ sudo make led-image-viewer cd ../examples-api-use sudo make cd ../bindings/python sudo make build-python PYTHON=$(which python3) sudo make install-python PYTHON=$(which python3)
Install OpenCV on the DietPi Buster
I've post another blog about installing OpenCV on the DietPi at https://opencvcooking.blogspot.com/2020/02/opencv-installation-rasbian-buster.html .Playing a movie on the 256 X 126 size RGB LED Matrix
This sample code is almost identical to the one used previously. This sample code is almost identical to the one used previously. All you have to do is adjust the options.cols and options.rows values to the new LED size.
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 * 2 options.rows = 32 * 2 options.chain_length = args.horizontal options.parallel = args.vertical options.brightness = 70 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) ret, im = cap.read() h, w, _ = im.shape print('Video frame size H:%d W:%d'%(h, w))
double_buffer = matrix.CreateFrameCanvas() while cap.isOpened(): start = time.time() 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) double_buffer.SetImage(im_pil) double_buffer.SetImage(im_pil, canvas_w) double_buffer = matrix.SwapOnVSync(double_buffer) elapsed = time.time() - start #print('elapsed:%f'%(elapsed)) time.sleep(max([0, (0.066 - elapsed)/2] ))
<nbym_video_multichain_pi4.py>
Now run the code.
root@DietPi:/usr/local/src/rpi-rgb-led-matrix/bindings/python/samples# python3 nbym_video_multichain_pi4.py --horizontal=2 --vertical=2 --video=woman-walking-on-beach.mp4 Matrix H:128 W:256 Image size H:128 W:256
Video frame size H:1080 W:1920
69.9Hzmax: 17835usec
<1920X1080 size woman-walking-on-beach.mp4>
In the photo, black lines are bold, but you cannot feel them with your real eyes. However, flickering can be felt. As you can see from the console log above, the refresh rate is only about 69Hz. Flickering occurs because of this low refresh rate. The reason for the low refresh rate is that it takes a lot of time to process the video frame. The video used in the example above is a 1920X1080 frame. Given that our actual frame size is 256X128, the size of 1920X1080 is too large.
On desktops, there are no problems handling large video frames, but the relatively weak computing power of the Raspberry Pi slows down a lot to handle large video frames. Therefore, it is necessary to reduce the processing burden on the Raspberry Pi by resizing the video file in advance. And to reduce the decoding burden, it is also a good idea to convert it to a video in uncompressed format.
First, adjust the video file using ffmpeg as follows. This can be done on a PC with high processing speed, not on a Raspberry Pi.
ffmpeg -i woman-walking-on-beach.mp4 -s 256x128 woman-s.y4m
ffmpeg -i woman-walking-on-beach.mp4 -s 256x128 woman-s.mp4
Even if you adjust the size, you can see that the size of the uncompressed file is much larger. The uncompressed file (y4m) requires a relatively long time to read from the SD card instead of having a fast processing speed. Therefore, it is difficult to say that either mp4 or y4m files perform better. The performance of the SD card you use will also affect it. Test both types of files and use the ones that perform well. Performance measurement is based on the Hz value displayed on the console screen. The higher this value, the better the performance.
f:\tmp>dir wo* Volume in drive F has no label. Volume Serial Number is A4B8-174E Directory of f:\tmp 07/03/2020 11:13 PM 223,322 woman-s.mp4 07/04/2020 11:03 AM 31,166,232 woman-s.y4m 07/03/2020 10:51 PM 80,557,879 woman-walking-on-beach.mp4 07/04/2020 10:39 AM 476,849 woman.jpg 4 File(s) 112,424,282 bytes 0 Dir(s) 1,480,754,466,816 bytes free
Now let's test it using the modified video file.
@DietPi:/usr/local/src/rpi-rgb-led-matrix/bindings/python/samples# python3 nbym_video_multichain_pi4.py --horizontal=2 --vertical=2 --video=woman-s.y4m Matrix H:128 W:256 Image size H:128 W:256 Video frame size H:128 W:256 94.7Hzmax: 15116usec
The refresh rate is near 94 Hz and it is difficult to notice flickering with the eyes. The woman-s.mp4 file performed similarly.
<256X128 size woman-s.y4m>
Wrapping up
Today, I connected four RGB LED Matrix of size 128X64 to configure the display. Note that an LED Matrix of 64X64 size or larger uses 1/32 multiplexing and can be easily configured.
Since the processing speed decreases as the screen size increases, it is useful to adjust the frame size of the input video file in advance so as not to be too large.
Since the processing speed decreases as the screen size increases, it is useful to adjust the frame size of the input video file in advance so as not to be too large.
You can speed up video frame processing using CPU multicore. If you are interested, see https://opencvcooking.blogspot.com/2020/07/opencv-video-processing-speed-up.html.
I downloaded the video clip(woman-walking-on-beach.mp4) I used for testing from https://mixkit.co/free-stock-video/beach/.
You can download the source codes at https://github.com/raspberry-pi-maker/IoT .
안녕하세요~
답글삭제작은 디스플레이를 만들어 액자 안에 넣고 싶은데, 모듈 고정하는 방법을 찾고 있습니다.
저는 64x64 모듈 두개를 이어붙이려고 하는데요.
사진을 보니 과학상자 스트립같은 철물로 모듈을 고정하셨네요.
어디서 저런 철물을 구할 수 있을까요?
혹시 정말 과학상자 부속품인가요?
예 맞습니다. 과학상자 부품입니다. 주의하실 점은 스트립 홀 간격이 LED 매트릭스의 홀간격과 일치하지 않습니다. 과학상자 부품 파는 곳에 가시면 홀 간격에 약간 여유가 있는 부품(위 사진에서 스테인레스 재질)이 있습니다. 액자에 넣는다고 하시니 이런 것을 몇개 준비해서 모듈 2개 연결만 시켜도 될 듯합니다. 치수 잘 측정하셔서 구매하시면 간단하게 연결 가능할 겁니다.
삭제