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.67k stars 1.17k forks source link

[Python] Changing some matrix options during runtime not possible? #1522

Open marvinmarmelade opened 1 year ago

marvinmarmelade commented 1 year ago

Hello,

I am working with the python bindings and i'm trying to change matrix options after initialization:

#!/usr/bin/env python
import time
import sys

from rgbmatrix import RGBMatrix, RGBMatrixOptions
from PIL import Image

image_file = PATH_TO_IMAGE

image = Image.open(image_file)

options = RGBMatrixOptions()
options.rows = 32
options.cols = 64
options.chain_length = 1
options.pwm_bits = 5
options.pwm_lsb_nanoseconds = 200
options.hardware_mapping = 'regular'
options.show_refresh_rate = True

matrix = RGBMatrix(options = options)

image.thumbnail((matrix.width, matrix.height), Image.ANTIALIAS)
matrix.SetImage(image.convert('RGB'))

time.sleep(2)

matrix.Clear()

options.chain_length = 4

matrix.SetImage(image.convert('RGB'))

time.sleep(2)

this obviously doesn't work, so i tried another approach where i deleted the matrix object and created another one with different options:


matrix.Clear()
del matrix

#create new matrix instance with different options
options.chain_length = 4
matrix = RGBMatrix(options = options)

matrix.SetImage(image.convert('RGB'))

time.sleep(2)

this actually works but it throws the following error message:

Can't set realtime thread priority=99: Operation not permitted.
You are probably not running as root ?
This will seriously mess with color stability and flicker
of the matrix. Please run as `root` (e.g. by invoking this
program with `sudo`), or setting the capability on this
binary by calling
sudo setcap 'cap_sys_nice=eip' /usr/bin/python3.9

now comes the actual issue: changing an option like 'pwm_lsb_nanoseconds' throws the same error message but there are no visible changes on the display. How can it be that some options can be changed and others can't? Has this something to do with hardware initialization and if so, how can i properly un-initialize the hardware?

combs commented 1 year ago

Not a maintainer, just a rando -- I think it's because the library gets rid of root privileges as soon as it initializes the hardware. As it says in the error, subsequent reinitialization doesn't work because it's not running as root anymore.

You can add this to keep it from happening,

options.drop_privileges = False