Autostart GPIO programs

I couldn’t get my timer program to start with the R Pi. Tried the usual places /etc/rc.local and /home/user/bashrc. but for unknown and possibly file locking problems neither worked.

SparkFun to the rescue! The below is based on:
learn.sparkfun.com/tutorials/how-to-run-a-raspberry-pi-program-on-startup/all

Create a .desktop File
You do not need root-level access to modify your profile’s (user’s) autostart and .desktop files. In fact, it is recommended that you do not use sudo, as you may affect the permissions of the file (e.g. the file would be owned by root) and make them unable to be executed by autostart (which has user-level permissions).

Open a terminal, and execute the following commands to create an autostart directory (if one does not already exist) and edit a .desktop file:

mkdir /home/user/.config/autostart
nano /home/user/.config/autostart/CountUp.desktop
Copy in the following text into the CountUp.desktop file. Feel free to change the Name and Exec variables to your particular application.

[Desktop Entry]
Type=Application
Name=CountUp
Exec=/bin/bash /home/admin/CountUp/CountUp.sh

CountUp.sh contains this:
#!/bin/sh
cd /home/admin/CountUp
sudo ./CountUp

1 Like