Nav

Pi Cap + MQTT

Learn how to connect your Pi Cap touch events to the internet.

This tutorial uses the Bare Conductive Pi Cap in combination with a Raspberry Pi to connect the touch events to the internet via MQTT. It requires an account with Adafruit’s IoT platform, Adafruit IO, to get access to a MQTT broker. The events that are sent out, can then be visualised in an Adafruit IO dashboard.

This tutorial was provided by our community member Sven Haiges, thank you very much Sven!

Use the grapher to visualise the sensitivity and precision of the Pi Cap’s sensors.

Pi Cap + Grapher

Follow this tutorial to set up your Pi Cap with a Raspberry Pi 1 A+/B+, Raspberry Pi 2 or Raspberry Pi 3.

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

Follow this tutorial to set up your Pi Cap with a Raspberry Pi Zero.

Setting up your Pi Cap on the Raspberry Pi Zero

Materials

To begin you will need:

1x Pi Cap

1x Raspberry Pi 1 A+ or B+, Raspberry Pi 2 or Raspberry Pi 3
setup with the Pi Cap (see Step 1)
or
1x Raspberry Pi Zero
setup with the Pi Cap (see Step 1)

Step 1

Setup a Raspberry Pi & Pi Cap

If you haven’t set up your Pi Cap then make sure to complete our setting 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

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, that’s fine, all the steps here apply to the screening method.

Step 2

Create the dashboard and get the AIO key

Before we start working on our Raspberry Pi, we first need to set up our MQTT broker, Adafruit. Head over to io.adafruit.com and sign up for the public beta. Once you’ve signed in, create a new dashboard by clicking on “My Dashboards”, then “Your Dashboards” on the left. Click the blue “Create Dashboard” button and give the new dashboard a name for example, “Pi Cap Dashboard”. Open the new dashboard and then click the little key icon on the top right, shown in the bottom right image. This will reveal the AIO key for this dashboard. Copy the key as you will need it later.

Step 3

Running the code on the Pi Cap

There are three programming languages to run the MQTT code, C++, Python and Node.js. We will be using Python, but each code example will perform identically.

After you have logged in to your Pi Cap via SSH, head to folder “picap-simple-mqtt-py” by entering “cd ~/PiCapExamples/Python/picap-simple-mqtt-py”. Then enter “./run -b io.adafruit.com -u USERNAME -p KEY”, where USERNAME is your username you used to sign up to io.adafruit.com (note – your username is not your email address) and KEY is the key you generated earlier. Hit enter and the code should be running. You won’t see any outputs, which is as expected. If you want to cancel the code press CTRL + C.

Step 4

Verify feed data

You can now check that everything is set up by checking the feeds in your Adafruit account. Head back over to io.adafruit.com and click on the ”Your Feeds” link on the left and check if there is a ”picap-touched” and ”picap-released” feed. You may have to wait a couple of seconds and refresh the page. If there the two feeds appear, congratulations! You got it all set up.

Step 5

Setup the Dashboard

You can now choose a visualisation of the feed. Open the dashboard you created before and click on the blue + icon on the right to add a new widget. Choose the gauge which displays the topic feed value in real time.  To configure the gauge, click “CHOOSE” next to the “picap-touched” feed in the list and click next. Here choose 11 for the max value. If you want you can change the style of the gauge to thick.

Finally, click ”create block”, and you should see a ”picap-touched” widget on the screen. Repeat these steps for the released feed. In the end, you will see the gauges as shown in the bottom image. Now, try touching a few of the electrodes – you should see the gauge moving accordingly. If you aren’t seeing anything, try stopping the code on the Raspberry Pi (remember, you have to use Ctrl+C) and then re-running it.

Suggested Tutorials

Use the grapher to visualise the sensitivity and precision of the Pi Cap’s sensors.

Pi Cap + Grapher

Follow this tutorial to set up your Pi Cap with a Raspberry Pi 1 A+/B+, Raspberry Pi 2 or Raspberry Pi 3.

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

Follow this tutorial to set up your Pi Cap with a Raspberry Pi Zero.

Setting up your Pi Cap on the Raspberry Pi Zero

Categories

Community

Instructions

Pi Cap

Date Posted

2016/11/03

Rating

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