LED - 5. Raspberry Pi 4 + DietPi Buster + Electrodragon HAT - Part 1

This post is related to several posts written to use the RGB LED matrix in Raspberry Pi. If you haven't read the previous posts, it can be hard to understand, in which case you ㅡmight read the previous posts in advance.

I've covered in previous post that Rasbian Buster and the RGB Matrix HAT don't fit together.

I was able to play the video successfully. However, noise often appeared on the video screen. To solve this problem, I have tried various things such as changing the power and changing the video format, testing various Raspberry Pi models(2B,3B,4B) but I could not improve it. Clues to solving this problem can be found on Henner Zeller's git page. If you read the Troubleshooting section, there is a description of the brightness instability in the latest version of Rasbian, and introduces issue # 483. This is due to a structural problem in the latest Raspbian kernel. In the contents, the 2016 Jessie version says there are very few problems. So I decided to download the 2016 Jessie Rasbian. Unfortunately, Rasberry Pi4 only supports lateast version of Debian Buster. So to use Jessie Rasbian, you need to use Raspberry 2 or 3.


As of February 2020, the latest Raspberry Pi model is the 4B. And Raspberry Pi 4B, unfortunately, only supports the Raspbian Buster version. Therefore, you can't use the Jessie OS you used to avoid the problems mentioned above. Eventually we come to the conclusion that the Raspberry Pi 4B model cannot be used. I enjoy OpenCV programming with Python 3 on Raspberry Pi. Video processing and image processing in OpenCV often require a lot of CPU resources. Therefore, the inability to use the Raspberry Pi 4B with the latest performance CPUs is a big disadvantage. One of the most popular Debian OSs that can be installed on Raspberry Pi is Rasbian, announced by the Raspberry Pi Foundation. But there's also DietPi, a lighter version of Rasbian. In this post, we will use the DietPi Buster version to solve the above problems and see if we can use Raspberry Pi 4.




 

Materials

Here's what you need for this post:

  • Raspberry Pi 4B(2GB Memory) : 1EA
  • Electrodragon RGB Matrix HAT : 1EA
  • P3 64X32 RGB LED Matrix : 4EA
  • Hub75 cable : 4EA
  • LED Power cable : 2EA
  • 5V 20A Power supply : 1EA
<RGB LED matrices   Electrodragon HAT   Raspberry Pi 4B>

<hub75 cable    LED power cable  5V 10A Power supply>


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.



Rasbian Jessie
Rasbian Buster Lite
DietPi Buster
Raspberry Pi
3B
4B (2GB Memory)
4B (2GB Memory)
OpenCV
3.1
4.1.1
4.1.1

Compare Rasbian Buster Lite, DietPi Buster, Rasbian Jessie

Rasbian Jessie



root@raspberrypi:~# cat /etc/*release*
PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
NAME="Raspbian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL=http://www.raspbian.org/RaspbianBugs


root@raspberrypi:~# free -m
             total       used       free     shared    buffers     cached
Mem:           925        143        782          6         14         95
-/+ buffers/cache:         33        892
Swap:           99          0         99


root@raspberrypi:~# service --status-all
 [ - ]  alsa-utils
 [ + ]  avahi-daemon
 [ - ]  bluetooth
 [ - ]  bootlogs
 [ - ]  bootmisc.sh
 [ - ]  checkfs.sh
 [ - ]  checkroot-bootclean.sh
 [ - ]  checkroot.sh
 [ + ]  console-setup
 [ + ]  cron
 [ + ]  dbus
 [ + ]  dhcpcd
 [ + ]  dphys-swapfile
 [ + ]  fake-hwclock
 [ - ]  hostname.sh
 [ - ]  hwclock.sh
 [ + ]  kbd
 [ + ]  keyboard-setup
 [ - ]  killprocs
 [ + ]  kmod
 [ - ]  motd
 [ - ]  mountall-bootclean.sh
 [ - ]  mountall.sh
 [ - ]  mountdevsubfs.sh
 [ - ]  mountkernfs.sh
 [ - ]  mountnfs-bootclean.sh
 [ - ]  mountnfs.sh
 [ + ]  networking
 [ - ]  nfs-common
 [ + ]  ntp
 [ - ]  plymouth
 [ - ]  plymouth-log
 [ + ]  procps
 [ + ]  raspi-config
 [ + ]  rc.local
 [ - ]  rmnologin
 [ - ]  rpcbind
 [ - ]  rsync
 [ + ]  rsyslog
 [ - ]  saned
 [ - ]  sendsigs
 [ + ]  ssh
 [ - ]  sudo
 [ + ]  triggerhappy
 [ + ]  udev
 [ + ]  udev-finish
 [ - ]  umountfs
 [ - ]  umountnfs.sh
 [ - ]  umountroot
 [ + ]  urandom
 [ - ]  x11-common



Rasbian Buster Lite


root@raspberrypi:~# cat /etc/*release*
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

root@raspberrypi:~# free -m
              total        used        free      shared  buff/cache   available
Mem:           1939          55        1757           8         126        1797
Swap:            99           0          99


root@raspberrypi:~# service --status-all
 [ - ]  alsa-utils
 [ + ]  avahi-daemon
 [ + ]  bluetooth
 [ - ]  console-setup.sh
 [ + ]  cron
 [ + ]  dbus
 [ + ]  dhcpcd
 [ + ]  dphys-swapfile
 [ + ]  fake-hwclock
 [ - ]  hwclock.sh
 [ - ]  keyboard-setup.sh
 [ + ]  kmod
 [ + ]  networking
 [ - ]  nfs-common
 [ - ]  paxctld
 [ + ]  procps
 [ + ]  raspi-config
 [ ? ]  rng-tools
 [ - ]  rpcbind
 [ - ]  rsync
 [ + ]  rsyslog
 [ + ]  ssh
 [ - ]  sudo
 [ + ]  triggerhappy
 [ + ]  udev


DietPi Buster



root@DietPi:~# cat /etc/*release*
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

root@DietPi:~# free -m
              total        used        free      shared  buff/cache   available
Mem:           1989          38        1801          17         150        1858
Swap:            58           0          58

root@DietPi:~# service --status-all
 [ - ]  console-setup.sh
 [ + ]  cron
 [ + ]  fake-hwclock
 [ - ]  hwclock.sh
 [ - ]  keyboard-setup.sh
 [ + ]  kmod
 [ + ]  networking
 [ + ]  procps
 [ + ]  resolvconf
 [ ? ]  rng-tools
 [ + ]  ssh
 [ - ]  sudo
 [ + ]  udev
 [ - ]  x11-common


The results show that DietPi is a very lightweight operating system that eliminates unnecessary services and has the most memory available.


DietPi Buster additional setup

Insert the SD card with the DietPi Buster operating system into your Raspberry Pi 4. If you followed the instructions above, you would also have OpenCV 4.1.1 installed. The following explanation assumes that OpenCV 4.1.1 is installed.

Disable Sound Driver

Open the /boot/config.txt file with an editor, and check that "dtparam = audio = off". If this value is "on", modify it to "off", then reboot. DietPi's default value should be "off".

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)


Raspberry Pi 4, Electrodragon RGB LED Matrix HAT

Now the software is ready.
It's time to connect the hardware. I'm going to use 4 P3-64X32 LED matrices.



  • Power off the Raspberry Pi 4B and connect the RGB LED matrix HAT to it. 
  • Connect HAT's first hub75 socket and the RGB LED Matrix with a cable.
  • Connect LED's power barrel jack to your 5V power supply. The power supply must be capable of supplying at least 8A of current.
  • Power on the Raspberry Pi 4B.

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 2 X 2 RGB LED Matrix

I'm going to use a code that I've used at https://iot-for-maker.blogspot.com/2020/02/led-5-lets-make-large-led-display-part.html.
But before you run the code, you should customize the code for the Raspberry Pi4 and Electrodragon HAT. Of course, you can adjust this setting using runtime parameters.

Raspberry Pi 4 is too fast, so set the gpio_slowdown value to 4
options.gpio_slowdown = 4.0

Now I'm going to use the Electrodragon HAT, so set the hardware_mapping to "regular".
options.hardware_mapping = 'regular'



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 * args.vertical
options.parallel = 1
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.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():
    imgs = []
    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)
        imgs.append(im)

    if(ret == False):
        break

    im_pils = []
    for img in imgs:
        for x in range (args.vertical):
            i = img[options.rows * x: options.rows * (x + 1), 0:canvas_w]
            h, w, c = i.shape
            # print('split image H:%d W:%d'%(h, w))
            if ((args.vertical - x) % 2) == 0:    #-> flip
                i = cv2.flip(i, 0) #vertical
                i = cv2.flip(i, 1) #horizontal
            if(x == 0):
                final = i
            else:
                final = cv2.hconcat([final, i])   #stack horizontally

        h, w, c = final.shape
        # print('final image H:%d W:%d'%(h, w))
        im_pil = Image.fromarray(final)
        im_pils.append(im_pil)
        # matrix.Clear()
        #matrix.SetImage(im_pil, 0)

    double_buffer.SetImage(im_pils[0])
    double_buffer.SetImage(im_pils[1], w)
    double_buffer = matrix.SwapOnVSync(double_buffer)

    elapsed = time.time() - start
    #print('elapsed:%f'%(elapsed))
    time.sleep(max([0, 0.066 - elapsed]))
<nbym_video_pi4.py>


When the above code is executed in Raspberry Pi 4 + Rasbian Buster OS, the screen becomes unstable. However, the above code was stable when run on Raspberry Pi 3 + Rasbian Jessie.
This time 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_pi4.py --video=Frozen_s.y4m --horizontal=2 --vertical=2
Matrix H:32 W:256
Image size H:64 W:128                                                                                                             161.0Hz 594usec

In the code above, I made the refresh rate of the image currently displayed in the LED matrix. It can be seen from the execution result that a refresh rate of 161 Hz is displayed. If it is this value, there is no problem to use.

<RGB LED matrix screen>

Raspberry Pi 4 not only improved CPU performance compared to previous versions, but also increased memory speed and capacity. If you monitor the system with htop while playing the video, the CPU usage of Raspberry Pi 4 is lower compared to the Raspberry Pi 3 with Jessie, and the free memory is much higher due to the increased memory capacity.

<Raspberry Pi 4(2GB) + DietPi Buster performance when playing the movie the LED>

<Raspberry Pi 3 + Rasbian Jessie performance when playing the movie the LED>

Wrapping up

Fortunately, the instability of the LED screen has gone. Therefore, the instability of the previous Rasbian Buster is more likely to be caused by the Rasbian optimization process rather than by the Debian Buster kernel problem.

Continued at https://iot-for-maker.blogspot.com/2020/02/led-5-raspberry-pi-4-dietpi-buster_23.html

You can download the source codes here(https://github.com/raspberry-pi-maker/IoT)











댓글

이 블로그의 인기 게시물

LED-12. Displaying HDMI Contents

LED-11. Make a very big size 384 X 512 RGB Matrix #6(final)