How to run Pi Cap script at start-up
Learn how to the run Pi Cap script at start-up
When you develop a script for the Pi Cap you might want to run it as soon as you connect your Pi to power. This way you can light a status LED at launch, or set-up the Pi Cap directly as a piano. In this tutorial, we SSH into the Pi, you can also do this set-up with a screen, mouse and keyboard.
Step 1 Setting up your Pi Cap with a Pi
If you haven’t set up your Pi Cap then make sure to complete one of our set up tutorials first:
In this tutorial, we are using the network connection to work with the Pi Cap. If you are using a screen with your Raspberry Pi, all the steps here will also apply that method.
Step 2 Decide which code you want to run
The first step is to decide which code you want to run on start-up. This could be, for example, one of the button example scripts. In this tutorial, we are using the “spinning LED” script. The code you choose needs to be something that runs independently. So, for example, any code that depends on writing to the terminal window isn’t suitable for running at start-up. Any code that uses the button, the LED or the capacitive sensors of the Pi Cap is more suitable.
Step 3 SSH into the Pi
For this example, we are using the picap-colour-spin.cpp sketch, but you can use any of our examples sketches.
Once you have SSH’d into the Pi, enter “sudo nano /etc/rc.local” into the Terminal window and hit enter. At the bottom of the file, add “bash /home/pi/PiCapExamples/cpp/picap-colour-spin-cpp/run &” in-between “fi” and “exit 0”. If you now press CTRL + X, then Y, then enter, it will save the recent edits in the file.