BalenaOS - rPi0W - Python Pygame - No available video device

Hi all,
This is a newbie question but I’ve searched and can’t find a clear answer.

I want to use balenaOS to run a Python application that connects to my server, downloads an image and displays it on the connected HDMI screen. A simple small digital photo frame I can give to an elderly relative that lives a few hours away.

I have written the Python script and it uses Pygame to draw the image onto the display.
I have it running fine using on my personal machine, and on the target device when using a small Buildroot instance but thinking ahead I need to be able to sort out the wifi easily and update it if needed etc, so Wifi-Connect and BalenaOS lead me here.

I’ve looked at BalenaDash and I can see the limitation is 1GB of ram. I assume this is because it’s using electron or chrome as the dashboard platform.

Is there another suitable base project with HDMI and Python setup?

When I do a fresh BalenaOS setup and then push my code to the device locally which builds in the requirements all I see in the terminal is:

error: XDG_RUNTIME_DIR not set in the environment.
....
....
pygame.error: No available video device

No matter what I do I’m going around in circles, which is likely my general new-ness to the platform.

Any help or pointers in the right direction would be much appreciated!

Hi @illwrks,

Can you share more details relating to python script and how you try to access the display? Also, the balenaDash as you mentioned might not fit but can be a good starting point to see how it exports the display: https://github.com/balenalabs/balena-dash/blob/master/kiosk/start.sh

-Nitish

@nitish Thanks for responding.

I have a basic Python Pygame script, not very different to this test script on the link below (which also doesn’t work)

When the script is run it shows the error:

error: XDG_RUNTIME_DIR not set in the environment.

and it specifies line 33:

game_screen = pygame.display.set_mode(SCREEN_SIZE)

and states:

"pygame.error: No available video device"

Hi

Have you looked at our blog post about running an X11 application?

@anujdeshpande Thanks for the link however it appears to suggest accessing and controlling an application running on a headless device that can only be interacted with using a GUI.

This is different from my need as I don’t need to login and control a GUI remotely, I need the my script to display a photo on the HDMI-connected screen, which the software can’t seem to find.

Because it can’t find the HDMI connected screen it suggests a driver might be missing, or a configuration file, from the RaspberryPi Zero BalenaOS build?
The terminal output is shown on screen, as well as the Balena logo so I feel like it must be some configuration problem, or driver issue with Python perhaps?

Hi

Seeing the logo or the terminal output is not the same as running an X environment.

  1. The balena logo that you see is part of the boot process - it’s not the same as compared to what you have when you are running a proper container.
  2. The terminal logs that you might see when the device boots up are also similar.

When you run your pygame application on Raspbian, or any other Linux - you can run it because there’s a graphical environment that the OS has setup for you. By default, balenaOS does not set that up for you. That’s why you’ll have to set that up for yourself

So in this case - in the example linked in the blog, you will find things such as x11-utils that are installed via the docker file - balena-vnc-example/Dockerfile.template at master · balena-io-playground/balena-vnc-example · GitHub
These are precisely the kind of things you need to do in order to get an X11 environment up and running (along with some other things that are mentioned in the blog)

I recommend you follow the blog to get some examples from there working, and then start removing unnecessary things like the calculator, etc. to suit your needs.

@anujdeshpande Brilliant thank you! I will follow this guide and report back, hopefully with success.