How to use the LED on the Pi Cap

Find out how to use the LED on the Pi Cap

LED on the Pi Cap and Pi Zero

The LED on the Pi Cap has 7 colours: red, blue, green, yellow, cyan, magenta and white. The various colours allow you to give status indications of your code, for example, if an electrode is touched, or if a code is running. In this tutorial, we are going to show how to include the LED in the code. Here, we SSH into the Pi, but if you don’t want to use SSH and the terminal, you can also use a monitor, keyboard and mouse connected to your Raspberry Pi.



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:

Setting up your Pi Cap on the Raspberry Pi 1, 2 or 3

Setting up your Pi Cap on the Raspberry Pi Zero

Step 2 Inspect

After you’ve SSH’d into the Pi, open the script, by entering “nano PiCapExamples/Python/picap-colour-spin-py/”.  At the beginning of the code, from code line 38 to 60, is where the LED on the Pi Cap is set up. This is the part that you need to include the LED in your code. Select and copy that section of the code and exit the code by entering CTRL + X. You can also find this code on GitHub.

Step 3 Edit

Now open the script by entering “nano PiCapExamples/Python/picap-simple-touch-py/”. Copy and paste the code selection from the previous step just underneath the line “import signal, sys, MPR121“. This will set-up the LED for the simple-touch code.

Now, further down in the code, you can see the parts where the electrodes are touched and released. Add “light_rgb (0, 0, 1)” below the line “print electrode {0} was just touched.format(i)” and further add “light_rgb (0, 1, 0)” below the line “print electrode {0} was just released.format(i)”. Make sure to include the right spacing before the light_rgb lines – they need to be indented to the same level as the print lines above them.

When you are done, enter CTRL + X, then Y, then enter.

Step 4 Run the code

If you now enter “./run”, it will run the new simple-touch code. If you touch an electrode, the LED will light up blue and when you release it again, it will light up green.

If you want to use different colours, have a look at the colour-spin code. At the bottom of the code, you can see the set-ups for each colour.

In this tutorial, we used the Python code, but the same methods apply for the C++ or Node example programs, just make sure to head to the correct folder location.

If you have any questions or you just want to share your project with us, you can send us an email at info@bareconductive or contact us via Instagram or Twitter.

Have you seen these related resources?