Esp 32 dev kit v1 touch sensor interrupt usage issue

Hi All,

I am working on a project in which I am using NodeMCU-ESP32 DEVKITV1. I am trying to use capacitive touch pins to perform a particular task when the value is below the threshold but without touch, the touch pin produces values that are below the threshold creating the problem. I have gone through the documentation and found that esp 32 does have this problem. To overcome this issue, people suggested using ISR, but I am a newbie and unable to understand the underlying concept. Can someone guide me on this?
Following is the script.


#include <BleKeyboard.h>
BleKeyboard bleKeyboard;

int touch_up;
int touch_down;

void setup() {
  Serial.begin(115200);
  bleKeyboard.begin();
}

void loop() {
   touch_up = touchRead(27);
   touch_down=touchRead(12);
   
  if (touch_up < 25)
  {
    Serial.println(touchRead(27));
    bleKeyboard.write(KEY_UP_ARROW);
    delay(100);
    bleKeyboard.releaseAll();
    }
  if (touch_down < 25)
  {
    Serial.println(touchRead(12));
    bleKeyboard.write(KEY_DOWN_ARROW);
    delay(100);
    bleKeyboard.releaseAll();
    }
  delay(100);
}

Change the threshold ?

What are you using as capacitive sensing pads ?

Post the entire code in code tags, a schematic of the wiring, and a pic of your project.

Actually, I have changed the threshold, but irrespective of the threshold, the value gets changed for a fraction of time as mentioned here. This causes the if block to be executed.

I have pasted the complete code. Moreover, I am just using pin 27 and pin 12 of the controller which I touch to execute the if block. Nothing extra is added to the hardware.

The code that you posted does not compile because touch_up and touch_down are not declared

@UKHeliBob My bad.

#include <BleKeyboard.h>
BleKeyboard bleKeyboard;

int touch_up;
int touch_down;

void setup() {
  Serial.begin(115200);
  bleKeyboard.begin();
}

void loop() {
   touch_up = touchRead(27);
   touch_down=touchRead(12);
   
  if (touch_up < 25)
  {
    Serial.println(touchRead(27));
    bleKeyboard.write(KEY_UP_ARROW);
    delay(100);
    bleKeyboard.releaseAll();
    }
  if (touch_down < 25)
  {
    Serial.println(touchRead(12));
    bleKeyboard.write(KEY_DOWN_ARROW);
    delay(100);
    bleKeyboard.releaseAll();
    }
  delay(100);
}

I am also facing the same issue.
This is causing a lot of false triggers and making the touch input feature practically useless.
Please tell me a solution if you have found out.

Using the touchRead function with an ESP32, I've found issues with noise / 'glitching' that can cause issues. I wrote a little example that shows how to de-glitch the signal and posted it on GitHub: GitHub - digamesystems/esp32_capacitive_touch_test: Experimenting with the Capacitive Touch Inputs on the ESP32

Hope this helps.

Regards,

John

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.