RP.PIO.Touch_Sense

Entities

Simple Types

Tagged Types

Subprograms

Description

Capacitive touch sensing is based on change in capacitance typically introduced by the contact or proximity of the user finger(s) with a pin.

Using PIO, any RP2040 pin connected to ground (or 3.3v) through a large resistor (e.g. 1Mohm) can be a capacitive touch sensor.

Two measure modes are available: Charge or Discharge

In Discharge mode (Default): Connect the pin to ground through a large resistor. The PIO program will charge the internal pin capacitor by configuring the pin as an output and set it high for a few microseconds. And then set the pin as an input and count how many cycles it takes for the capacitor to discharge through the resistor.

In Charge mode: Connect the pin to 3.3v through a large resistor. The PIO program will discharge the internal pin capacitor by configuring the pin as an output and set it low for a few microseconds. And then set the pin as an input and count how many cycles it takes for the capacitor to charge through the resistor.

If users touch the pin, the capacitance will increase and therefore the number of cycles it takes to discharge/charge will increase as well.

Initialize

procedure Initialize (This       : in out Touch_Sensor;
                      ASM_Offset :        PIO_Address := 0;
                      Max_Count  :        HAL.UInt32  := 10_000;
                      Mode       :        Touch_Mode  := Discharge)
Parameters
This
ASM_Offset
Max_Count
Mode

Initialized

function Initialized (This : Touch_Sensor) return Boolean
Parameters
This
Return Value

Raw_Value

function Raw_Value (This : Touch_Sensor) return HAL.UInt32
Parameters
This
Return Value

Set_Threshold

procedure Set_Threshold (This      : in out Touch_Sensor;
                         Threshold :        HAL.UInt32)
Parameters
This
Threshold

Threshold

function Threshold (This : Touch_Sensor) return HAL.UInt32
Parameters
This
Return Value

Touch

function Touch (This : Touch_Sensor) return Boolean
Parameters
This
Return Value

Touch_Mode

type Touch_Mode is (Discharge, Charge);

Measure either capacitive discharge time (Pin pulled down) or capacitive charge time (pin pulled up).

Enumeration Literal
Discharge
Charge

Touch_Sensor

type Touch_Sensor
  (Pin : not null access RP.GPIO.GPIO_Point;
   PIO : PIO_Device;
   SM  : PIO_SM)
is tagged private;
Record fields
Pin
PIO
SM