Hardware Reference
In-Depth Information
Start on power up
The first method we'll cover is also the most blunt—how to start a recording
or playback directly when powering up the Raspberry Pi. There isn't really a
standardized way of auto-starting regular user applications on boot, so we'll
have to improvise a bit to come up with our own way of doing what we want.
The Raspbian boot process is basically a collection of shell scripts being run one after
the other, with each script performing some important task. One of the last scripts to
run is /etc/rc.local , which is a good starting point for our custom autorun solution.
Right now, the script doesn't do much, it just prints out the IP address of the Pi.
You can try running the script any time using the following command:
pi@raspberrypi ~ $ /etc/rc.local
We could just jam our list of commands right in there, but let's try to make our
solution a little more elegant. We want the system to check whether there's an
autorun script in our home directory, and if it exists, run it as the pi user. This
will make sure our script doesn't accidentally wipe our entire SD card or write
huge WAV files in random locations.
1.
Let's start with the minor addition to rc.local :
pi@raspberrypi ~ $ sudo nano /etc/rc.local
2. We're going to add the following block of code just above the final exit 0 line:
if [ -x /home/pi/autorun.sh ]; then
sudo -u pi /home/pi/autorun.sh
fi
The preceding shell script means if there is an executable file named
autorun.sh in the pi user's home directory, then run that script as the pi
user (not as root , which would be the normal behavior for boot scripts).
If we run /etc/rc.local right now, nothing new would happen—not
until we create the autorun.sh script in our home directory and make
it executable.
3.
So let's create our autorun script:
pi@raspberrypi ~ $ nano ~/autorun.sh
 
Search WWH ::




Custom Search