Comments: How to Run a Raspberry Pi Program on Startup

Pages

Looking for answers to technical questions?

We welcome your comments and suggestions below. However, if you are looking for solutions to technical questions please see our Technical Assistance page.

  • Hi Sparkfun Thanks for the tutorial but as a product designer who is a newbie to pi and programming (apart from arduino) I would have appreciated a bit more warning about the risks of running a program on startup that you can get locked into. I wrote a python3 script that feeds the camera preview to the screen, in fullscreen, with a couple of gps data feed variables overlaid to it - essentially a heads up vehicle display showing speed and position. I wanted this to load directly when the pi is booted so I followed your tutorial and it looked like the Method 2 autostart was the best option. I deliberately included a keyboardInterrupt in the code so that ctrl+c would always exit back to the normal raspbian GUI. I wrote and debugged it in Thonny and the keyboard interrupt always worked. I also (following your warning in the tutorial) ran the program direct from terminal and the interrupt worked there too. So I felt confident to load it in autostart by changing the filepath in your clock.desktop file to point to my script. I rebooted the pi. The program loaded. I had my camera feed and my gps data showing over it. but ctrl+c did nothing, so I'm locked into it. The only keyboard override I could get to work was Ctrl+shift+del+F2 which reboots the pi and starts the cycle again. So followed about 4 hours of working out how to load the SD card into my macbook, edit the cmdline file to force a safe mode boot, boot it back in the pi, access the clock.desktop file to change the filepath named in it to some fictional file, find that the pi has rebooted in read only mode so I can't make that edit, work out the command to remount it in rw mode, change the clock.desktop filepath, go back to MacOS and remove the safemode command again in cmdline.txt, so that I can finally reboot back into my normal pi GUI. That was fun! Do you have any suggestions for why the keyboardInterrupt works when I'm manually running my script from either Thonny or Terminal, but not when autostart it? Thanks

  • Thanks for the tutorial, I was struggling to get the rc.local method to work but the autostart option worked great.

    FYI there is a small typo on the autostart code:

    mkdir /home/pi/.config/autostart nano /home/pi/.config/autostart/clock.dekstop ---should be desktop


If you've found a bug or have other constructive feedback for our tutorial authors, please send us your feedback!