ESP32 touch false positve detection

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
ingoiot
Normal user
Posts: 83
Joined: 15 Aug 2019, 22:09

ESP32 touch false positve detection

#1 Post by ingoiot » 06 Mar 2021, 20:29

my ESP frequently triggers the touch event even if its not touched.

like 2828368: EVENT: touch#Touch=76.00
even if my trigger level is set to 50.

it seems always to happen after the
2791957: WD : Uptime 47 ConnectFailures 0 FreeMem 200912 WiFiStatus WL_CONNECTED ESPeasy internal wifi status: Conn. IP Init
Event.
Also there is no duration event in the logs when it happens automatically - when i touch it, the duration event is present.

Code: Select all

2791957: WD   : Uptime 47 ConnectFailures 0 FreeMem 200912 WiFiStatus WL_CONNECTED ESPeasy internal wifi status: Conn. IP Init
2806398: EVENT: Clock#Time=Sat,19:14
2821954: WD   : Uptime 47 ConnectFailures 0 FreeMem 200884 WiFiStatus WL_CONNECTED ESPeasy internal wifi status: Conn. IP Init
2828277: Touch : ADC2 ch4 (T4): 76
2828368: EVENT: touch#Touch=76.00
2828375: ACT  : servo,1,17,1
2828379: Servo : GPIO 17 Servo set to 1
2828382: ACT  : timerSet,1,4
2832385: EVENT: Rules#Timer=1,1
2832403: ACT  : servo,1,17,70
2832406: Servo : GPIO 17 Servo set to 70
2832410: ACT  : timerSet,2,4
2836432: EVENT: Rules#Timer=2,1
2836457: ACT  : servo,1,17,9000
2836460: Servo : GPIO 17 Servo detached
2841978: Touch : ADC2 ch4 (T4): 33
2842069: EVENT: touch#Touch=33.00
2842076: ACT  : servo,1,17,1
2842079: Servo : GPIO 17 Servo set to 1
2842083: ACT  : timerSet,1,4
2842571: EVENT: touch#Duration=607
2846086: EVENT: Rules#Timer=1,1
2846102: ACT  : servo,1,17,70
2846105: Servo : GPIO 17 Servo set to 70
2846108: ACT  : timerSet,2,4
2850114: EVENT: Rules#Timer=2,1
2850139: ACT  : servo,1,17,9000
2850142: Servo : GPIO 17 Servo detached
2851957: WD   : Uptime 48 ConnectFailures 0 FreeMem 200728 WiFiStatus WL_CONNECTED ESPeasy internal wifi status: Conn. IP Init


2926399: EVENT: Clock#Time=Sat,19:16
2941955: WD   : Uptime 49 ConnectFailures 0 FreeMem 200648 WiFiStatus WL_CONNECTED ESPeasy internal wifi status: Conn. IP Init
2961973: Touch : ADC2 ch4 (T4): 76
2962070: EVENT: touch#Touch=76.00
2962077: ACT  : servo,1,17,1
2962080: Servo : GPIO 17 Servo set to 1
2962084: ACT  : timerSet,1,4
2966088: EVENT: Rules#Timer=1,1
2966104: ACT  : servo,1,17,70
2966107: Servo : GPIO 17 Servo set to 70
2966110: ACT  : timerSet,2,4

User avatar
Ath
Normal user
Posts: 3482
Joined: 10 Jun 2018, 12:06
Location: NL

Re: ESP32 touch false positve detection

#2 Post by Ath » 06 Mar 2021, 20:49

How have you wired your touch contact? the wire should be as short as possible.

The Threshold is normally the minimum value that has to be reached before the event is triggered. As 76 is over 50, it should be triggered... but I haven't looked at the code or tried such touch sensor, so maybe I shouldn't comment...
/Ton (PayPal.me)

TD-er
Core team member
Posts: 8738
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32 touch false positve detection

#3 Post by TD-er » 07 Mar 2021, 12:49

The ESP32 touch plugin is more like an analog measurement.
It also allows to set a proper threshold for touches as it may differ per setup what is a good minimum.
The touch sensing works by considering the touch pin as a capacitor which is charged and discharged.
By pressing your finger on the pad (or even very close to allow for some isolation like an enclosure) you affect the measured capacity.
What determines the measured capacity is the amount of surface (of your finger) you place on the pad and the distance to it.
So pressing harder may flatten your finger and thus increase the surface on a larger pad, and/or it may bring the tissue that's affecting the capacitance closer to the pad.

I hope this makes it more clear what may cause the capacity change and more importantly to make it clear why you need to have to calibrate each touch pad for your purpose.

My advice is to calibrate the value to such a minimal value that accidental touches will be ignored and that you may need to press a bit more firmly.
N.B. this may also differ per person as someone with dry hands, or callus ("eelt" in Dutch) may cause a different change in capacity compared to someone with moisturized hands. Also the body size of the person may have an effect.

ingoiot
Normal user
Posts: 83
Joined: 15 Aug 2019, 22:09

Re: ESP32 touch false positve detection

#4 Post by ingoiot » 07 Mar 2021, 14:16

i tried to find a good value.

but why does the esp start an event when the value is over my setvalue like in:

Code: Select all

2828368: EVENT: touch#Touch=76.00
2828375: ACT  : servo,1,17,1
thats over the set limit of 50.

also the duration event is missing when its triggered randomly like this:

Code: Select all

2941955: WD   : Uptime 49 ConnectFailures 0 FreeMem 200648 WiFiStatus WL_CONNECTED ESPeasy internal wifi status: Conn. IP Init
2961973: Touch : ADC2 ch4 (T4): 76
2962070: EVENT: touch#Touch=76.00

User avatar
Ath
Normal user
Posts: 3482
Joined: 10 Jun 2018, 12:06
Location: NL

Re: ESP32 touch false positve detection

#5 Post by Ath » 07 Mar 2021, 14:29

You could try a touch pin that's on ADC1, I think ESP32 WiFi is interfering with ADC2.
/Ton (PayPal.me)

TD-er
Core team member
Posts: 8738
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32 touch false positve detection

#6 Post by TD-er » 07 Mar 2021, 15:44

Yep, forgot to mention it, you should only use pins that are connected to ADC1.

ingoiot
Normal user
Posts: 83
Joined: 15 Aug 2019, 22:09

Re: ESP32 touch false positve detection

#7 Post by ingoiot » 07 Mar 2021, 21:31

i´ve quite some problems to get rid of the false positives.

on adc1 it initially didn't work at all. seems like touch 8 and 9 are reversed.

maybe it has something to do with this:

Image


https://ibb.co/qD5my9W
esp.png
esp.png (209.01 KiB) Viewed 9074 times

TD-er
Core team member
Posts: 8738
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32 touch false positve detection

#8 Post by TD-er » 07 Mar 2021, 21:47

Image
The pin count is different here as it is referring to the WROOM32 module and not a NodeMCU-like layout.
But still the schematic does seem to agree with your screenshot.

This is the source code in ESPEasy to define the relation between GPIO pins, ADC, ADC channel and touch pin:

Code: Select all

// Get ADC related info for a given GPIO pin
// @param gpio_pin   GPIO pin number
// @param adc        Number of ADC unit (0 == Hall effect)
// @param ch         Channel number on ADC unit
// @param t          index of touch pad ID
bool getADC_gpio_info(int gpio_pin, int& adc, int& ch, int& t)
{
  t = -1;

  switch (gpio_pin) {
    case -1: adc = 0; break; // Hall effect Sensor
    case 36: adc = 1; ch = 0; break;
    case 37: adc = 1; ch = 1; break;
    case 38: adc = 1; ch = 2; break;
    case 39: adc = 1; ch = 3; break;
    case 32: adc = 1; ch = 4; t = 9; break;
    case 33: adc = 1; ch = 5; t = 8; break;
    case 34: adc = 1; ch = 6; break;
    case 35: adc = 1; ch = 7; break;
    case 4:  adc = 2; ch = 0; t = 0; break;
    case 0:  adc = 2; ch = 1; t = 1; break;
    case 2:  adc = 2; ch = 2; t = 2; break;
    case 15: adc = 2; ch = 3; t = 3; break;
    case 13: adc = 2; ch = 4; t = 4; break;
    case 12: adc = 2; ch = 5; t = 5; break;
    case 14: adc = 2; ch = 6; t = 6; break;
    case 27: adc = 2; ch = 7; t = 7; break;
    case 25: adc = 2; ch = 8; break;
    case 26: adc = 2; ch = 9; break;
    default:
      return false;
  }
  return true;
}
GPIO32 does look like it is set to Touch9
GPIO33 to Touch8
Please let me know if you found a bug in this list in the source code.

ingoiot
Normal user
Posts: 83
Joined: 15 Aug 2019, 22:09

Re: ESP32 touch false positve detection

#9 Post by ingoiot » 07 Mar 2021, 22:21

hm, seems like the code is ok, but when i touch on the board direct on the castelated edge
touch 9 an 8 are reversed.

i configured T9 but have to touch T8.

dont know if this my board, but it looks like an original wroom -32 like in your pic.

edit:
looks like someone else had a similar problem
https://github.com/espressif/arduino-esp32/issues/3575
esp3.png
esp3.png (9.09 KiB) Viewed 9065 times
esp2.png
esp2.png (34 KiB) Viewed 9065 times

TD-er
Core team member
Posts: 8738
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32 touch false positve detection

#10 Post by TD-er » 07 Mar 2021, 22:26

It is still possible the silkscreen on your board is incorrect.

You can also try to use it as a switch output or just interact with it via GPIO commands to see what pin goes high if you set GPIO-32 to high.

ingoiot
Normal user
Posts: 83
Joined: 15 Aug 2019, 22:09

Re: ESP32 touch false positve detection

#11 Post by ingoiot » 07 Mar 2021, 22:33

the web gpio commands are correct.

its not likely the silkscreen because i touched the castelate edges of the chip - so it seems to be the chip itself.
(or the docs)

ingoiot
Normal user
Posts: 83
Joined: 15 Aug 2019, 22:09

Re: ESP32 touch false positve detection

#12 Post by ingoiot » 09 Mar 2021, 11:56

is there an option to debounce the touch trigger?
no matter the threshold, there are sometimes spikes that are way to high

TD-er
Core team member
Posts: 8738
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32 touch false positve detection

#13 Post by TD-er » 09 Mar 2021, 13:13

Not yet, but I guess that would be a very useful feature for the touch plugin.

Just made an issue for it: https://github.com/letscontrolit/ESPEasy/issues/3539

ingoiot
Normal user
Posts: 83
Joined: 15 Aug 2019, 22:09

Re: ESP32 touch false positve detection

#14 Post by ingoiot » 09 Mar 2021, 14:53

tnx,
sounds great
Attachments
2ndWorking.tar.gz
(5.02 KiB) Downloaded 203 times
Last edited by ingoiot on 11 Mar 2021, 20:08, edited 1 time in total.

ingoiot
Normal user
Posts: 83
Joined: 15 Aug 2019, 22:09

Re: ESP32 touch false positve detection

#15 Post by ingoiot » 10 Mar 2021, 15:11

i tried software debounce in rules, but there are occasionally still false positives.
am i doing it the right way, or is the code faulty?

Code: Select all

on System#Boot do
  let,1,0
endon

// With debouncing in the script
on touch#Touch do
  if %v1%=0
    let,1,1
    endif
    timerSet_ms,1,1200 // Debouncing timer
  endif
endon

on Rules#Timer=1 do
  if %v1%=1
     servo,1,17,1   // servo Pos1
  timerSet,2,4      //Set Timer 2 for the next event in 4seconds
    endif
    let,1,0
  endif
endon

On Rules#Timer=2 do  //When Timer2 expires, do
   servo,1,17,70   // servo Pos2
   timerSet,3,4      //Set Timer 3 for the next event in 4seconds
endon 

On Rules#Timer=3 do  //When Timer 3 expires, do
   servo,1,17,9000   // servo off

TD-er
Core team member
Posts: 8738
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32 touch false positve detection

#16 Post by TD-er » 10 Mar 2021, 15:19

Just looking at the first block, I do see an error in the nr of endif statements:

Code: Select all

// With debouncing in the script
on touch#Touch do
  if %v1%=0
    let,1,1
    endif    // <<<<--- This one is not needed
    timerSet_ms,1,1200 // Debouncing timer
  endif
endon
The other blocks also have too many "endif" statements.

ingoiot
Normal user
Posts: 83
Joined: 15 Aug 2019, 22:09

Re: ESP32 touch false positve detection

#17 Post by ingoiot » 10 Mar 2021, 19:08

i changed it to:

Code: Select all

on System#Boot do

  let,1,0
endon


// With debouncing in the script:

on touch#Touch do

  if %v1%=0
    let,1,1
    timerSet_ms,1,1200 // Debouncing timer  
  endif
endon


on Rules#Timer=1 do

  if %v1%=1
     servo,1,17,1   // servo Pos1
     timerSet,2,4      //Set Timer 2 for the next event in 4seconds
  endif
    let,1,0
endon


On Rules#Timer=2 do  //When Timer2 expires, do

   servo,1,17,70   // servo Pos2
   timerSet,3,4      //Set Timer 3 for the next event in 4seconds
endon 


On Rules#Timer=3 do  //When Timer 3 expires, do

   servo,1,17,9000   // servo off
endon
looks like deboncing doesnt work-
it still triggers , even when i touch only for a short time in the
1200 ms period.

edit changed again:

Code: Select all

on System#Boot do

  let,1,0
endon


// With debouncing in the script:

on touch#Touch do

  if %v1%=0
    let,1,1
  else
    timerSet_ms,1,1200 // Debouncing timer  
  endif
endon


on Rules#Timer=1 do

  if %v1%=1
     servo,1,17,1   // servo Pos1
     timerSet,2,4      //Set Timer 2 for the next event in 4seconds
     let,1,0
  else
  endif
endon


On Rules#Timer=2 do  //When Timer2 expires, do

   servo,1,17,70   // servo Pos2
   timerSet,3,4      //Set Timer 3 for the next event in 4seconds
endon 


On Rules#Timer=3 do  //When Timer 3 expires, do

   servo,1,17,9000   // servo off
endon

TD-er
Core team member
Posts: 8738
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32 touch false positve detection

#18 Post by TD-er » 10 Mar 2021, 21:57

I don't understand what you attempt to do with the debounce timer.
What you probably want to do is set the timer only if %v1%=0 and not in the else scope.

ingoiot
Normal user
Posts: 83
Joined: 15 Aug 2019, 22:09

Re: ESP32 touch false positve detection

#19 Post by ingoiot » 11 Mar 2021, 08:51

finally a version that seems to work:

Code: Select all

on touch#Touch do
  
  timerSet_ms,1,2200      //Set Timer 1 for the next event 
endon

on touch#Touch do
   if [Touch#touch]>50
  
      timerSet_ms,1,0     //ReSet Timer 1
endon

on Rules#Timer=1 do

  if [Touch#touch]<30
     servo,1,17,1   // servo Pos1
     timerSet,2,4      //Set Timer 2 for the next event in 4seconds
endon  

On Rules#Timer=2 do  //When Timer1 expires, do
  servo,1,17,70
  timerSet,3,4      //Set Timer 3 for the next event in 2seconds
endon  

On Rules#Timer=3 do  //When Timer3 expires, do
   servo,1,17,9000   // servo off
endon
Attachments
deviceConfig.png
deviceConfig.png (59.17 KiB) Viewed 8797 times

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 25 guests