simonfish
Posts: 18
Joined: Wed Jul 01, 2020 8:24 am

python code help.

Sun Jul 05, 2020 10:58 am

I thought i would ask a new question as my problem has now changed. I`m using this github link for my first project and this is going to be my only rpi project as i wanted just a working movie prop. I need help because i have no idea how to get things wotking on thr RPI. I would like to get it working from the console @ pi@raspberrypi:~ $ and not from the descktop once its loaded. i`m using a raspberry pi 3 my os is buster but i`m using a screen that plugs into the 3.5mm headphone jack. And i think part of my problem is becasuse the project used a diffrent tft. not one pluged into the 3.5 jack like im using. If i try running the the main.py @ pi@raspberrypi:~ $ i get some error messages listed below, is this because the driver is not loaded ?

Code: Select all

pi@raspberrypi:~ $ cd /home/pi/tracker
pi@raspberrypi:~/tracker $ python main.py
pygame 1.9.4.post1
Hello from the pygame community. https://www.pygame.org/contribute.html
Driver: fbcon failed.
Driver: directfb failed.
Driver: svgalib failed.
Traceback (most recent call last):
  File "main.py", line 59, in <module>
    scope=pyscope()
  File "/home/pi/tracker/pyscope.py", line 33, in __init__
    raise Exception('No suitable video driver found!')
Exception: No suitable video driver found!
pi@raspberrypi:~/tracker $ fbconfbcon
Please try and understand that i may be asking the wrong question and is the pi@raspberrypi:~ $ the console ? im still trying to lurn as i go

hippy
Posts: 8084
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: python code help.

Sun Jul 05, 2020 2:24 pm

The code used in the pyscope.py module to determine which frame buffer is available ...

Code: Select all

        # 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!'
Is very similar to what I am using in my own code ....

Code: Select all

def FindDisplayDriver():
  for driver in ["fbcon", "directfb", "svgalib"]:
    if not os.getenv("SDL_VIDEODRIVER"):
      os.putenv("SDL_VIDEODRIVER", driver)
    try:
      pygame.display.init()
      return True
    except pygame.error:
      pass
  return False
  
if not FindDisplayDriver():
  print("Failed to initialise display driver")
I have just re-tested and that works for me on a Pi 3B and earlier, both as boot to command line and boot to desktop. I can't test for composite at present but recall it did work in the past.

I am not sure how to tell what 'frame buffers' may be available, but 'fbset -i', 'ls /dev/fb*' and 'tvservice -l' might be a start for determining what you have.

My code evolved from other sources, quite possibly the above, and I have never been confident about -

Code: Select all

    if not os.getenv("SDL_VIDEODRIVER"):
      os.putenv("SDL_VIDEODRIVER", driver)
As that would seem to set it always to "fbcon" if not previously set. I don't know if that's right but as I have never encountered any issues I've not had to worry about it.

simonfish
Posts: 18
Joined: Wed Jul 01, 2020 8:24 am

Re: python code help.

Sun Jul 05, 2020 3:20 pm

hippy wrote:
Sun Jul 05, 2020 2:24 pm
The code used in the pyscope.py module to determine which frame buffer is available ...

Code: Select all

        # 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!'
Is very similar to what I am using in my own code ....

Code: Select all

def FindDisplayDriver():
  for driver in ["fbcon", "directfb", "svgalib"]:
    if not os.getenv("SDL_VIDEODRIVER"):
      os.putenv("SDL_VIDEODRIVER", driver)
    try:
      pygame.display.init()
      return True
    except pygame.error:
      pass
  return False
  
if not FindDisplayDriver():
  print("Failed to initialise display driver")
I have just re-tested and that works for me on a Pi 3B and earlier, both as boot to command line and boot to desktop. I can't test for composite at present but recall it did work in the past.

I am not sure how to tell what 'frame buffers' may be available, but 'fbset -i', 'ls /dev/fb*' and 'tvservice -l' might be a start for determining what you have.

My code evolved from other sources, quite possibly the above, and I have never been confident about -

Code: Select all

    if not os.getenv("SDL_VIDEODRIVER"):
      os.putenv("SDL_VIDEODRIVER", driver)
As that would seem to set it always to "fbcon" if not previously set. I don't know if that's right but as I have never encountered any issues I've not had to worry about it.
Thanks for the reply. Are you saying to changesome code ? if so what should i change could you mabe explain to a newbie.

hippy
Posts: 8084
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: python code help.

Sun Jul 05, 2020 5:36 pm

simonfish wrote:
Sun Jul 05, 2020 3:20 pm
Thanks for the reply. Are you saying to changesome code ? if so what should i change could you mabe explain to a newbie.
Sorry; I was saying the code seems to be fine, and that seems to work for most people including myself.

It therefore seems it is something with your set-up which seems problematic, but I am not convinced it's because you are using composite video via the 3.5mm jack.

I'm not sure what the issue would be, or the fix, but those 'fbset -i', 'ls /dev/fb*' and 'tvservice -l' commands may give a clue.

simonfish
Posts: 18
Joined: Wed Jul 01, 2020 8:24 am

Re: python code help.

Sun Jul 05, 2020 9:01 pm

hippy wrote:
Sun Jul 05, 2020 5:36 pm
simonfish wrote:
Sun Jul 05, 2020 3:20 pm
Thanks for the reply. Are you saying to changesome code ? if so what should i change could you mabe explain to a newbie.
Sorry; I was saying the code seems to be fine, and that seems to work for most people including myself.

It therefore seems it is something with your set-up which seems problematic, but I am not convinced it's because you are using composite video via the 3.5mm jack.

I'm not sure what the issue would be, or the fix, but those 'fbset -i', 'ls /dev/fb*' and 'tvservice -l' commands may give a clue.
Even if I have the RPI wired to my tv using HDMI get the same error message.

hippy
Posts: 8084
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: python code help.

Sun Jul 05, 2020 10:54 pm

simonfish wrote:
Sun Jul 05, 2020 9:01 pm
Even if I have the RPI wired to my tv using HDMI get the same error message.
Maybe try those'fbset -i', 'ls /dev/fb*' and 'tvservice -l' commands to see if they give some clue.

simonfish
Posts: 18
Joined: Wed Jul 01, 2020 8:24 am

Re: python code help.

Mon Jul 06, 2020 6:29 am

hippy wrote:
Sun Jul 05, 2020 10:54 pm
simonfish wrote:
Sun Jul 05, 2020 9:01 pm
Even if I have the RPI wired to my tv using HDMI get the same error message.
Maybe try those'fbset -i', 'ls /dev/fb*' and 'tvservice -l' commands to see if they give some clue.
But how do I change them ?
If loaded after desktop it works. But will not work if typed into the command prompt.

hippy
Posts: 8084
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: python code help.

Mon Jul 06, 2020 9:42 am

simonfish wrote:
Mon Jul 06, 2020 6:29 am
hippy wrote:
Sun Jul 05, 2020 10:54 pm
simonfish wrote:
Sun Jul 05, 2020 9:01 pm
Even if I have the RPI wired to my tv using HDMI get the same error message.
Maybe try those'fbset -i', 'ls /dev/fb*' and 'tvservice -l' commands to see if they give some clue.
But how do I change them ?
If loaded after desktop it works. But will not work if typed into the command prompt.
You don't need to change anything. Just type the commands suggested at the command line and let us know what is reported. That may give a clue as to what is wrong and why.

simonfish
Posts: 18
Joined: Wed Jul 01, 2020 8:24 am

Re: python code help.

Mon Jul 06, 2020 9:46 am

hippy wrote:
Mon Jul 06, 2020 9:42 am
simonfish wrote:
Mon Jul 06, 2020 6:29 am
hippy wrote:
Sun Jul 05, 2020 10:54 pm

Maybe try those'fbset -i', 'ls /dev/fb*' and 'tvservice -l' commands to see if they give some clue.
But how do I change them ?
If loaded after desktop it works. But will not work if typed into the command prompt.
You don't need to change anything. Just type the commands suggested at the command line and let us know what is reported. That may give a clue as to what is wrong and why.
Sorry to be a bit stuppid but type what into the command line ?

hippy
Posts: 8084
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: python code help.

Mon Jul 06, 2020 10:11 am

Code: Select all

fbset -i

Code: Select all

ls /dev/fb*

Code: Select all

tvservice -l

simonfish
Posts: 18
Joined: Wed Jul 01, 2020 8:24 am

Re: python code help.

Mon Jul 06, 2020 11:13 am

hippy wrote:
Mon Jul 06, 2020 10:11 am

Code: Select all

fbset -i

Code: Select all

ls /dev/fb*

Code: Select all

tvservice -l
capied and paisted each line one by one.

Code: Select all

pi@raspberrypi:~ $ fbset -i

mode "1360x768"
    geometry 1360 768 1360 768 32
    timings 0 0 0 0 0 0 0
    rgba 8/16,8/8,8/0,8/24
endmode

Frame buffer device information:
    Name        : BCM2708 FB
    Address     : 0x1e7fe000
    Size        : 4177920
    Type        : PACKED PIXELS
    Visual      : TRUECOLOR
    XPanStep    : 1
    YPanStep    : 1
    YWrapStep   : 0
    LineLength  : 5440
    Accelerator : No
pi@raspberrypi:~ $ ls /dev/fb*
/dev/fb0
pi@raspberrypi:~ $ tvservice -l
1 attached device(s), display ID's are :
Display Number 2, type HDMI 0
pi@raspberrypi:~ $ python2 /home/pi/tracker/main.py
pygame 1.9.4.post1
Hello from the pygame community. https://www.pygame.org/contribute.html
Driver: fbcon failed.
Driver: directfb failed.
Driver: svgalib failed.
Traceback (most recent call last):
  File "/home/pi/tracker/main.py", line 59, in <module>
    scope=pyscope()
  File "/home/pi/tracker/pyscope.py", line 33, in __init__
    raise Exception('No suitable video driver found!')
Exception: No suitable video driver found!
pi@raspberrypi:~ $

hippy
Posts: 8084
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: python code help.

Mon Jul 06, 2020 11:48 am

That all looks fine to me but I'm no expert on frame buffers and video drivers. I can't see any reason pyscope.py / PyGame wouldn't be able to choose a video driver to use.

The only time I've ever had PyGame not choose a driver is when I have tried to run a program over SSH/Telnet and have forgotten to tell it to use the main display. Other than that it has always been able to choose a driver and worked.

If you are launching your program over SSH/Telnet you could try -

Code: Select all

DISPLAY=:0 python2 /home/pi/tracker/main.py
Other than that it looks like you may have to wait for someone who knows more than me to come along and offer assistance.

simonfish
Posts: 18
Joined: Wed Jul 01, 2020 8:24 am

Re: python code help.

Mon Jul 06, 2020 12:48 pm

hippy wrote:
Mon Jul 06, 2020 11:48 am
That all looks fine to me but I'm no expert on frame buffers and video drivers. I can't see any reason pyscope.py / PyGame wouldn't be able to choose a video driver to use.

The only time I've ever had PyGame not choose a driver is when I have tried to run a program over SSH/Telnet and have forgotten to tell it to use the main display. Other than that it has always been able to choose a driver and worked.

If you are launching your program over SSH/Telnet you could try -

Code: Select all

DISPLAY=:0 python2 /home/pi/tracker/main.py
Other than that it looks like you may have to wait for someone who knows more than me to come along and offer assistance.
Tried over ssh same errors. But it will work if i run in after loading the desktop. And run ssh command but it looks like its missing fbcp.

pi@raspberrypi:~ $ DISPLAY=:0 python2 /home/pi/tracker/main.py
pygame 1.9.4.post1
Hello from the pygame community. https://www.pygame.org/contribute.html
sh: 1: fbcp: not found

simonfish
Posts: 18
Joined: Wed Jul 01, 2020 8:24 am

Re: python code help.

Mon Jul 06, 2020 1:00 pm

Dose this link mean anything to you.

Code: Select all

https://github.com/waveshare/LCD-show/issues/8

hippy
Posts: 8084
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: python code help.

Mon Jul 06, 2020 3:26 pm

simonfish wrote:
Mon Jul 06, 2020 1:00 pm
Dose this link mean anything to you.

Code: Select all

https://github.com/waveshare/LCD-show/issues/8
Yes, I believe I understand it.

I believe 'fbcp' means 'frame buffer copy' which makes sense if one is rendering to some frame buffer then continually copying that out to a Waveshare LCD which uses its own frame buffer. I would presume 'fbcp' would not be needed if one isn't doing that.

I downloaded the project to my Pi 3B and ran it (via Telnet) and that worked for me ...

Code: Select all

pi@Pi3B:~ $ git clone https://github.com/martinr1000/AliensMotionTracker.git
Cloning into 'AliensMotionTracker'...
remote: Enumerating objects: 158, done.
remote: Total 158 (delta 0), reused 0 (delta 0), pack-reused 158
Receiving objects: 100% (158/158), 37.91 MiB | 5.55 MiB/s, done.
Resolving deltas: 100% (17/17), done.

Code: Select all

pi@Pi3B:~ $ cd AliensMotionTracker
pi@Pi3B:~/AliensMotionTracker $ DISPLAY=:0 python2 main.py
pygame 1.9.4.post1
Hello from the pygame community. https://www.pygame.org/contribute.html
sh: 1: fbcp: not found
And on my HDMI TV I can see an Alien's style scanner in the top left which looks like it's the perfect size to copy to a smaller Waveshare LCD display.

So, I'm guessing the project renders to the default display buffer, then continually copies part of that to the Waveshare LCD, needing and using 'fbcp' to do that. But, if there isn't a Waveshare LCD, it doesn't need to do that, and it doesn't matter if 'fbcp' cannot be found.

So, without a Waveshare LCD one can ignore that "sh: 1: fbcp: not found" error. It's merely informative when not using a Waveshare LCD. Installing it won't solve the problem here.

The original issue was that there was no frame buffer at all for PyGame to render to; the frame buffer 'fbcp' would have been copying from does not exist.

Has that issue been solved for you ?
What do you see on your monitor / TV / display ?


Update : See next post

hippy
Posts: 8084
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: python code help.

Mon Jul 06, 2020 3:56 pm

Okay; getting somewhere now.

It works with a GUI from a desktop command prompt, works via Telnet with DISPLAY=:0.

Booted to the CLI it doesn't work from command prompt. But my own PyGame using code does.

So, if it's not an issue with PyGame, it must be something else, whatever this project is doing.

If I comment out the two lines below in main.py it runs, eventually gives the 'click-click-click' sound of the scanner, but shows a blank screen ( Ctrl-X to exit ) -

Code: Select all

os.environ["SDL_FBDEV"] = "/dev/fb1"
os.environ['SDL_VIDEO_CENTERED'] = '1'
And you might as well comment out the line which launches the non-existent 'fbcp' -

Code: Select all

os.system("fbcp &")
So it's running from the command line just not rendering anything to the screen. It won't run over Telnet.

I tried os.environ["SDL_FBDEV"] = "/dev/fb0" but that's not the fix. Not sure what would be.

simonfish
Posts: 18
Joined: Wed Jul 01, 2020 8:24 am

Re: python code help.

Mon Jul 06, 2020 4:09 pm

After i set my rpi via

Code: Select all

 $ sudo raspi-config. $ boot options $ B1 $ B2: Console autologin.
Then reboot.
Then from my pc SSH to rpi.

Code: Select all

pi@raspberrypi:~ $ DISPLAY=:0 python2 /home/pi/tracker/main.py
pygame 1.9.4.post1
Hello from the pygame community. https://www.pygame.org/contribute.html
xcb_connection_has_error() returned true
Driver: fbcon failed.
Driver: directfb failed.
Driver: svgalib failed.
Traceback (most recent call last):
  File "/home/pi/tracker/main.py", line 59, in <module>
    scope=pyscope()
  File "/home/pi/tracker/pyscope.py", line 33, in __init__
    raise Exception('No suitable video driver found!')
Exception: No suitable video driver found!
pi@raspberrypi:~ $
I see nothing on my tv screen via the hdmi.

simonfish
Posts: 18
Joined: Wed Jul 01, 2020 8:24 am

Re: python code help.

Mon Jul 06, 2020 4:14 pm

Is there a way you could edit the code for me # out the code thats says use the tft display.
Maybe i could try a fresh install of Buster, and see if i then get it on screen

hippy
Posts: 8084
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: python code help.

Mon Jul 06, 2020 5:32 pm

simonfish wrote:
Mon Jul 06, 2020 4:09 pm
Then from my pc SSH to rpi ...
I can't get it to work over Telnet so it doesn't surprise me it doesn't work over SSH either. I get exactly the same as you, the same "xcb_connection_has_error() returned true" report over Telnet, even with DISPLAY=:0, and none of the drivers are found. And same with my own PyGame code over Telnet.

I don't know why that is, if or how that can be fixed, so the best solution is to run it from an attached keyboard / monitor rather than over SSH.

Because we don't know what in the code needs altering to make things work, neither of us having the skills nor inclination to put the effort into figuring that out; the pragmatic course would be to run the code under the desktop where it at least does work without change, go from there.

simonfish
Posts: 18
Joined: Wed Jul 01, 2020 8:24 am

Re: python code help.

Mon Jul 06, 2020 6:22 pm

Thanks for all the help.

Return to “Python”