Saturday 23 March 2013

Snowboard HUD Part 6 - Auto-launching the script

Now that the battery pack has arrived I can now think about making this mobile.

Before I get on to connecting up the battery, I need to make the display script start up automatically, since when it is out and about it wont have a keyboard attached in order to load the script.

Running scripts on startup can be achieved in a number of ways. I wish I could find a decent article somewhere that descripbes all the different methods and why you might choose one over the other. I have in the past modified the .profile file within the user's home folder, but in this case I need to run scripts using sudo, and I haven't been able to do that using the .profile. Therefore what I've done is used the guide from here.  First I created a new file called rungui

sudo nano /etc/init.d/rungui

and put this text into it

#! /bin/sh
# /etc/init.d/rungui

### BEGIN INIT INFO
# Provides:          noip
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Simple script to start a program at boot
# Description:       A simple script which will start / stop a program a boot /$
### END INIT INFO

echo 'called rungui script'

sudo killall gpsd
sudo gpsd /dev/ttyUSB0 -F /va
sudo python /home/pi/test_gui3.py

exit 0

The important lines are at the bottom

The two lines that refer to gpsd have been added since for some reason my GPS has stopped working unless you do this on every boot. I have no idea why, I don't think I have changed anything since I first got this working, but eventually I found I could fix it with these two lines. So I'm calling them on every boot of the pi.

The script is then called suing python /home/pi/test_gui3.py. I should probably rename that something sensible at some point.

Once this file is created run:

sudo update-rc.d rungui defaults

and the script should be launched automatically when the pi boots.



No comments:

Post a Comment