Run PyGame program without booting to Desktop Raspberry Pi - python

I am using the PiTFT display for the Raspberry Pi, and I want to run my PyGame (Python) program without booting to the Desktop.
The reason I want to do this is because it will mean less RAM usage, and that is pretty important on a Raspberry Pi.
This has been asked before, but none of the answers are up to date, or else never worked in the first place.

I'm not exactly clear what problem you're having, but this should be fairly straightforward.
I add this at the top of my pygame scripts when using the PiTFT screen (none of my Pis use the desktop environment):
import os
# Tell the RPi to use the TFT screen and that it's a touchscreen device
os.putenv('SDL_VIDEODRIVER', 'fbcon')
os.putenv('SDL_FBDEV' , '/dev/fb1')
os.putenv('SDL_MOUSEDRV' , 'TSLIB')
os.putenv('SDL_MOUSEDEV' , '/dev/input/touchscreen')
Then you just need to make sure your pi doesn't boot into the desktop environment. You can do that by running:
sudo raspi-config
and changing the relevant setting.

Related

My Application (based on python tkinter) is not running at Boot time (autostart) in Raspberry Pi Os?

I have made executable file of python tkinter application. It runs well when clicked.
But I want to run it at Boot time (AutoStart) in Raspberry Pi Os.
I have tried many methods but they didn't work.
One method which I tried will other applications:
sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
`#/home/pi/Downloads/exes/project2/work/dist/homeP` (#path_of_file/applicatin_name)
This didn't work with my Current application, Even no error is observed. Please help me ??
I have tried many methods but they didn't work.
One method which I tried will other applications:
sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
`#/home/pi/Downloads/exes/project2/work/dist/homeP` (#path_of_file/applicatin_name)
This didn't work with my Current application, Even no error is observed.

Raspberry Pi: Enable or disable touch screen from Python script

I am working with Raspberry Pi 4 B, 8 gb RAM and Raspbian OS. I am having 7" touch screen attached to PI.
In my project, I want to make touch screen sleep if there is no activity detected for 5 mins from the Python script (just to save some power). Is there any shell command I can use in the Python script?
There is the option in config.txt of "disable_touchscreen=1" which will stop the Pi polling the controller board for touch input. It also doesn't start the firmware side of the touchscreen input driver, which should stop the Linux side loading either. The display side will work exactly as before.
This file is normally accessible as /boot/config.txt from raspbian OS.
You can read config.txt and modify using following python code
import ConfigParser
config_parser = ConfigParser.ConfigParser()
config_parser.read('config.txt')

How to lock user out from using OS on Ubuntu MATE (Raspberry Pi 3)

I'm building a Tkinter GUI in Python 3.7 meant to run on a Raspberry Pi 3, and I want the user to be unable to close it or access the OS (Ubuntu MATE) below it.
I tried using this flag to make the window un-closeable:
root.overrideredirect(boolean=True)
but this creates all top-level widgets underneath the root window. I tried forcing them to be created above the root using a variety of different methods but with no luck.
I then tried to update idle tasks before setting the flag:
root.update_idletasks()
root.overrideredirect(boolean=True)
and this worked on my Intel desktop running Ubuntu, but when running it on a Raspberry Pi 3 running Ubuntu MATE, updating idle tasks before setting the flag just seems to have disabled it completely, meaning the user could still access the OS.
I was wondering how could I prevent the user from accessing the OS on the Raspberry Pi 3. Any help would be nice.

Run OpenCV script on start with imshow

I have an OpenCV/python script running at my Raspberry Pi which reads the camera and shows the stream on the RCA monitor connected to the Pi.
Now I want the script to be loaded on boot. I already tried a cronjob #reboot, the /etc/rc.locale, /etc/profile and ~/.bash_profile.
I see the red light of the camera turning on every time, but the image won't be shown. Is there any solution to run the script? (I have no external input devices connected)
Thank you!
I know its quite an old thread, but I thought you might be still interested in a solution that worked for me. Hopefully, that can help you as well:
Raspberry Pi - Autostart OpenCv-Script - Error with cv::imshow()
In short: You most likely have problems with the DISPLAY / XAUTHORITY environment variable.

How to display pygame output on cloud9-vnc?

So I'm playing with python3 on Cloud9, got interested in trying pygame and found a recommendation to install cloud9-vnc for a desktop display. Got both of those things to work, but not in tandem. I'm a rather newbish with Linux and VNC, so I'm stuck at the moment. Any chance I can get pygame output on a VNC desktop?
What I have so far is that I've installed pygame using this and cloud9-vnc using this. Pygame import and commands run smoothly (both in terminal and script) and when I run the script with c9vnc I get the link to a VNC desktop. However, the desktop is clear, apart from Ubuntu logo.
The program doesn't actually seems to be running, considering that it doesn't display the text to be printed
In fact, it seems that it's not even started to run.
However, inside the VNC desktop I have the access to complete cloud9 workspace, including installed pygame, which does work, albeit a bit more clunky, compared to cloud9's interface.
So what I want to ask is is there a way for me to write and run a code on cloud9's default interface that would directly display the output in VNC's desktop, with little to no additional interaction?

Categories

Resources