1703 views|3 replies

1w

Posts

25

Resources
The OP
 

【RPi PICO】Touch Sensing [Copy link]

 This post was last edited by dcexpert on 2021-2-19 08:40

From: https://forum.micropython.org/viewtopic.php?t=9829&p=55021#p55021

Ported from the arduino library, use two GPIOs, one as a touch input, and the other is connected to the input using a 1 megohm resistor to judge the touch state by the charging time.

# touchA.py by CWE

from machine import *
from utime import *

led= Pin(25, Pin.OUT)
led.value(0)

send= Pin(16, Pin.OUT) # via 1meg resistor connected to touch pad
send.value(0)

t1= Pin(17,Pin.IN) # directly connected to touch pad
sleep(1)

trigLevel= 0

def getT1(): # Sensor routine gives back a number
    start=0
    end=0
    start= ticks_us()
    send.value(1)
    while t1.value()<1:
        pass
    end= ticks_us()
    send.value(0)
    return(end-start)

def calibT1():
    global trigLevel
    for i in range(0,50):
        trigLevel= max(getT1()*1.3 , trigLevel) # factor 1.3 perhaps needs tuning
        print(".",end="")
        sleep(0.05)

print("Calibrating....")
calibT1()
print("TrigLevel: ", trigLevel)

actT1= False

while True:
    lastT1= actT1
    t1Val= getT1()
    
    actT1= t1Val > trigLevel
    if actT1 and lastT1: # switch only, if two consecutive same levels detected
        led.value(1)
    elif actT1==False and lastT1==False:
        led.value(0)
    print(trigLevel,t1Val) # use with plotter of thonny
    sleep(0.05)
    

Latest reply

Similar to this principle? ? https://tech.hqew.com/fangan_2052192   Details Published on 2021-2-19 11:23
 
 

2940

Posts

0

Resources
2
 

Is there a circuit diagram? I don't understand the principle.

 
 
 

1w

Posts

25

Resources
3
 
tagetage posted on 2021-2-18 20:17 Is there a circuit diagram? I don't understand the principle.

I remember that MSP430 used this method before, that is, after touching, the size of the coupling capacitor on the pin will change, and the coupling capacitor of another pin will be charged through one pin. The charging time will be different for different capacitance sizes, and the touch state can be judged by the charging time.

 
 
 

2940

Posts

0

Resources
4
 

Similar to this principle? ? https://tech.hqew.com/fangan_2052192

 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list