touchRead() causes several problems (tested on ESP32-S2)
Author: purehunter1Created Jan 12, 2026Updated Sep 23, 2026
LabelsStatus: Awaiting triage
Board
LOLIN S2 Mini V1.0.0
Device Description
Plain board. No external Components to reproduce
Hardware Configuration
GPIO 5 = touch input
Version
v3.3.5
Type
Bug
IDE Name
Arduino 2.3.6
Operating System
Win11 pro
Flash frequency
?
PSRAM enabled
yes
Upload speed
different
Description
Obvious problem was: after the program was uploaded once, it ran, but standard updates via Arduino IDE upload-button were impossible then. Program uploads were possible, only if the ESP was set to DFU mode manually (GPIO0). Long investigation showed, that the touchRead() function caused (at least) 2 problems:
- The ESP does not initialize the USB correctly in the DFU mode, if the Arduino IDE switches from CDC to DFU after the function touchRead() was called in a program (Windows does not recognize the module and does not assign a COM port to it)
- the touchRead() function returns an irregular value upon the first call in the program (returns 4194303 = 2^22 -1)
The misbehaviour did not exist in Board Manager Version 3.1.3 but it exists latest since Version 3.3.1 and is also in 3.3.3 and 3.3.5
Sketch
void setup() {
Serial.begin(115200);
while(!Serial);
Serial.println();
unsigned int touch = 0;
// GPIO can be any possible Touch pin
touch = touchRead(GPIO_NUM_5); // first touchRead() in program always returns 4194303 = 2^22 -1 | and causes the ESP to initialize the USB incorrectly after the switch from CDC to DFU by the Arduino IDE
Serial.println(touch);
touch = touchRead(GPIO_NUM_5); // immediate additional call returns still 4194303
Serial.println(touch);
delay(10);
touch = touchRead(GPIO_NUM_5); // later calls of touchRead() return plausible values
Serial.println(touch);
}
void loop() {
// put your main code here, to run repeatedly:
}Debug Message
16:35:19.633 ->
16:35:19.633 -> 4194303
16:35:19.633 -> 4194303
16:35:19.633 -> 8975Other Steps to Reproduce
touchRead() works correctly in Board Manager 3.1.3
I have checked existing issues, online documentation and the Troubleshooting Guide
- I confirm I have checked existing issues, online documentation and Troubleshooting guide.
Source: espressif/arduino-esp32