Skip to content

Using the capacitive touch sensor with Button2 #95

Description

@nielsnl68

Hi all,

I'm trying to figure out a good solution using the ESP32S3 capacitive touch sensor solution using the touchRead() solution. But i dont get it stable, enough to use it all the time.

The issue is that from time to time the value pops above the trashhold value and triggers the button while not being touched.

this is what i have for now:

#include "Button2.h"

#define TOUCH_PIN 1
uint32_t current_trashhold = 0;

uint8_t btn_state_handler() {
  auto touch = touchRead(TOUCH_PIN);
  return touch > current_trashhold? LOW : HIGH;
}

void Setup() {
  ...

  # weakup touch sensor 
  touch_value_t touch = 400000;
  while (touch >= 400000) {
    touch = touchRead(TOUCH_PIN);
  }

  # calibrate the trashhold value
  if (current_trashhold == 0) {
    for (uint8_t x=0; x < 10; x++) {
      touch = touchRead(TOUCH_PIN);
      if (touch > current_trashhold) {
        current_trashhold = touch;
      }
      delay(25);
    }
    current_trashhold += 1000;
  }

  btn1.setDebounceTime(60);
  btn1.setButtonStateFunction(btn_state_handler);
  btn1.begin(BTN_VIRTUAL_PIN);
  
  ...
}

Maybe you could give some insides of your own testing, with the capacitive touch sensors.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions