class TouchPad – touch

The ESP32 provides up to 10 capacitive sensing GPIOs, capable of detecting the capacitance difference caused by direct contact or proximity of a finger or other object.

Constructors

class TouchPad.TouchPad(Pin)

Create a TouchPad object associated with the given pin.

  • Pin - The available pins are:

Capacitive sensing signal name

ESP32 GPIO

mPython Board pin

Description

TOUCH0

GPIO4

P28/Touch_N

TOUCH1

GPIO0

P5/Button_A

Cannot be used with pin pull-up

TOUCH2

GPIO2

P11/Button_B

Cannot be used with pin pull-up

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

The ESP32 has 10 touch sensors. The mPython Board has 8 usable touch sensors, 6 of which are routed to the touch pads on the front of the board. For more information, see mPython Board pin definitions.

Example:

from machine import TouchPad, Pin

tp = TouchPad(Pin(14))

Methods

TouchPad.read()

Read the level of the TouchPad.

TouchPad.read returns a value relative to the capacitive variable. When touched, it is a small number (usually within 10); when not touched, a large number (greater than 1000) is common. However, these values are “relative” and can vary according to the board and the surroundings, so some calibration may be needed. Note that calling other non-touch pins will cause a ValueError.

TouchPad.config(value)

Set the touch threshold

  • value integer