User avatar
liamkennedy
Posts: 62
Joined: Thu Dec 19, 2013 10:12 am
Contact: Website Facebook Twitter

Multiscreen=AWESOME- how to support via Python/PyGame?

Tue Sep 15, 2015 5:25 pm

Wow. It's so great to have the two-screen option now. I'm messing around with that via my ISSAbove stuff. It's great to be able to direct the live video from the Space Station out to the HDMI while other info screens appear on the Touchscreen.

Now for the question. How can I have my python/pygame code support both displays?

This is the init code I am currently using - but it just picks up whatever is the "default" display.

Code: Select all

class pyscreen :
    screen = None;
    
    def __init__(self):
        "Ininitializes a new pygame screen using the framebuffer"
        # Based on "Python GUI in Linux frame buffer"
        # http://www.karoltomala.com/blog/?p=679
        disp_no = os.getenv("DISPLAY")
        if disp_no:
            pass
            #print "I'm running under X display = {0}".format(disp_no)
        
        # Check which frame buffer drivers are available
        # Start with fbcon since directfb hangs with composite output
        drivers = ['fbcon', 'directfb', 'svgalib']
        found = False
        for driver in drivers:
            # Make sure that SDL_VIDEODRIVER is set
            if not os.getenv('SDL_VIDEODRIVER'):
                os.putenv('SDL_VIDEODRIVER', driver)
            try:
                pygame.display.init()
            except pygame.error:
                print 'Driver: {0} failed.'.format(driver)
                continue
            found = True
            break
    
        if not found:
            raise Exception('No suitable video driver found!')
Any clues would be very much appreciated - thanks

-Liam

User avatar
topguy
Posts: 5392
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Multiscreen=AWESOME- how to support via Python/PyGame?

Tue Sep 15, 2015 5:50 pm

I have a feeling that if (or when) you can get pygame to use the screen of your choice then its probably best to see if you can create two programs and have them control only one screen each. I have a feeling pygame.display.init() is written to be called only once and initializes a lot of global variables.

Dr H
Posts: 14
Joined: Sat Sep 12, 2015 7:58 pm

Re: Multiscreen=AWESOME- how to support via Python/PyGame?

Tue Sep 15, 2015 6:03 pm

Hi Liam,

so far I have not managed to have both screens running at the same time, and the only option to do so, so far I have read, was running videos on OMXPlayer. Do I need special adjustments to the config-files or alike? is there a trick to have one desktop on the touch screen and another on the big screen?

Would be nice if you, or someone, else might help.

-H

fruitoftheloom
Posts: 19353
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: Multiscreen=AWESOME- how to support via Python/PyGame?

Tue Sep 15, 2015 6:09 pm

Dr H wrote:Hi Liam,

so far I have not managed to have both screens running at the same time, and the only option to do so, so far I have read, was running videos on OMXPlayer. Do I need special adjustments to the config-files or alike? is there a trick to have one desktop on the touch screen and another on the big screen?

Would be nice if you, or someone, else might help.

-H
There are a similar queery:

viewtopic.php?f=91&t=120728

viewtopic.php?f=108&t=120541
adieu

My other Computer is an Asus CS10 ChromeBit running Chrome Operating System.
HP Envy 4500 Wireless Printer supported by HPLIP software in Raspbian Stretch.

User avatar
liamkennedy
Posts: 62
Joined: Thu Dec 19, 2013 10:12 am
Contact: Website Facebook Twitter

Re: Multiscreen=AWESOME- how to support via Python/PyGame?

Tue Sep 15, 2015 6:13 pm

Dr H wrote:so far I have not managed to have both screens running at the same time, and the only option to do so, so far I have read, was running videos on OMXPlayer. Do I need special adjustments to the config-files or alike? is there a trick to have one desktop on the touch screen and another on the big screen?
-H
All I am doing right now is pushing videos out to the HDMI monitor via the omxplayer trick. No special config is needed to make that happen - just add the --display=5 option to the commandline.

If I figure out how to get PyGame to support both screens I'll definitely be back here - BUT - the answer to THAT question is why I asked THIS question.

User avatar
liamkennedy
Posts: 62
Joined: Thu Dec 19, 2013 10:12 am
Contact: Website Facebook Twitter

Re: Multiscreen=AWESOME- how to support via Python/PyGame?

Tue Sep 15, 2015 6:17 pm

topguy wrote:I have a feeling that if (or when) you can get pygame to use the screen of your choice then its probably best to see if you can create two programs and have them control only one screen each. I have a feeling pygame.display.init() is written to be called only once and initializes a lot of global variables.
Well - it's not out of the question for me to do that - it just sure would make things easier to have it in one piece of code. I do already have a couple of modules running - with interprocess comms happening via 0mq (although there are probably better ways).

gsh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1382
Joined: Sat Sep 10, 2011 11:43 am

Re: Multiscreen=AWESOME- how to support via Python/PyGame?

Tue Sep 15, 2015 6:18 pm

Question is how does pygame access the screen, if it uses /dev/fb0 to write pixels to the screen then it will not work right now...

Whereas if it uses direct access of a dispmanx framebuffer then it is possible to change it to output to the other screen by changing the parameter to dispmanx_display_open this is what I recently did to get Kivy to output to the other screen...

(Kivy now supports this upstream if anyone wants to have go, I've got X running on my HDMI and kivy on the LCD and it all seems to work well)

Gordon
--
Gordon Hollingworth PhD
Raspberry Pi - Director of Software Engineering

User avatar
liamkennedy
Posts: 62
Joined: Thu Dec 19, 2013 10:12 am
Contact: Website Facebook Twitter

Re: Multiscreen=AWESOME- how to support via Python/PyGame?

Tue Sep 15, 2015 6:34 pm

gsh wrote:Question is how does pygame access the screen, if it uses /dev/fb0 to write pixels to the screen then it will not work right now...

Whereas if it uses direct access of a dispmanx framebuffer then it is possible to change it to output to the other screen by changing the parameter to dispmanx_display_open this is what I recently did to get Kivy to output to the other screen...
Not sure how to find that out. Checking out the bitbucket repo for pygame has me lost in c code in 2 seconds flat
gsh wrote:(Kivy now supports this upstream if anyone wants to have go, I've got X running on my HDMI and kivy on the LCD and it all seems to work well)
Maybe I need to look at using Kivy instead of pygame.

Thanks for the pointers in any case

User avatar
makuk66
Posts: 3
Joined: Thu Sep 17, 2015 9:00 am
Contact: Website

Re: Multiscreen=AWESOME- how to support via Python/PyGame?

Thu Sep 17, 2015 9:17 am

gsh wrote: Kivy now supports this upstream if anyone wants to have go, I've got X running on my HDMI and kivy on the LCD and it all seems to work well
Gordon: Could you share more details about this setup? I built the latest kivy from source, and tried the examples/demo/showcase demo, with the KIVY_BCM_DISPMANX_ID environment variable set (I tried 0 to 5), but nothing shows up on my touchscreen. I know the screen works, as I can run X on it. Do I need something special in config.txt? Do I need to modify the kivy code?

Francis asks the same here: https://www.raspberrypi.org/blog/the-ea ... nt-1243768
-- Martijn

gsh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1382
Joined: Sat Sep 10, 2011 11:43 am

Re: Multiscreen=AWESOME- how to support via Python/PyGame?

Thu Sep 17, 2015 11:01 am

Sorry I've not been able to try it yet (haven't had the time!) but I believe you need to build and install the latest version from github, is that what you used?

Gordon
--
Gordon Hollingworth PhD
Raspberry Pi - Director of Software Engineering

User avatar
makuk66
Posts: 3
Joined: Thu Sep 17, 2015 9:00 am
Contact: Website

Re: Multiscreen=AWESOME- how to support via Python/PyGame?

Fri Sep 18, 2015 10:51 am

Yes, this was with commit 0ca33cfb2d74cb5f5047ff6d49315023880ed1a5, which includes the relevant commit 0647cd0129bbcf281c7ac6d2eafe367e00ab0187. I added some logging to verify the display number is obtained from the environment variable and used.

Running with 'KIVY_BCM_DISPMANX_ID=6 python kivy/examples/demo/pictures/main.py -d', the last thing I see is "Actual display size: 800x480", which indicates the touchscreen, but nothing displays. Strangely enough, after a reboot, if I do the same again it, it still says it's using 800x480, but actually displays on the main screen.
Logs and config are here: https://gist.github.com/makuk66/8cde17fcc1c1810531eb

Running 'omxplayer --display=6 test.mkv' displays on the touchscreen, so the screen and its connections are OK.
Running the kivy demo on the main HDMI display works, so my kivy installation is seemingly OK.
I tried increasing the GPU memory to 192M to exclude memory issues.
I tried powering the display board and pi both from their own mini-usb connectors rather than using the pins to exclude power level issues.
-- Martijn

jehutting
Posts: 138
Joined: Sun Feb 15, 2015 8:37 am
Location: The Netherlands

Re: Multiscreen=AWESOME- how to support via Python/PyGame?

Sat Sep 19, 2015 8:45 am

Made the following modification to the (latest and greatest pulled) KIVY git code

Code: Select all

$ git diff
diff --git a/kivy/lib/vidcore_lite/egl.pyx b/kivy/lib/vidcore_lite/egl.pyx
index ee8491f..41218c1 100644
--- a/kivy/lib/vidcore_lite/egl.pyx
+++ b/kivy/lib/vidcore_lite/egl.pyx
@@ -603,7 +603,7 @@ def bcm_display_open(bcm.uint32_t device):
     cdef:
         bcm.DISPMANX_DISPLAY_HANDLE_T disp
         bcm.DisplayHandle D
-    disp = bcm.vc_dispmanx_display_open( 0 )
+    disp = bcm.vc_dispmanx_display_open( device )
     if disp == 0:
         raise bcm.BCMDisplayException("Couldn't open handle to display")
     D = bcm.DisplayHandle()
Now executing

Code: Select all

KIVY_BCM_DISPMANX_ID=4 LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH python examples/demo/pictures/main.py -d
gives me the AWESOME demo on the dsi display WITH touch!

Of course with

Code: Select all

KIVY_BCM_DISPMANX_ID=5 
it runs on the HDMI screen, but WITHOUT touch :lol: :lol: :lol:

gsh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1382
Joined: Sat Sep 10, 2011 11:43 am

Re: Multiscreen=AWESOME- how to support via Python/PyGame?

Sat Sep 19, 2015 8:49 am

Can you push it back, it looks like the change for the touchscreen was missed out

Gordon
--
Gordon Hollingworth PhD
Raspberry Pi - Director of Software Engineering

jehutting
Posts: 138
Joined: Sun Feb 15, 2015 8:37 am
Location: The Netherlands

Re: Multiscreen=AWESOME- how to support via Python/PyGame?

Sat Sep 19, 2015 11:21 am

My pull request is merged into the Kivy (master repository) git. So, now it is just a git pull away :D

User avatar
makuk66
Posts: 3
Joined: Thu Sep 17, 2015 9:00 am
Contact: Website

Re: Multiscreen=AWESOME- how to support via Python/PyGame?

Tue Sep 22, 2015 7:22 pm

Works for me -- Thanks jehutting!
-- Martijn

peterst
Posts: 16
Joined: Sun Apr 28, 2013 6:59 pm

Re: Multiscreen=AWESOME- how to support via Python/PyGame?

Sat Sep 26, 2015 7:16 pm

jehutting wrote:
Now executing

Code: Select all

KIVY_BCM_DISPMANX_ID=4 LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH python examples/demo/pictures/main.py -d
gives me the AWESOME demo on the dsi display WITH touch!

Of course with

Code: Select all

KIVY_BCM_DISPMANX_ID=5 
it runs on the HDMI screen, but WITHOUT touch :lol: :lol: :lol:

I have it running on HDMI but when I try to run it on the touchscreen I end up with

from an X termins:
warning: video: failed (multisamples=2)
warning trying without antialiasing
Fatal Python error: (pygame parachute) Segmentation fault
from console:
[INFO ] [Window ] Provider: egl_rpi
[INFO ] [Window ] Provider: pygame(['window_egl_rpi'] ignored)
[ERROR ] [Window ] Unable to use pygame
[ERROR ] [Window ] The module raised an important error: 'Unable to open a console terminal'
Exception kivy.core.CoreCriticalException: CoreCriticalException('Unable to open a console terminal',) in 'kivy.properties.dpi2px' ignored
[INFO ] [Window ] Provider: egl_rpi
[INFO ] [Window ] Provider: pygame(['window_egl_rpi'] ignored)
[DEBUG ] [Window ] Ignored <x11> (import error)
[CRITICAL] [Window ] Unable to find any valuable Window provider at all!
egl_rpi - AttributeError: 'NoneType' object has no attribute '_WindowBase__instance'
File "/usr/local/lib/python2.7/dist-packages/kivy/core/__init__.py", line 67, in core_select_lib
cls = cls()
File "/usr/local/lib/python2.7/dist-packages/kivy/core/window/__init__.py", line 613, in __init__
if WindowBase.__instance is not None and not force:

pygame - AttributeError: 'NoneType' object has no attribute '_WindowBase__instance'
File "/usr/local/lib/python2.7/dist-packages/kivy/core/__init__.py", line 67, in core_select_lib
cls = cls()
File "/usr/local/lib/python2.7/dist-packages/kivy/core/window/__init__.py", line 613, in __init__
if WindowBase.__instance is not None and not force:

x11 - ImportError: No module named window_x11
File "/usr/local/lib/python2.7/dist-packages/kivy/core/__init__.py", line 59, in core_select_lib
fromlist=[modulename], level=0)

[CRITICAL] [App ] Unable to get a Window, abort.
running the latest kivy (just did a checkout some minutes ago) and the touchscreen is running fine (x, touch).
Any hints on how to display one program on each screen?

jehutting
Posts: 138
Joined: Sun Feb 15, 2015 8:37 am
Location: The Netherlands

Re: Multiscreen=AWESOME- how to support via Python/PyGame?

Sun Sep 27, 2015 11:02 am

Could you try out the following to see if the DISPLAY setting fixes the open console terminal error and also getting more logging?

Code: Select all

DISPLAY=:0.0 python main.py -c kivy:log_level:trace
When running the demo I get

Code: Select all

...
[INFO   ] [Window      ] Provider: egl_rpi
[INFO   ] [GL          ] OpenGL version <OpenGL ES 2.0>
[INFO   ] [GL          ] OpenGL vendor <Broadcom>
[INFO   ] [GL          ] OpenGL renderer <VideoCore IV HW>
[INFO   ] [GL          ] OpenGL parsed version: 2, 0
[INFO   ] [GL          ] Shading version <OpenGL ES GLSL ES 1.00>
[INFO   ] [GL          ] Texture max size <2048>
[INFO   ] [GL          ] Texture max units <8>
[INFO   ] [Shader      ] fragment shader: <Compiled>
...
No pygame provider logging at all.
I'm running on Raspbian (updated and upgraded).

peterst
Posts: 16
Joined: Sun Apr 28, 2013 6:59 pm

Re: Multiscreen=AWESOME- how to support via Python/PyGame?

Sun Sep 27, 2015 1:14 pm

it will always run on HDMI (starting over ssh console, starting from a local console, starting from an x termina):
[INFO ] [Image ] Providers: img_tex, img_dds, img_gif, img_pygame, img_pil (img_ffpyplayer ignored)
[DEBUG ] [Cache ] register <kv.texture> with limit=1000, timeout=60
[DEBUG ] [Cache ] register <kv.shader> with limit=1000, timeout=3600
[INFO ] [Text ] Provider: pygame
[DEBUG ] [App ] Loading kv <./test.kv>
[DEBUG ] [App ] kv <./test.kv> not found
[INFO ] [Window ] Provider: egl_rpi
[DEBUG ] [Window ] Actual display size: 1920x1080
[INFO ] [GL ] OpenGL version <OpenGL ES 2.0>
[INFO ] [GL ] OpenGL vendor <Broadcom>
[INFO ] [GL ] OpenGL renderer <VideoCore IV HW>
[INFO ] [GL ] OpenGL parsed version: 2, 0
[INFO ] [GL ] Shading version <OpenGL ES GLSL ES 1.00>
[INFO ] [GL ] Texture max size <2048>
[INFO ] [GL ] Texture max units <8>
[INFO ] [Shader ] fragment shader: <Compiled>
[DEBUG ] [Shader ] Fragment compiled successfully
[INFO ] [Shader ] vertex shader: <Compiled>
[DEBUG ] [Shader ] Vertex compiled successfully
which was running before. I can't run it on the touchscreen (Waveshare Spotpear 3.5")

also a rasbian

jehutting
Posts: 138
Joined: Sun Feb 15, 2015 8:37 am
Location: The Netherlands

Re: Multiscreen=AWESOME- how to support via Python/PyGame?

Sun Sep 27, 2015 1:59 pm

Waveshare Spotpear 3.5"... ehhhh, ahem, well, OK, :D ...

Isn't that touchscreen working through a SPI interface interacting with a framebuffer device /dev/fbX and not using the DSI interface at all?

peterst
Posts: 16
Joined: Sun Apr 28, 2013 6:59 pm

Re: Multiscreen=AWESOME- how to support via Python/PyGame?

Sun Sep 27, 2015 2:10 pm

oh, well...thats..right :) That means that it won't work at all, right?

jehutting
Posts: 138
Joined: Sun Feb 15, 2015 8:37 am
Location: The Netherlands

Re: Multiscreen=AWESOME- how to support via Python/PyGame?

Sun Sep 27, 2015 5:57 pm

As far as I know, that's right...it doesn't work.

Although...look here: Kivy seems to work with an Adafruit PiTFT.

peterst
Posts: 16
Joined: Sun Apr 28, 2013 6:59 pm

Re: Multiscreen=AWESOME- how to support via Python/PyGame?

Sun Sep 27, 2015 6:48 pm

the touchevents are used but its not displaying the kivy output on the lcd. So I have X or a console on the LCD and the kivy project on the HDMI; when I touch the LCD touchscreen the touch-events are read (so I'm clicking on the X start button,...) and transfered into the kivy app. I think that bug just talks about the touch events and not how to display it on the lcd

just found a bug: https://github.com/kivy/kivy/issues/3633
see the last comment :( damn cheap touchscreen!

jehutting
Posts: 138
Joined: Sun Feb 15, 2015 8:37 am
Location: The Netherlands

Re: Multiscreen=AWESOME- how to support via Python/PyGame?

Mon Sep 28, 2015 9:10 pm

In "my link" the OP states he uses fbcp to get the dispmanx framebuffer into the framebuffer of the PiTFT. It is a long time ago that I tried it myself with OMXPlayer and it played reasonably well.

Return to “Official Foundation Display”