Having issues with touch interrupts on WROOM 32E, problem does not appear on devkit with WROOM 32D.
Using arduino ide 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 a devkit i have with WROOM 32D but the issue shows up on my new hardware with WROOM 32E.
Code used:
/*
This is an example how to use Touch Intrrerupts
The bigger the threshold, the more sensible is the touch
*/
#if CONFIG_IDF_TARGET_ESP32P4
int threshold = 0; // when 0 is used, the benchmarked value will be used
#else
int threshold = 29;
#endif
bool touch1detected = false;
bool touch2detected = false;
void gotTouch1() {
touch1detected = true;
}
void gotTouch2() {
touch2detected = true;
}
void setup() {
Serial.begin(115200);
delay(1000); // give me time to bring up serial monitor
Serial.println("ESP32 Touch Interrupt Test");
touchAttachInterrupt(T4, gotTouch1, threshold);
touchAttachInterrupt(T5, gotTouch2, threshold);
}
void loop() {
if (touch1detected) {
Serial.println("Touch 1 detected");
delay(300);
touch1detected = false;
}
if (touch2detected) {
Serial.println("Touch 2 detected");
delay(300);
touch2detected = false;
}
}
ESP32 WROOM32E touch interrupt issue
-
- Posts: 23
- Joined: Sat Jan 18, 2025 2:31 pm
Re: ESP32 WROOM32E touch interrupt issue
A lower threshold makes the pin more sensitive. Try increasing the value. To avoid cross-triggering or false triggers, you can add a debounce mechanism:
Code: Select all
int threshold = 50;
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;
}
// Raw value monitoring (for debugging)
Serial.print("T4: ");
Serial.print(touchRead(T4));
Serial.print(" T5: ");
Serial.println(touchRead(T5));
delay(300);
}
-
- Posts: 4
- Joined: Fri Jan 24, 2025 9:40 pm
Re: ESP32 WROOM32E touch interrupt issue
Hi, thanks for getting back to me so quickly.
Sorry, i should have been more specific in my first post... the problem was initially discovered in a different piece of code which had debouncing (although a different debounce implementation) and also used pins T8 and T9 as well and the problem was exactly the same. I used this simpler example code because it reproduced the same problem and was easier to follow. 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.
I tried the code you posted (had to change the threshold to 30 as the baseline reading is approximately 50 on my hardware) and the problem still persists. After either pin is touched twice, touching the other pin will trigger both somehow and print out Touch1detected and Touch2detected. Problem does not occur on WROOM32D, only on WROOM32E, I have tried it on two different boards with 32E just to confirm it wasn't a bad chip. 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?
Sorry, i should have been more specific in my first post... the problem was initially discovered in a different piece of code which had debouncing (although a different debounce implementation) and also used pins T8 and T9 as well and the problem was exactly the same. I used this simpler example code because it reproduced the same problem and was easier to follow. 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.
I tried the code you posted (had to change the threshold to 30 as the baseline reading is approximately 50 on my hardware) and the problem still persists. After either pin is touched twice, touching the other pin will trigger both somehow and print out Touch1detected and Touch2detected. Problem does not occur on WROOM32D, only on WROOM32E, I have tried it on two different boards with 32E just to confirm it wasn't a bad chip. 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?
-
- Posts: 4
- Joined: Fri Jan 24, 2025 9:40 pm
Re: ESP32 WROOM32E touch interrupt issue
I managed to obtain some esp32 devkits with WROOM 32E modules to try to see if the problem could relate to something else on my custom boards and no luck. The problem still persists, using a FREENOVE ES32 WROOM devkit purchased off amazon and still the same problem.
Has anyone else had any issues with touch interrupts on the WROOM 32E?
Has anyone else had any issues with touch interrupts on the WROOM 32E?
Who is online
Users browsing this forum: No registered users and 32 guests