Close
0%
0%

IO-touch: every IO pin is a capacitive sensor

Without any external components or capacitive sensor peripheral, any IO pin can serve as a capacitive sensor

Public Chat
Similar projects worth following
When we do capacitive sensing, we normally need chips with capacitive sensing peripherals, such as the ESP32, Atmel Peripheral Touch Controller (PTC), or special capacitive sensor ICs. In this project, I show that a single IO with no peripheral components, no capacitive sensing peripheral in the MCU (RP2040), and no extra capacitive sensor, you can still do capacitive sensing, and I made a simple touchpad as an example. This demonstrates that virtually any I/O pin on most microcontrollers can function as a capacitive sensor, expanding the possibilities for touch-based interfaces in embedded systems. (It does support multi-touch)


(Circle pads are analog pins and square pads are digital pins)

Here is how I implement this:

1. Analog pins

For analog pins (pins connected with internal ADC), The touchpad that connects with an analog pin forms a capacitor with the ground pour. First, the analog pin outputs a very short pulse to charge the capacitor. Then the pin turns to analog input, which has big input resistance, and the capacitor discharges slowly through this big resistance. When your finger touches the pads, the capacitance will be bigger which causes a slower discharging process (discharge slower), as shown in the image. 

By taking a measurement at a fixed time point after the pulse, we can detect the change in discharge and detect the touch. When you touch it, the reading will be higher than when the pad is empty.

2. Digital pins

The mechanism for digital pins is similar. When touching the pad, the capacitance increases, and the discharging process changes. However, digital pins are not connected with the internal ADC therefore can not measure this change by sampling the voltage at a fixed moment. The approach I'm using for digital pins is: when touching the pad, the discharge gets slower, therefore the falling edge arrives later. So I record the timestamp when the pulse outputs, and set the digital IO to input and attach to an interruption with it which is triggered by a falling edge. The interruption routine records the timestamp and calculates the time difference between the trigger time and pulse output time. The time difference with a finger touch is longer than the one without (although it's only a few microseconds, but already enough to capture). As shown in the images, when the pad is touched, the falling edge triggering time is longer. It will be better to add a filter to the data.

Platform:

- Firmware: Platformio + VScode (Arduino framework)

- Hardware: XIAO RP2040 + a milled PCB.

main.cpp

main file

cpp - 3.40 kB - 03/19/2025 at 15:33

Download

XIAO2PICO_PIN_MAP.h

pin map header

h - 300.00 bytes - 03/19/2025 at 15:33

Download

platformio.ini

Platformio configuration

ini - 707.00 bytes - 03/19/2025 at 15:33

Download

  • 1 × XIAO RP2040
  • 1 × Milled PCB

View project log

  • 1
    Calibration is needed

    before using it, the board need to be hold and calibrate for a few seconds.

View all instructions

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates