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

display camera output on rpi-rgb-led-matrix with picamera #714

Closed matzehuels closed 5 years ago

matzehuels commented 5 years ago

I am struggling with a project that I am working on currently. Essentially, I want to capture an image using picamera (see https://github.com/waveform80/picamera) and then display it on an RGB LED-matrix. It seems, somehow both packages cant work together and I can not really figure out why and how to fix this issue.

When I run the minimal example below, I get an error saying "* failed to open vchiq instance"


from rgbmatrix import RGBMatrix, RGBMatrixOptions

# Configuration for the matrix
options = RGBMatrixOptions()
options.led_rgb_sequence = 'RBG'
options.rows = 64
options.cols = 64
options.chain_length = 1
options.parallel = 1
options.hardware_mapping = 'adafruit-hat'
matrix = RGBMatrix(options = options)

# Output to LED Matrix

import time
import picamera
import picamera.array
from PIL import Image

camera = picamera.PiCamera(0)
stream = picamera.array.PiRGBArray(camera)
camera.resolution = (100, 100)

camera.start_preview()
time.sleep(2)
camera.capture(stream, 'rgb')

image = Image.fromarray(stream.array)
image.thumbnail((matrix.width, matrix.height), Image.ANTIALIAS)
matrix.SetImage(image)
hzeller commented 5 years ago

Does the camera need root access ? By default, the RGBMatrix construction will drop privileges to nobody/nobody. If you want to stay root, make sure to set the change the runtime options to not drop root privileges.

In the c++ header you see the description of the Runtime struct. You have to set the right value in Python.

hzeller commented 5 years ago

did you get it to work ?

hygeanne commented 5 years ago

Hello,

I am working on this project as well and I came across is exact same issue. I did try your suggestion, but it did not work for me.

This might be an issue that has not been well documented yet, but I've tried various things fix it, including: https://raspberrypi.stackexchange.com/questions/19436/how-can-i-permanently-fix-dev-vchiq-permission-errors

I ran this exact code in my setup, and tested each line. It turns out, that the line "matrix = RGBMatrix(options = options)" was the line that's the problem, but I have no idea why. (Obviously, without it the matrix functions wouldn't work so those were commented out as well. But the "matrix = RGBMatrix(options = options)" line alone should have still executed).

I played around with all the possibilities of where I could put that line, But I'd either get the same error, or the program would get completely stuck.

Is it possible that the GPIO pin of the camera and rgb-matrix could be conflicting with each other, thus not allowing access to the camera?

hzeller commented 5 years ago

So did you try the --led-no-drop-privs option as suggested above ?

hygeanne commented 5 years ago

Thanks for your reply! Yes sir, I did. Unfortunately, with no luck.

On Sun, Dec 9, 2018 at 5:06 PM Henner Zeller notifications@github.com wrote:

So did you try the --led-no-drop-privs option as suggested above ?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/hzeller/rpi-rgb-led-matrix/issues/714#issuecomment-445576262, or mute the thread https://github.com/notifications/unsubscribe-auth/Ao1Y3fgpVW1eElOPZjwaJixWRGsTFlTWks5u3YlUgaJpZM4YPe9b .

hzeller commented 5 years ago

so your camera probably uses some of the functionality the matrix uses as well. If it is the hardware pulse generator, try --led-no-hardware-pulse.

matzehuels commented 5 years ago

Sorry for getting back to this with delay. I got it running by not dropping the Sudo rights as hzeller suggested. Also remember to actually run the process as sudo!

hygeanne commented 5 years ago

Hi! Turns out I completely misread hzeller's original response as manually entering into the command line, not actually setting the value in the code. Thanks again!

marcmerlin commented 3 years ago

Well, how about that, that was my problem too @hzeller , can't believe I didn't find this bug. In my case I had to add ropt.drop_privileges = -1; before RGBMatrix *rgbmatrix = rgb_matrix::CreateMatrixFromOptions(defaults, ropt); this allows the picam to still work after the RGBMatrix is initialized.