Class TouchPad – Touch Sensor
ESP32 provides up to 10 capacitive sensing GPIOs that can detect capacitance differences caused by direct contact or proximity of a finger or other objects.
Constructors
- class TouchPad.TouchPad(Pin)
Create a TouchPad object associated with the specified pin.
Pin- Available pins:
Touch Signal Name
ESP32 GPIO
mPython Board Pin
Notes
TOUCH0
GPIO4
P28/Touch_N
TOUCH1
GPIO0
P5/Button_A
Pull-up not usable
TOUCH2
GPIO2
P11/Button_B
Pull-up not usable
TOUCH3
GPIO15
P27/Touch_O
TOUCH4
GPIO13
P26/Touch_H
TOUCH5
GPIO12
P25/Touch_T
TOUCH6
GPIO14
P24/Touch_Y
TOUCH7
GPIO27
P23/Touch_P
TOUCH8
GPIO33
P0
TOUCH9
GPIO32
P1
Note
ESP32 has 10 touch sensors. mPython Board has 8 usable touch sensors, of which 6 are routed to touch pads on the front of the board. For more information, see mPython Board Pin Definition .
Example:
from machine import TouchPad, Pin
tp = TouchPad(Pin(14))
Methods
- TouchPad.read()
Read the TouchPad level.
TouchPad.read returns a value relative to the capacitive variable. When touched, it is a small number (typically within 10); when not touched, a larger number (greater than 1000) is common. However, these values are “relative” and may vary depending on the board and surroundings, so some calibration may be needed.
Note that calling a non-touch pin will raise ValueError.
- TouchPad.config(value)
Set the touch threshold.
valueInteger