Gemma-M0 touch sensor dropout/failure

Adafruit's tiny microcontroller platform. Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
cjames53
 
Posts: 7
Joined: Fri Oct 07, 2022 6:54 pm

Gemma-M0 touch sensor dropout/failure

Post by cjames53 »

I'm using Gemma-M0's as capacitive touch/proximity sensor mode. The Gemma is essentially an amplifier that sense proximity and send an analog voltage to a wire that is sensed by a larger platform (e.g. an Arduino board).

It mostly works superbly. But ... if the touch is too direct, like a person places a hand firmly on the sensor, the sensed "proximity" suddenly drops from 100% to 0%. This renders the whole thing rather useless.

My suspicion is that a touch that is "too strong" overloads the PWM and basically shorts it out, cutting off its ability to sense the capacitance around the sensor. But that's just a guess.

Here is the code I'm using:

Code: Select all

"""CircuitPython Essentials Capacitive Touch example"""
import time
import board
import digitalio
import touchio
from analogio import AnalogOut

touch_pad = board.A1  # Will not work for Circuit Playground Express!

led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT
led_cycle = 0;

touch = touchio.TouchIn(touch_pad)
analog_out = AnalogOut(board.A0)
analog_factor = 60

offset = 0.0;
for i in range(100):
    offset += touch.raw_value
offset /= 100.0
offset = int(offset + 0.5)

print("Initial offset: ", offset)

filtered_value = offset;
n = 0;
while True:
    filtered_value = touch.raw_value; # /100.0 + filtered_value*0.99
    output = (int(filtered_value) - offset) * analog_factor
    if output < 0:
        output = 0
    elif output > 65535:
        output = 65535
    analog_out.value = output;
    led_percent = int(output * 100.0 / 65536.0)
    if led_cycle < led_percent:
        led.value = True
    else:
        led.value = False
    led_cycle += 1;
    if led_cycle > 99:
        led_cycle = 0
    n += 1
I'm considering inserting a resistor between the Gemma-M0 and the touch/proximity sensor, but I have no idea what the impedence of the capacitive sensor is, so don't know what resistor would be appropriate, or even if that's a good idea.

On a related note, I've discovered that if I touch two of the capacitive sensors at once, one with my left hand and one with my right hand (both powered from the same source), they both drop out, showing zero proximity. I can only guess that the PWM signals are passed through my body and the two Gemmas are confusing each other.

Any suggestions?

Thanks!

User avatar
alpierce
 
Posts: 206
Joined: Mon May 13, 2013 2:44 am

Re: Gemma-M0 touch sensor dropout/failure

Post by alpierce »

What are you using as your touch plate? Perhaps you could cover it with an appropriate thickness of acrylic, glass, or some other material so it could not be touched directly? Seems you want it ro react when your hand is close, but not actually touching. Just a thought.

User avatar
cjames53
 
Posts: 7
Joined: Fri Oct 07, 2022 6:54 pm

Re: Gemma-M0 touch sensor dropout/failure

Post by cjames53 »

What are you using as your touch plate? Perhaps you could cover it with an appropriate thickness of acrylic, glass, or some other material so it could not be touched directly? Seems you want it ro react when your hand is close, but not actually touching. Just a thought.
Thanks, that is indeed a solution. The trouble is we're using a wide variety of sensor material, from conductive thread to metal foils, perhaps even conductive ceramic glazes. This project is for artists who want to create touch-sensitive pieces, and it's hard to say what might work best for them.

User avatar
cjames53
 
Posts: 7
Joined: Fri Oct 07, 2022 6:54 pm

Re: Gemma-M0 touch sensor dropout/failure

Post by cjames53 »

Update: I expermented with resistors ranging from 1K to 40K, and it made no difference, except that at 40K sensitivity was reduced.

User avatar
cjames53
 
Posts: 7
Joined: Fri Oct 07, 2022 6:54 pm

Re: Gemma-M0 touch sensor dropout/failure

Post by cjames53 »

Bumping this discussion -- I could use some help with this!

Nothing I've done works. It's important to our project to use the Gemma-M0's capacitance-proximity feature, but at this point the "dropout" mentioned in my initial posting makes it nearly useless. Does anyone have knowledge of the inner PWM circuitry and software, and have an idea why this is happening, plus what to do about it?

Thanks!
Craig

User avatar
alpierce
 
Posts: 206
Joined: Mon May 13, 2013 2:44 am

Re: Gemma-M0 touch sensor dropout/failure

Post by alpierce »

Maybe just handle in software such that it can't exceed 100% or won't accept zero value unless it is the initial value.

User avatar
adafruit_support_mike
 
Posts: 67391
Joined: Thu Feb 11, 2010 2:51 pm

Re: Gemma-M0 touch sensor dropout/failure

Post by adafruit_support_mike »

Do you have the option to use smaller touch pads?

Touch sensors operate on two basic principles:

1 - Everything has some amount of parasitic capacitance.

In effect, any conductor connected to a voltage forms one plate of a theoretical capacitor whose other plate is an infinite distance away. That sounds weird, but when you crunch the numbers you get values that can be confirmed experimentally. The average 1cm pad has a few picofarads of capacitance.

2 - For equivalent volumes, water stores about 80x as much energy as air when used as the dielectric in a capacitor.

Electric fields obey the inverse-square law, so things close to the touchpad have much more effect than things farther away. In practical terms, almost all of the energy stored by parasitic capacitance lives in the volume of space above the pad, going up about half the pad's smallest dimension. That space is effectively the insulation layer between the pad and the rest of the universe.

When the pad is untouched, that region of space is filled with air. When you touch the pad, most of that space is mostly filled with the water in your tissue.

Water molecules are polar, so they tend to rotate in line with an external electric field. That rotation stores energy, making them particle-scale torsion springs. As mentioned before, those molecular springs can store about 80x as much energy as air or vacuum, which changes the value of the parasitic capacitor dramatically.

The unit of charge is the Farad, which reduces to Coulombs of charge per Volt. A 1F capacitor's voltage changes by 1V for every 1 Coulomb of charge you pump in or out. A 1uF capacitor changes by 1V for every microcoulomb.

The unit of current is the Ampere, which reduces to Coulombs of charge (about 6.25e25 electrons) per second. Charging a 1F capacitor at 1A will make its voltage change at a rate of 1V/s. Charging a 1uF cap at 1A will make its voltage change by a million volts per second.


Touch sensors work by feeding the touchpad a fixed amount of current and measuring how long it takes to charge the pad to a given voltage. The exact voltage isn't important as long as it stays consistent over time, so microcontrollers use the high-input threshold voltage of a GPIO pin.

The code that manages touch sensing measures how long it takes to bring the pad to 'on' voltage, and keeps a running average of that time. If the time suddenly becomes much longer, it's considered a touch event. When the time suddenly becomes much shorter again, it's considered a release event.

You can use the amount of change to measure proximity, but only in rough terms.


What do you get as raw values from the touch sensor? It sounds like your issue has more to do with processing the data than the sensor itself.

Locked
Please be positive and constructive with your questions and comments.

Return to “Trinket ATTiny, Trinket M0”