Posts: 7
Joined: Fri Feb 27, 2015 6:47 am

Loading my app like Scratch loaded at boot time

Fri Feb 27, 2015 7:06 am

Hi All -

I am relatively new to raspi world. I am creating an application in Python and want to run it at boot time. Exactly the same way it does while you set up "Scratch" to load post boot (by changing the raspi-config - "Enable boot to Desktop/Scratch" option and select Scratch).
1. Can I directly boot to “My App” instead of scratch?
2. If YES, what are the steps I need to follow to achieve this?
3. If NO, what is the closest option to get this functionality? I don’t want the command line or desktop after boot. And want only “My App” will be running after boot.
4. When “My App” is closed (with some key mapping - ESC etc.), the Raspi will shut down.
5. Even if 4 is not possible, I want a solution for 3.
Apology for my poor search skill, if this is already discussed somewhere. A solution will definitely help me. Thanks in adv.


Posts: 7
Joined: Fri Feb 27, 2015 6:47 am

Re: Loading my app like Scratch loaded at boot time

Wed Jun 03, 2015 5:07 am

Hi All -

Can someone help me on this topic?


Posts: 107
Joined: Sun Jan 18, 2015 1:31 pm

Re: Loading my app like Scratch loaded at boot time

Wed Jun 03, 2015 12:10 pm

I may can help you with some of your request. After trying all of the "normal methods" to auto start my Python script a couple of things became apparent to me.

1. If your script uses the "x" environment then some stated autostart routines will not work.
2. If your script uses the GPIO pins then some of the stated autostart routines will not work.

Facing these 2 challenges, through much trial and error I figures out this method to be VERY reliable to always start my script and the end user never sees the desktop (except for a few milliseconds) before my program launches correctly with sudo access to the GPIO.

I do not know exactly why this works where other methods fail, someone much smarter than me may chime in:

If using X and GPIO then you have to make 2 Python scripts, one exist only to start the other, the main script.

(In the terminal type this, this is for Rpi2)
sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

(add this to the file)
@/usr/bin/sudo python3.2 #(where is the script that will launch the main script)

The script will look something like this:

#!/usr/bin/env python3
#import python system modules
import time
import subprocess
import sys
import os

time.sleep(1) #may not be needed
os.system("cd /home/pi") #navigate to the correct path of the actual Python script
time.sleep(1) #may not be needed
os.system("sudo python3.2") #launch the main Python program

Save this file in home/pi and make it executable
Save the Main Python script in home/pi and make it executable

This method has been 100% reliable for several months now.


Posts: 7
Joined: Fri Feb 27, 2015 6:47 am

Re: Loading my app like Scratch loaded at boot time

Wed Jun 03, 2015 2:16 pm

First thing first...
Many thanks to B.Goode and Henry for your quick reply. They are really informative and worth trying. I'll definitely try them out and if any issues, will let you know.
But before I go ahead, let me explain my work a little more, just in case this helps you to add any further info.
Sincere apology for my naivety in this RPi /Python world.
My work…
I am working on a new python application, which essentially has few modules - an UI module (based on Tk), a GPRS module (for HTTP), a sensor module (GPIO), Bluetooth and whole bunch of logic.
So far what I was doing is - running the python program (sudo python myprog.pyc) from crontab (at startup) by booting to the UI mode at RPi startup. No issues, it is running fine.
What I want...
I want to take this application to a more advanced level. This program will run in headless mode w/o any monitoring forever (which it is doing now also). For that I want to...
1>Suppress all boot text and insert my own image(.gif if possible), so that once started, pi w/o showing the text scrolling, shows custom image and 2> then directly opens up my application w/o showing anything in between, not even the desktop with empty background
The sequence of events should be…
RPi powered ON ->My image displayed in the foreground (booting is going on background)->booting ends(My image is gone)->My program starts and UI displayed(some images etc.)
Some control information is passed to my program->My program shuts down->RPi shuts down
My questions are...
Is it doable from RPi UI mode login? If not, I am hoping I will not get access to the Tk etc. from RPi console mode, as they are essentially part of UI module, then how do I launch my program from console mode. Or Am I sounding over ambitious?

Please put some light on part <1> of my question as well.

Posts: 501
Joined: Fri Jun 29, 2012 4:27 pm

Re: Loading my app like Scratch loaded at boot time

Wed Jun 03, 2015 3:12 pm

English isn’t my first language, so please excuse any mistakes.

Return to “General discussion”