hzeller / rpi-rgb-led-matrix

Controlling up to three chains of 64x64, 32x32, 16x32 or similar RGB LED displays using Raspberry Pi GPIO
GNU General Public License v2.0
3.64k stars 1.16k forks source link

Glitch cause by running desktop? #1192

Open louiselessel opened 3 years ago

louiselessel commented 3 years ago

Hi,

Does this look like a glitch caused by running the Desktop? It happens once every 10-20 seconds or so (once in a while, not at regular intervals).

https://www.dropbox.com/s/2nvlqxoakbse0qb/glitch.MOV?dl=0

I am building a series of python shader examples that will run on the pi (using pi3d), and was hoping to be able to run them on the matrix as well. This is my first time using the matrixes.

Since I am running pi3d it is necessary to run a small shader window (32x32 pixel) like this (in front of the terminal)https://www.dropbox.com/s/b6ndm40gg9cybmn/running%20from%20terminal.JPG?dl=0

I am trying to see if I can somehow run it from the terminal without initializing the desktop on bootup. I think that could be the issue, based on reading your troubleshooting section. But no luck so far... So before I go far down that route, I just wanted to know if that might even be the cause?

I have messed around with all of the settings, including options.pwm_lsb_nanoseconds = 200, GPIO slowdown.. and followed all of the instructions on reserving a core, disabling sound, etc. and I just have this one glitch left to deal with. (Have tested several matrixes, it happens regardless).

Setup here: https://www.dropbox.com/s/x9cjhruemwpjetr/setup.jpg?dl=0 Cable length has no effect on this glitch. Hzeller board on Raspberry pi 4. Power supply gives (S300-5) 5.15V, 60A

Also tested Adafruit Bonnet, and Adafruit HAT. Get a similar, but worse, more constant, glitch (https://www.dropbox.com/s/dxrmor24oliattj/Random%20lines.MOV?dl=0)

I pasted the systemctl and the top command, but I am not sure what to look for, so, does anything below look weird?

MY CODE

#!/usr/bin/env python

import time
import demo
import pi3d
import datetime
from rgbmatrix import RGBMatrix, RGBMatrixOptions
from PIL import Image
from PIL import ImageDraw

#-------------------------------------------------
# Configuration for the shader

(W, H) = (32, 32) # Windowed
# For scale, make sure the numbers are divisible to the resolution with no remainders (use even numbers between 0 and 1). 1.0 is full non-scaled resolution.
SCALE = 1.0 # downscale the shadertoy shader resolution

timeScalar = 0.6 # for scaling the speed of time
fps = 60 # framerate

BACKGROUND_COLOR = (0.0, 0.0, 0.0, 0.0)

display = pi3d.Display.create(window_title='shader',
                              w=W, h=H, frames_per_second=fps,
                              background=BACKGROUND_COLOR,
                              #display_config=pi3d.DISPLAY_CONFIG_HIDE_CURSOR | pi3d.DISPLAY_CONFIG_MAXIMIZED,
                              use_glx=True
                              )
#print(display.opengl.gl_id) # the type of glsl your pi is running

if W is None or H is None:
 (W, H) = (display.width, display.height)
 print('setting display size to ' + str(W) + ' ' + str(H))

## shadertoy shader stuff ##
sprite = pi3d.Triangle(corners=((-1.0, -1.0),(-1.0, 3.0),(3.0, -1.0)))
shader = pi3d.Shader('lensflare_a')
sprite.set_shader(shader)

## offscreen texture stuff ##
cam = pi3d.Camera(is_3d=False)
postsh = pi3d.Shader('post_vanilla')
post = pi3d.PostProcess(camera=cam, shader=postsh, scale=SCALE)

## interactive inputs ##
kbd = pi3d.Keyboard()
mouse = pi3d.Mouse() # pi3d.Mouse(restrict = True) # changes input coordinates
mouse.start()
MX, MY = mouse.position()
MXC, MYC = mouse.position()
MC = mouse.button_status() # 8 = hover, 9 = right Click down, 10 = left C, 12 = middle C
MouseClicked = False

## set up time ##
iTIME = 0
iTIMEDELTA = 0
iFRAME = 0
iDate = datetime.datetime.now()
#print ("The current local date time is ", iDate)
(YR, MTH, DAY) = (iDate.year, iDate.month, iDate.day)
iDateSecondsSinceMidnight = iDate.hour*60*60 + iDate.minute*60 + iDate.second
#print (iDateSecondsSinceMidnight)

## pass shadertoy uniforms into our base shader from shadertoy ##
sprite.unif[0:2] = [W, H]       # iResolution
sprite.unif[2] = iTIME          # iTime - shader playback time
sprite.unif[3] = iTIMEDELTA     # iTimeDelta - render time (in seconds)
sprite.unif[4] = SCALE          # iScale - scale for downscaling the resolution of shader
sprite.unif[5] = iFRAME         # iFrame - shader playback frame
sprite.unif[6:8] = [MX, MY]     # iMouse - xpos, ypos (set while button held down)
sprite.unif[9:11] = [MXC, MYC]    # iMouse - xposClicked, yposClicked (set on click)
sprite.unif[12:15] = [YR, MTH, DAY] # iDate
sprite.unif[15] = iDateSecondsSinceMidnight  # seconds since midnight
# iChannel0...3, iChannelTime and iChannelResolution not implemented yet

## pass own uniforms into shader (see notes.py to understand the addressing) ##
#sprite.unif[48:51] = [var1, var2, var3] # ownVar1 This is how you can pass in own variables to uniforms
#sprite.unif[57:60] = [var1, var2, var3] # ownVar2 You can add from 48 - 59, so this is the last address! 

## pass uniforms into postprocessing postsh ##
post.draw({0:W, 1:H, 2:iTIME, 3:iTIMEDELTA, 4:SCALE, 5:iFRAME,
           6:MX, 7:MY, 9:MXC, 10:MYC,
           12:YR, 13:MTH, 14:DAY, 15:iDateSecondsSinceMidnight})    

# time at start
tm0 = time.time()
last_time = 0

#-------------------------------------------------

# Configuration for the matrix
# - More info in ReadMe here https://github.com/hzeller/rpi-rgb-led-matrix
# - https://github.com/hzeller/rpi-rgb-led-matrix/blob/master/bindings/python/rgbmatrix/core.pyx
options = RGBMatrixOptions()
options.rows = 32
options.cols = 32
options.chain_length = 1
options.parallel = 1
options.hardware_mapping = 'regular'  # If you have an Adafruit HAT: 'adafruit-hat'
options.brightness = 100
#options.pwm_bits = 11    #default 11
options.pwm_lsb_nanoseconds = 200
#options.scan_mode = 0    #default 0
#options.multiplexing = 0   #default 0, <1..17>
#options.row_address_type = 0   #default 0, <0..4>
#options.disable_hardware_pulsing = False   # debugging if nothing on panel - sound setting
options.show_refresh_rate = True
#options.inverse_colors = False
#options.led_rgb_sequence = "RGB"
#options.pixel_mapper_config = 
#options.panel_type = "FM6126A"   #Current supported types: FM6126A or FM6127
#options.pwm_dither_bits = 0    #default 0
options.limit_refresh_rate_hz = 200
options.gpio_slowdown = 2
#options.daemon = False    #  if it looks weird, reboot
options.drop_privileges = True

matrix = RGBMatrix(options = options)

#-------------------------------------------------
# PUT SHADER ON MATRIX

while display.loop_running():
    # drawing
    post.start_capture()
    sprite.draw()
    post.end_capture()
    post.draw()

    ## inputs - mouse ##
    MX, MY = mouse.position()
    MVX, MVY = mouse.velocity()
    MC = mouse.button_status()
    #print('(' + str(MX) + ', ' + str(MY) + ')')

    # if mouse click on this frame (any button)
    if MC == 9 or MC == 10 or MC == 12 and MouseClicked == False:
        (MXC, MYC) = (MX, MY)
        sprite.unif[9:11] = [MXC, MYC]    # update iMouse - xposClicked, yposClicked
        post.draw({9:MXC, 10:MYC})
        #print('(' + str(MXC) + ', ' + str(MYC) + ')')
        MouseClicked = True
    # while mouse is clicked (button held down)
    if MouseClicked == True:
        sprite.unif[6:8] = [MX, MY]       # update iMouse - xpos, ypos
        post.draw({6:MX, 7:MY})
    # mouse button released    
    if MC == 8 and MouseClicked == True:
        MouseClicked = False

    # inputs - keyboard #
    k = kbd.read()
    if k == 27:
        kbd.close()
        mouse.stop()
        display.stop()
        break

    # setting non-interactive uniforms #
    iTIME = (time.time() - tm0) * timeScalar    # change the timeScalar to slow time
    iDate = datetime.datetime.now()
    (YR, MTH, DAY) = (iDate.year, iDate.month, iDate.day)
    iDateSecondsSinceMidnight = iDate.hour*60*60 + iDate.minute*60 + iDate.second
    iTIMEDELTA = display.time - last_time # display.time is set at start of each frame
    last_time = display.time

    # pass only the changed shadertoy uniforms into our base shader from shadertoy #
    sprite.unif[2] = iTIME          # iTime - shader playback time
    sprite.unif[3] = iTIMEDELTA     # iTimeDelta - render time (in seconds) ----- not implemented yet
    sprite.unif[5] = iFRAME         # iFrame - shader playback frame
    sprite.unif[12:15] = [YR, MTH, DAY] # iDate
    sprite.unif[15] = iDateSecondsSinceMidnight  # seconds since midnight

    # pass only the changed uniforms into postprocessing postsh #
    post.draw({2:iTIME, 3:iTIMEDELTA, 5:iFRAME, 12:YR, 13:MTH, 14:DAY, 15:iDateSecondsSinceMidnight})

    # updating variables #
    iFRAME += 1
    #print(int(FRAME/fps))    # calculate seconds based on framerate, not time.time

    # draw the shader buffer into a PIL image
    image = Image.fromarray(pi3d.screenshot())
    matrix.SetImage(image,0,0)

`systemctl

UNIT LOAD ACTIVE SUB DESCRIPTION
proc-sys-fs-binfmt_misc.automount loaded active waiting Arbitrary Executable File sys-devices-platform-emmc2bus-fe340000.emmc2-mmc_host-mmc0-mmc0:0001-block-mmcblk0-mmcblk0p1.device loaded active plugged /sys/devices/platform/emm sys-devices-platform-emmc2bus-fe340000.emmc2-mmc_host-mmc0-mmc0:0001-block-mmcblk0-mmcblk0p2.device loaded active plugged /sys/devices/platform/emm sys-devices-platform-emmc2bus-fe340000.emmc2-mmc_host-mmc0-mmc0:0001-block-mmcblk0.device loaded active plugged /sys/devices/platform/emm sys-devices-platform-scb-fd580000.ethernet-net-eth0.device loaded active plugged /sys/devices/platform/scb sys-devices-platform-soc-fe201000.serial-tty-ttyAMA0-hci0.device loaded active plugged /sys/devices/platform/soc sys-devices-platform-soc-fe201000.serial-tty-ttyAMA0.device loaded active plugged /sys/devices/platform/soc sys-devices-platform-soc-fe300000.mmcnr-mmc_host-mmc1-mmc1:0001-mmc1:0001:1-net-wlan0.device loaded active plugged /sys/devices/platform/soc sys-devices-virtual-block-ram0.device loaded active plugged /sys/devices/virtual/bloc sys-devices-virtual-block-ram1.device loaded active plugged /sys/devices/virtual/bloc sys-devices-virtual-block-ram10.device loaded active plugged /sys/devices/virtual/bloc sys-devices-virtual-block-ram11.device loaded active plugged /sys/devices/virtual/bloc sys-devices-virtual-block-ram12.device loaded active plugged /sys/devices/virtual/bloc sys-devices-virtual-block-ram13.device loaded active plugged /sys/devices/virtual/bloc sys-devices-virtual-block-ram14.device loaded active plugged /sys/devices/virtual/bloc sys-devices-virtual-block-ram15.device loaded active plugged /sys/devices/virtual/bloc sys-devices-virtual-block-ram2.device loaded active plugged /sys/devices/virtual/bloc sys-devices-virtual-block-ram3.device loaded active plugged /sys/devices/virtual/bloc sys-devices-virtual-block-ram4.device loaded active plugged /sys/devices/virtual/bloc sys-devices-virtual-block-ram5.device loaded active plugged /sys/devices/virtual/bloc sys-devices-virtual-block-ram6.device loaded active plugged /sys/devices/virtual/bloc sys-devices-virtual-block-ram7.device loaded active plugged /sys/devices/virtual/bloc `

`pi@raspberrypi:~ $ top

top - 16:55:51 up 57 min, 2 users, load average: 0.83, 0.41, 0.38 Tasks: 174 total, 1 running, 173 sleeping, 0 stopped, 0 zombie %Cpu(s): 9.3 us, 2.7 sy, 0.0 ni, 88.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st MiB Mem : 3776.5 total, 2449.9 free, 625.4 used, 701.3 buff/cache MiB Swap: 100.0 total, 100.0 free, 0.0 used. 2781.6 avail Mem

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2965 daemon 20 0 152884 59052 34768 S 40.1 1.5 0:54.87 python3
501 root 20 0 150880 71788 51372 S 6.6 1.9 1:59.82 Xorg
903 pi 20 0 167468 49088 38432 S 2.6 1.3 0:08.35 lxterminal
1363 pi 20 0 86036 38636 14216 S 2.6 1.0 1:10.55 thonny
192 root -2 0 0 0 0 S 1.3 0.0 0:27.00 v3d_render
191 root -2 0 0 0 0 S 1.0 0.0 0:19.87 v3d_bin
2520 pi 20 0 590812 231116 81400 S 0.7 6.0 1:31.76 chromium-browse
3002 pi 20 0 10416 3152 2620 R 0.7 0.1 0:00.09 top
346 root 20 0 13148 5880 5200 S 0.3 0.2 0:00.67 systemd-logind
960 pi 20 0 543380 141052 85204 S 0.3 3.6 1:25.78 chromium-browse
1 root 20 0 34712 8172 6492 S 0.0 0.2 0:03.91 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kthreadd
3 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_gp
4 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_par_gp
8 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 mm_percpu_wq
9 root 20 0 0 0 0 S 0.0 0.0 0:00.47 ksoftirqd/0
10 root 20 0 0 0 0 I 0.0 0.0 0:02.91 rcu_sched `

jaygarcia commented 3 years ago

Have you considered limiting the Linux OS to 3 Cores and dedicating one to this library?

xuniuer commented 3 years ago

Have you considered limiting the Linux OS to 3 Cores and dedicating one to this library?

How to do? Could you provide more details? I find SSH communication from Host to RPi will cause sudden faint flicking.

jaygarcia commented 3 years ago

Hi @xuniuer ,

edit /boot/cmdline.txt , add isolcpus=3, reboot.

jaygarcia commented 3 years ago

Another option may be to overclock the pi a little? Just a thought.

xuniuer commented 3 years ago

Hi @xuniuer ,

edit /boot/cmdline.txt , add isolcpus=3, reboot.

I consult the settings of isolcpus=3 as refer: https://yosh.ke.mu/raspberry_pi_isolating_cores_in_linux_kernel As understood, only a process is moved onto the core, user-process time would not be stolen - RTOS.

I browse the source code: the library indeed uses the fourth core, by default, to do refresh. I will have a try.