Nav

How to use the LED on the Pi Cap

Find out how to use the LED on the Pi Cap

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 simple-touch.py 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.

 

 

Learn how to the run Pi Cap script at start-up

How to run Pi Cap script at start-up

Learn how to use Raspberry Pi projection mapping to turn a simple graphic into an augmented reality super-wall, activated by touch

Raspberry Pi Projection Mapping using a Pi Cap

Set the Pi Cap either as a touch or proximity sensor

How to make a proximity sensor with your Pi Cap

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

Links

Step 2

Inspect colour-spin.py

After you’ve SSH’d into the Pi, open the colour-spin.py script, by entering “nano PiCapExamples/Python/picap-colour-spin-py/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.

Links

Step 3

Edit simple-touch.py

Now open the simple-touch.py script by entering “nano PiCapExamples/Python/picap-simple-touch-py/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 simple-touch.py 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.

Links

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.

Links
LED on the Pi Cap and Pi Zero

Suggested Tutorials

Learn how to the run Pi Cap script at start-up

How to run Pi Cap script at start-up

Learn how to use Raspberry Pi projection mapping to turn a simple graphic into an augmented reality super-wall, activated by touch

Raspberry Pi Projection Mapping using a Pi Cap

Set the Pi Cap either as a touch or proximity sensor

How to make a proximity sensor with your Pi Cap

Categories

Bare Conductive

Instructions

Pi Cap

Date Posted

2018/08/16

Rating

0.00 avg. rating (0% score) - 0 votes