ESP32 WROOM32E touch interrupt problem

danmerkley
Posts: 4
Joined: Fri Jan 24, 2025 9:40 pm

ESP32 WROOM32E touch interrupt problem

Postby danmerkley » Tue Feb 04, 2025 4:28 pm

Having issues with touch interrupts on WROOM 32E, problem does not appear on devkit with WROOM 32D.

Using arduino ide v2.3.4 for programing, using the provided example for touch interrupt with pins T4 and T5.

Both touch pins are working and trigger interrupt when touched. However when one pin is touched twice in a row and then the other pin is touched, there is an incorrect triggering of the first pin as well. For example if pins touched are T4, T4, and then T5 (with appropriate delay) the output will be:

ESP32 Touch Interrupt Test
Touch 1 detected
Touch 1 detected
Touch 1 detected
Touch 2 detected

This problem did not occur on older esp32 modules including devkits i have with WROOM 32 and WROOM 32D modules but the issue shows up on my new custom hardware with WROOM 32E. I have tried out several boards with WROOM 32E including two brand new devkits purchased from amazon with WROOM 32E modules and the problem persists.

I also tried using the iram_attr on the interrupts and tried declaring all involved variables as volatile, static and also static volatile just to see if it had any effect and nothing changed. Baseline touchread value is approximately 50 on my board and with pin touched it is approx 15 so threshold is set to 30. Confirmed it is not a cross triggering problem as the touchread value for each pin does not vary significantly when the other pin is touched.

Not sure what is going on here as it should not be possible to flag both touch1detected and touch2detected within 300ms unless i'm missing something?

Code used:

int threshold = 30;

unsigned long lastTouch1Time = 0;
unsigned long lastTouch2Time = 0;

bool touch1detected = false;
bool touch2detected = false;

void gotTouch1() {
if (millis() - lastTouch1Time > 300) {
touch1detected = true;
lastTouch1Time = millis();
}
}

void gotTouch2() {
if (millis() - lastTouch2Time > 300) {
touch2detected = true;
lastTouch2Time = millis();
}
}

void setup() {
Serial.begin(115200);
delay(2000); // Stabilization delay
Serial.println("ESP32 Touch Interrupt Test");
touchAttachInterrupt(T4, gotTouch1, threshold);
touchAttachInterrupt(T5, gotTouch2, threshold);
}

void loop() {
if (touch1detected) {
Serial.println("Touch 1 detected");
touch1detected = false;
}
if (touch2detected) {
Serial.println("Touch 2 detected");
touch2detected = false;
}


}

Who is online

Users browsing this forum: No registered users and 8 guests