doghousedean
Posts: 3
Joined: Wed Aug 08, 2012 10:46 am

Running a pi 2b headless with pygame in a vehicle

Fri Apr 12, 2019 8:53 am

Morning folks,

Been a long time since I posted here, 2012 in fact!

I've been struggling to get my project to move forward, I've installed a Pi 2b a small 300w amp and an Arduino inside the case for a double din car radio (For my camper van) with the hopes and dreams of it being a touchscreen sensor display as well as pass through bluetooth audio (This part works flawlessly, https://github.com/BaReinhard/Super-Sim ... er-Install for details)

So I have the hardware all connected up, audio working fine, arduino on I2C with the pi, wifi in my van means I can access it remotely, even customised the cloud4rpi.io scripts to show my public IP so I can ssh to it on a non standard port from anywhere. All fine.

The last part im struggling with is the GUI, im running the latest headless Jessie with a 7" 1024x600 screen from aliexpress (not great but for £25 its a steal).

My idea was to launch pygame on boot (systemd service?) but can't seem to get an image out of it successfully. I've googled and googled this but all solutions I try don't seem to work. My last attempt was to use code from here https://facelesstech.wordpress.com/2017 ... pi-camera/ which looked promising as I was able to use fim, the frame buffer tool, to show a splash screen (altho not successfully on boot, got the console text over the top as it scrolled through)

The rest of the plans to connect up the sensors and relays etc is simple enough, just this one thing has defeated me, now my new wife thinks i'm not the nerd I promised I was, please help me save my marriage ;)

Will going to a lightweight desktop environment be the simplest solution, will this be worth the extra load?

This is my current code:

Code: Select all

#!/usr/bin/env python3
import pygame
import sys
import time
from time import strftime
import os
import json

time_stamp_prev=0
os.environ['SDL_AUDIODRIVER'] = 'dsp'
os.environ["SDL_VIDEODRIVER"] = "fbcon"
os.environ["SDL_FBDEV"] = "/dev/fb0"

print(os.environ["SDL_FBDEV"])
pygame.init()

size = width, height = 1024, 600
#pygame.mouse.set_visible(0)
screen = pygame.display.set_mode(size)
while True:
        displayTime()
        pygame.display.flip()
        time.sleep(10)
        graph = pygame.image.load("/opt/splash.png")
        graphrect = graph.get_rect()
        screen.blit(graph, graphrect)
        pygame.display.flip()
        time.sleep(10)
/edit

Forgot to include the error!

Code: Select all

[email protected]:~ $ ./test3.py
pygame 1.9.5
Hello from the pygame community. https://www.pygame.org/contribute.html
/dev/fb0
Traceback (most recent call last):
  File "./test3.py", line 19, in <module>
    screen = pygame.display.set_mode(size)
pygame.error: Unable to open a console terminal

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

Re: Running a pi 2b headless with pygame in a vehicle

Fri Apr 12, 2019 8:57 am

doghousedean wrote:
Fri Apr 12, 2019 8:53 am
Morning folks,

Been a long time since I posted here, 2012 in fact!

I've been struggling to get my project to move forward, I've installed a Pi 2b a small 300w amp and an Arduino inside the case for a double din car radio (For my camper van) with the hopes and dreams of it being a touchscreen sensor display as well as pass through bluetooth audio (This part works flawlessly, https://github.com/BaReinhard/Super-Sim ... er-Install for details)

So I have the hardware all connected up, audio working fine, arduino on I2C with the pi, wifi in my van means I can access it remotely, even customised the cloud4rpi.io scripts to show my public IP so I can ssh to it on a non standard port from anywhere. All fine.

The last part im struggling with is the GUI, im running the latest headless Jessie with a 7" 1024x600 screen from aliexpress (not great but for £25 its a steal).

My idea was to launch pygame on boot (systemd service?) but can't seem to get an image out of it successfully. I've googled and googled this but all solutions I try don't seem to work. My last attempt was to use code from here https://facelesstech.wordpress.com/2017 ... pi-camera/ which looked promising as I was able to use fim, the frame buffer tool, to show a splash screen (altho not successfully on boot, got the console text over the top as it scrolled through)

The rest of the plans to connect up the sensors and relays etc is simple enough, just this one thing has defeated me, now my new wife thinks i'm not the nerd I promised I was, please help me save my marriage ;)

Will going to a lightweight desktop environment be the simplest solution, will this be worth the extra load?

This is my current code:

Code: Select all

#!/usr/bin/env python3
import pygame
import sys
import time
from time import strftime
import os
import json

time_stamp_prev=0
os.environ['SDL_AUDIODRIVER'] = 'dsp'
os.environ["SDL_VIDEODRIVER"] = "fbcon"
os.environ["SDL_FBDEV"] = "/dev/fb0"

print(os.environ["SDL_FBDEV"])
pygame.init()

size = width, height = 1024, 600
#pygame.mouse.set_visible(0)
screen = pygame.display.set_mode(size)
while True:
        displayTime()
        pygame.display.flip()
        time.sleep(10)
        graph = pygame.image.load("/opt/splash.png")
        graphrect = graph.get_rect()
        screen.blit(graph, graphrect)
        pygame.display.flip()
        time.sleep(10)

Raspbian Jessie's does not use SystemD and actually went end of life August 2017.

Raspbian Stretch has been with us for nearly 2 years and soon to be replaced by Raspbian Buster.
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.

doghousedean
Posts: 3
Joined: Wed Aug 08, 2012 10:46 am

Re: Running a pi 2b headless with pygame in a vehicle

Fri Apr 12, 2019 9:50 am

fruitoftheloom wrote:
Fri Apr 12, 2019 8:57 am
Raspbian Jessie's does not use SystemD and actually went end of life August 2017.

Raspbian Stretch has been with us for nearly 2 years and soon to be replaced by Raspbian Buster.
Of course your are correct, it is on Stretch not Jessie, I should have more than 1 cup of tea before posting!

tqhien
Posts: 19
Joined: Thu Feb 02, 2012 10:07 am

Re: Running a pi 2b headless with pygame in a vehicle

Fri May 10, 2019 3:18 pm

Hello.

For a project of mine, I uses pygame with a simple tft screen for use with the framebuffer. I used a tutoril from Adafruit to test the framebuffer driver : https://learn.adafruit.com/pi-video-out ... ramebuffer

You need to call the script with sudo as root user is needed to access the framebuffer.

Once you know which driver is used, you can hardcode it in your program.

And last comment : you cannot use it through remote access. You can launch your program through ssh but result will be on the screen attached to the Pi.

Hien.

Return to “Advanced users”