todbot / picotouch

Tiny capsense touch MIDI keyboard controller from a Raspberry Pi Pico

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How the basic reading of individual electrode works

Sciss opened this issue · comments

commented

Hi there. I'm trying to understand how I could use your project as a starting point for getting capacitive proximity sensing done on a Pi Pico. If I want to bypass the PCB, what would be the minimum setup to connect a single electrode? I am looking at the touchio API, but I don't understand how this works with a single pin. I suppose this one GPIO pin that gets toggled between output (temporary switching from low to high) and input (then reading, "counting" the delay till it returns to low)? What does your circuit do exactly; it connects one GPIO pin to one electrode, and in parallel with 1 MOhms to GND or something like that? Thanks!

Hi,
For each touchio capacitive touch sensor input, all you need is one 1M ohm to ground. So it's not really a circuit exactly, just some wiring with a resistor. There's a bit more detail about CircuitPython cap touch here: https://learn.adafruit.com/circuitpython-essentials/circuitpython-cap-touch

This video post on Twitter shows the same circuit as pictouch but implemented on a solderless breadboard with just a bunch of resistors, one per input.

To do a single input, it would look something like:

import time
import board
import touchio

# put 1M resistor from GPO to ground, then touch GP0 to trigger
touch = touchio.TouchIn( board.GP0 ) 

while True:
    if touch.value:
        print("Touched!")
    time.sleep(0.05)

To do proximity sensing (as opposed to touch sensing) with capacitive touch, just use more metal connected to your touch input (board.GP0 in the above example). This "more metal" could be a longer wire, wrapped into a coil, a metal plate, etc. Note that proximity sensing is generally very finicky as it will vary based on person, ambient humidity, battery voltage, and other environmental factors.

But here's an example of doing proximity capacitive sensing using CircuitPython:
https://github.com/todbot/qtpy-tricks#use-capsense-as-proximity-detector-to-make-spooopy-ghost

commented

Thanks a lot for taking the time, I'll try this out. It's all a bit of a mystery, there is just a confusing amount of alternative touch sensing designs out there :)

Yes, it can be confusing. Fundamentally they are all working the same way, just as you outlined: a GPIO pin is switched to an output, set HIGH to charge the pin capacitance, then switched to input and time how long it takes to go LOW through a known resistance.

In some chips, this functionality is implemented in hardware, with an internal resistor and timing circuitry. In other implementations, the sense resistor is connected to two pins so it can be charged in both directions (which can improve results). And every chip vendor has their own version of an API on how to do it.

CircuitPython attempts to simplify things by providing one touchio API to hide all that variation, even though there's about four or so different vendor APIs, depending on which chip is running CircuitPython.