Let's get started with the PiicoDev Capacitive Touch sensor and a Raspberry Pi Pico. In this tutorial we'll cover reading the touch-status of each pad, changing some setup options to tune the sensor for different tasks, and do a little colour-mixing project using some WS2812B LEDs (GlowBit, Neopixel etc.)

Transcript

I'm going to show you how to get started with your PiicoDev capacitive touch sensor and a Raspberry Pi Pico. We'll connect these two together and get some example code running so you can detect touch events on each pad, and then we'll remix that code to create a lighting controller. Let's do it.

To follow along, you'll need a PiicoDev capacitive touch sensor, a Raspberry Pi Pico with the pin soldered facing down, a PiicoDev expansion board for Raspberry Pi Pico, and a PiicoDev cable. Plug your Pico into the expansion board, making sure that the USB connection is on the same side as the 2-pin battery connector. Connect the cable to the PiicoDev socket at the bottom, and connect the other end to your capacitive touch sensor. And I've just mounted everything to this PiicoDev platform to keep it in place for the rest of the tutorial. Finally connect your Pico to your computer with a USB lead.

In the download section for this tutorial, find the 3 files that we need to download, right click each link and select save link as. I'm going to save these somewhere that makes sense, like a PiicoDev directory in my documents.

Next open up Thonny, navigate to that same directory you saved those files, here they are in my documents PicoDev, and you may have to click the start stop button just to connect to your Raspberry Pi Pico, here it is down the bottom left. Connect the 3 files that you downloaded with a left click on the top one, hold down shift, and click on the bottom one, then right click and upload to. We can see those 3 files have uploaded to the Pico.

Double click main.py on the Raspberry Pi Pico to open up that example script, and this is what we're working with. We can press control D to run the script, and we have coming out in the shell, we have 3 digits on the right hand side all reading 0s, and they correspond to touchpads 1, 2 and 3.So, if I touch touchpad 1, we can turn the first digit to a 1. If I touch touchpad 2, the second digit becomes a 1, and the same for touchpad 3. You can see that reflected in the plot on the right. If I touch 1, the blue line goes up, 2 is the orange line, and 3 is the red line. If I slide my finger along the touch sensor, I can actually trigger 2 adjacent pads. Here we have touchpad 1 and 2 registering a touch event simultaneously, and 1 and 3. You can see that in the graph as well.

We've got a few options when we set up the touch sensor. We can pass in the argument touch mode equals single as a string, and I've just pressed control R to run that. Now, if I touch a pad and then another pad, it rejects that second touch event. So, that can be useful if you want to, say, slide your finger from one pad to another and not allow multiple touch events at the same time. Sliding along the sensor, I can only cause one of those indicators to be a 1 at any time.

The touch sensor also has a programmable sensitivity from 0 to 7, with 0 being the most sensitive, and 7 being the least sensitive. You can change that sensitivity with the sensitivity argument. If I set it to be very sensitive at 0 and run the script again with control R, then I may not even have to touch the sensor to get a touch event. My finger is hovering just above the pad, but it's still registering an event. You might want to tune the sensitivity if you want to put a label over your touch sensor. This way, you can put your text or pictures on the touch sensor and give each button a new meaning.

You might also want to tune the sensitivity if you intend to clip onto these ring terminals with some alligator clips, so that you can clip them onto other objects and use those objects as touch sensors. Now, for a fun little project.I'm going to connect this Globit Rainbow to the Pico, and use the numbers 1, 2, and 3 to control the colours that are shown on these LEDs. We've covered connecting a Rainbow to a Raspberry Pi Pico before, check out our tutorial for that.

Copy the remix code out of the article, and paste it into your main.py. In the loop at the bottom of the main script, we have, as usual, status equals touch sensor dot read to read the status of the pads. And then we use that status to load either a 0 or a 255 into three variables, R, G, and B. We use the amount of red, green, and blue to mix in on the LEDs. Then we just call pixels dot fill RGB to show the solid colour on the whole strip that we have determined using the touch pads.

The following code basically just prints out whichever colour is appearing in the LEDs. So if we run the script, there's red, there's green, and there's blue.

So 1 is red, 2 is green, and 3 is blue. If I touch 1 and 2 at the same time, we can mix red and green to make yellow. And 1 and 3 at the same time, red and blue, make magenta. And just for completeness, 2 and 3 at the same time, green plus blue, is a nice like aquamarine.

And so there you have it. We can register touch events using the PiicoDev capacitive touch sensor. We can even branch our program to do different things depending on which sensor is being pressed. In this case, we're printing a different message into the shell, but we're also changing our program's behaviour just by using that status indicator in the way that we determine the values of some variables.

So there you have it. I hope this little starter project inspires you for your own projects using the PiicoDev capacitive touch sensor. In this little starter project, we were able to change the print message based on what pad is being pressed, so we can branch our program to do different actions.Depending on which button or pad is being pressed. We also used that status to change what values are loaded into certain variables so that we can make a nice lighting display.

If you make something cool from this starter project, or if you just need some help, head over to the Core Electronics forums. We'd love to see you there.

And until next time, thanks for watching.

Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.