VincentARM
Posts: 15
Joined: Sat Feb 06, 2021 8:00 pm

is it possible to use pico pins for detect contact fingers ?

Fri Apr 23, 2021 4:34 pm

Hello.
Is it possible to detect if one finger or several fingers are placed on 2 pins of Pico?
What can be measured (resistance ?, temperature? Pulse?) And how?
If so, which pins can be used?
Thank you.

danjperron
Posts: 3747
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: is it possible to use pico pins for detect contact fingers ?

Fri Apr 23, 2021 5:16 pm

This is one idea.

capacitive effect.

Set the pin High and then set the pin on INPUT with pull down. Check the times it takes to return to 0. if something like a finger touch it will be longer! The PIO is perfect for that.

You could do the inverse also. Set Low with IN+ pull up!

There is some PIO timer already posted!

danjperron
Posts: 3747
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: is it possible to use pico pins for detect contact fingers ?

Fri Apr 23, 2021 6:37 pm

this is an example using PIO on pin16

You could increase the timing by using high resistor value instead of the pull_down resistor.

Just remove the Pin.PULL_DOWN.

B.T.W. Having the pin floating, no external resistor or PULL_DOWN, could be use also but what you get is noise .


run the program and touch the PIO16.

Code: Select all

'''
 *
 *
 * The MIT License (MIT)
 *
 * Copyright (c) 2021 Daniel Perron
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
'''

''' this is a program to read the timing when finger touch'''


import utime
import rp2
from rp2 import PIO, asm_pio
from machine import Pin, mem32
    
@asm_pio(set_init=rp2.PIO.OUT_HIGH)
def GetTouchPulse():
    set(pindirs,0)
    set(x,0)
    label('loopH1')
    jmp(x_dec,'loopH2')
    label('loopH2')
    nop()
    jmp( pin, 'loopH1')
    mov(isr,x)
    push()
    label('done')
    jmp('done')

try:

    while True:

        p16 = Pin(16,Pin.OUT,Pin.PULL_DOWN)
        p16.value(1)
        sm0 = rp2.StateMachine(0,GetTouchPulse,in_base=p16,jmp_pin=p16,set_base=p16,freq=125_000_000)
        sm0.active(1)
        print(0xffffffff-sm0.get())
        utime.sleep_ms(100)
except KeyboardInterrupt:
        pass
    

User avatar
scruss
Posts: 4015
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: is it possible to use pico pins for detect contact fingers ?

Fri Apr 23, 2021 7:02 pm

This looks like the same technique as is employed on STM32 with the ADCTouchSensorSTM library. But using direct-touch on the Pico's pins themselves risks zapping them on a dry static-filled day.

Maybe a MPR121 sensor or similar might be less risky.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

danjperron
Posts: 3747
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: is it possible to use pico pins for detect contact fingers ?

Fri Apr 23, 2021 7:37 pm

This looks like the same technique as is employed on STM32 with the ADCTouchSensorSTM library. But using direct-touch on the Pico's pins themselves risks zapping them on a dry static-filled day.
Of course normally you add a resistor in series. 4K7 should do. I'm used to Microchip which are really well protected. But with the Pin using the pull down mode the risk is minimized.

Looking at the reference manual I found that the PIOs have ESD diode protection. (page 571)
And got some ESD compliant performance. (page 624). Are good are they??

User avatar
jbeale
Posts: 3855
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: is it possible to use pico pins for detect contact fingers ?

Sun Apr 25, 2021 6:14 am

When it got unusually dry here I walked across the floor and pulled a big loud spark from a Pico board when I touched it, without affecting it so far as I know. Then it happened again later, but definitely wouldn't want to make a habit of that.

VincentARM
Posts: 15
Joined: Sat Feb 06, 2021 8:00 pm

Re: is it possible to use pico pins for detect contact fingers ?

Sun Apr 25, 2021 1:59 pm

Hello.
Thank you for your answers.
I will write a program based on these elements.

Return to “General”