techmaniac
Posts: 3
Joined: Fri Oct 09, 2015 2:14 pm

Pygame Init fails / fbcon issue?

Fri Oct 09, 2015 2:25 pm

Hello all,
will i got the brand new official Display as well as a rpi with a clean jessy sd. I am trying to implement a script using pigame under python which formerly worked fine but now I fond myself back at the very roots as I can't get pygame to init

So here's the code:

Code: Select all

class pyscope :
    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:
            print "I'm running under X display = {0}".format(disp_no)      # -->If I print it anyway it gives me "None"
        
        #Display waehlen
        os.environ["SDL_FBDEV"] = "/dev/fb1"        #= "/dev/fb1" SPI / fb0=HDMI
        #Touch
        os.environ['SDL_VIDEODRIVER'] = 'fbcon'     #fbcon
        os.environ["SDL_FBDEV"] = "/dev/fb1"        #"/dev/fb1"
        os.environ["SDL_MOUSEDEV"] = "/dev/input/touchscreen"  #touchscreen
        os.environ["SDL_MOUSEDRV"] = "TSLIB"
        
        # Check which frame buffer drivers are available
        # Start with fbcon since directfb hangs with composite output
        drivers = ['fbcon', 'directfb', 'svgalib','x11']
        found = False
        for driver in drivers:
            print driver
            # 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!')
        
        size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
        print "Framebuffer size: %d x %d" % (size[0], size[1])
        self.screen = pygame.display.set_mode(size, pygame.FULLSCREEN)
        # Clear the screen to start
        self.screen.fill((0, 0, 0))        
        
        # Initialise font support
        pygame.font.init()

        # Render the screen
        pygame.display.update()
And that's what I get in the console when running it from my Laptop

Code: Select all

fbcon
Driver: fbcon failed.
directfb
Driver: directfb failed.
svgalib
Driver: svgalib failed.
I was also running it before from the console and everything was finely displayed on the PRI Display (those days an adafruti 2,8" wich was a Little bit more difficult to configure)

fbi is installed, well all up to date.... no more clue.... ehm.... anybody some good hints or simply a more clever way to init pygame with the official Display over DSI? (Tested code highly appreciated)

Thank you all!

techmaniac
Posts: 3
Joined: Fri Oct 09, 2015 2:14 pm

Re: Pygame Init fails / fbcon issue?

Tue Oct 13, 2015 11:25 am

An addition: Maybe someone saw it in the code: If I try to get the os.environment("DISPLAY") value is says "None" although the screen and touch are running fine...
Any inits which have to be modified and may that be the reason why pygame init fails?

texy
Forum Moderator
Forum Moderator
Posts: 5156
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Pygame Init fails / fbcon issue?

Tue Oct 13, 2015 1:43 pm

Hi,
I'll need to check later when the hardware is in front of me, but I think I found that the system default environmental's were already correct. Try removing them all and see if it just runs..............

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

techmaniac
Posts: 3
Joined: Fri Oct 09, 2015 2:14 pm

Re: Pygame Init fails / fbcon issue?

Wed Oct 14, 2015 8:31 pm

Thank you for your Infos.
To be honest, I would not see a plce wehere I should look for that.
The Desktop boots fine in the Display so the env variables should not be that wrong. Anyway I have searched around and tried various things - no Chance at the Moment.

I also wanted to try pygame Zero but I'm still trying to find out whether I can also include it in normal python code eiminiating the pgzrun and using python instead with a Import pgzero(not working) or checking if all libraries and functions are available if I start it with pgzrun. A little bit strange somehow - or any other clue what could be used to create some Buttons and Display Images with ease?

Return to “Official Foundation Display”