[SOLVED] Can you automatically start basic_test_all.py on boot?

Hello, I was wondering if you knew a way to automatically start basic_test_all.py on boot? I can run the script just fine by using ssh and another computer on the network or by plugging a monitor and keyboard into the pi itself. However I really just want the pi to start, the script to run automatically, and I can press the keys to move the robot around.

I tried this tutorial: http://www.instructables.com/id/Raspberry-Pi-Launch-Python-script-on-startup/?ALLSTEPS However, I think cronjobs must not be okay with user input because my log says the following:

Cmd: Traceback (most recent call last): File “basic_test_all.py”, line 6, in <module> a=raw_input() EOFERROR: EOF when reading a line.

Is there a way that this could work? Thank you.

Hi,
Just wanted to check a few things, are you using a wireless keyboard to control the GoPiGo after setup because the cronjob would be running on the main terminal after boot.

Also, would it be possible for you to connect the Pi to a monitor and check why the script is failing.

-Karan

Hello Karan,
Thanks for your help.

I am using a wireless keyboard connected to the GoPiGo. I used the keys specified in the file to try to move it after it boot. I have tried it with a monitor connected directly to the pi. However, I don’t see a terminal pop up on boot, and pressing the keys doesn’t move the GoPiGo.

The chron log shows that EOF error. However, if I try to run the launcher.sh file manually by going to its location and typing “sh launcher.sh” it does start the program, and I can use the keys to move it. So I know my launcher is working, the given python program is working, but it doesn’t start automatically with the chron job and instead has the EOF error in the log.

Thanks again :slight_smile:

Hi,
I think that the problem might be with the way you running the script. At startup there are other things there are also programs being run one by one so maybe the python Program try to block their execution because it’s waiting for the input and the OS terminates the program. I am not sure about this but it does look like the problem is related to getting the user input on runtime.

I found this thread on the Raspberry Pi forums which might come useful. What it does is that it delays the script to run after a few seconds. Might be worth a try http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=46125.

The raspberry Pi forums might be a better place to ask this question.

Do let us know if you are able to solve this problem.
-Karan

Hello Karan,

Thanks for all your help and for the thread. After reading that forum, it is working!

First, I decided to use basic_robot.py and I moved it to my desktop.

Then I did the following:
mkdir ~/.config/autostart
nano ~/.config/autostart/myprogram.desktop

I entered this in nano and saved:
[Desktop Entry]
Exec=lxterminal -e "sudo python /home/pi/Desktop/basic_robot.py"
Type=Application

I also made the given Python program executable by: chmod +x basic_robot.py Then I checked that the python program had the #!/usr/bin/python at the top of its program and it already did.

I rebooted and now it starts the program in terminal. I can press a key and the enter key for it to move without having a monitor attached or using ssh from another computer.

Thanks again. :slight_smile:

Hi,
Great to hear that it’s working and thanks a lot for letting us know how to get it to work. Hopefully this will help someone else too in the future.

Thanks again,
Karan

Dear Karan,
I am also having the same kind of problem.Stared using pi few days back.
following is my code located at /home/pi

#!/usr/bin/python
name = raw_input()
print name

thats all.
In above example I could not see the reference myprogram.desktop anywhere.
In what way I can make above example executable 5 seconds after boot ?
In attached link /yourpath/bin/yourscript.sh & is mentioned. Does yourpath means make something new having /bin directory & then .sh in that ?
Your help will give me a boost.
Thanks
vpmax

Hi,
This should help you with writing the desktop file:http://www.raspians.com/Knowledgebase/putting-shortcuts-on-the-desktop/ .

So what worked for @rosetyler was that she made a .desktop file which had a link to the python file and placed the desktop file in the autostart folder.

Try it out and let us know how it goes.

-Karan

Dear Karan ,
Thanks for your quick reply. I will try to understand the mechanism related to this. One more thing I will never be using windows part of it I mean GUI (Is it desktop refered above ?) Will it still work for me ? I will be using command prompt of things . It shows ~$. Thanks again. I will let you know . It may take little more time for me to understand whole thing.
Thanks again

Hi,
I think it should work, because it is automatically loaded on startup. I have not tried this but it worked for @rosetyler without SSH or using a desktop. I think what is does is the after the boot sequence getting completed and the desktop loads, it automatically starts the script and whatever you enter via the keyboard is automatically taken by the script. You might have to set the Pi to boot to desktop.

This a pretty clever hack nad I can’t think of a better way to do it.

Let me know if it works for you.

-Karan

I tried hard with many ways but no success yet. I tried to move .desktop file in .Desktop folder but could not run.
I will start all again may be some thing missing as there are no errors or warnings.
Thanks
When it works I will let you know.

Hi, Do let us know if you are able to get it to work and the Raspberry Pi forums would be a good place to start looking around for answers and asking questions.

-Karan

I have to add usr/bin/lxterminal in the path though it is in the first line of the program. Whole program is working now . Procedure mentioned above is correct.
Thanks Karan for your help and encouragement.
vpmax

My daughter is attempting to use the method above to autostart a Scratch project on her GoPiGo 2. We are successfully getting Scratch to start upon boot, but it requires a mouse to click Start Programming and then on “OK” on the alert that follows. Is there a way to either bypass those or include that input in the .desktop?

Thanks!

We are using the .desktop file to start /home/pi/Dexter/lib/Dexter/Scratch_GUI/Scratch_Start.py

If there is a better way of doing this, please let us know. Thanks!

Hi @mike3,

You have to run 2 commands in order to get GoPiGo and Scratch going at start-up:

sudo bash /home/pi/di_update/Raspbian_For_Robots/Scratch_GUI/scratch_direct  /home/pi/di_update/Raspbian_For_Robots/Scratch_GUI/new.sb
sudo python /home/pi/Dexter/GoPiGo/Software/Scratch/GoPiGoScratch.py

Using these 2 commands will bypass the window and will directly jump into Scratch.

Thank you!

@RobertLucian, thank you! That worked for her with one very minor tweak. The f in Raspbian_for_Robots is actually capitalized on her instance. So it is actually Raspbian_For_Robots. Thanks again for a quick response to my question.

1 Like