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!
To begin you will need:
- 1x Pi Cap
- 1x Raspberry Pi 1 A+ or B+, Raspberry Pi 2, Raspberry Pi 3 or Raspberry Pi Zero setup with the Pi Cap (see Step 1)
If you haven’t set up your Pi Cap then make sure to complete our setting 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, that’s fine, all the steps here apply to the screening method.
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.
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.
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.
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.