Raspberry Pi 3Sometimes you want stuff to run at startup, be it an application or a forced setting. This is fairly easy to achieve in Rasbpian, here’s how:

You can use the Raspbian preferences via the GUI to cause the pi user to be auto logged in at boot up and the GUI to automatically run. However, if you need to run with root privileges due to needing IO pin control (PLEASE NOTE: It is not advised to run as root) then set the Raspbian preferences to boot to the command line. Now open this file by editing it(you can use your favourite editor, for this example we use nano):

sudo nano /etc/rc.local

Before the “exit 0” line in it add the following line:

#Auto run the GUI as root
sudo startx

Save it by pressing Ctrl+X, ” Y“, ENTER

Reboot your RPi and it should automatically run the GUI as the root user.

Setting An Application To Automatically Run In The GUI

For the standard Pi user (if not using “sudo startx“):

sudo nano /home/pi/.config/lxsession/LXDE-pi/autostart

For the root Pi user (if running the GUI with “sudo startx“):

sudo nano /root/.config/lxsession/LXDE-pi/autostart

This is the same file that is edited if you are disabling the screen saver, it executes applications/options when the GUI loads for a user. To run an application you simply add it on a line starting with a ‘@‘ character. A good way to test if it works is to run one of the built-in applications, e.g. LXTerminal, by adding the following:

@lxterminal

Use CTRL+X to save the file and then restart the GUI, you should see that LXTerminal is opened as soon as the GUI loads.

To run your own application then simply give the path to the executable file, which in this example is called “YourAppNameHere”:

@/home/pi/projects/myfolder/YourAppNameHere

Questions? Comments?

 

Share:
What do you think of this post?
  • Interesting (1)
  • Sucks (0)
  • Boring (0)
  • Useful (0)
  • Awesome (0)
\