Register / Login  |  Desktop view  |  Jump to bottom of page

tcMenu Arduinio library » ESP32 touch sensor.

Author: ScubaSteve
18/08/2021 15:56:00
Hi Dave!

I've been struggling to find good quality binary encoders, and have settled in on the ESP32 as my primary platform for projects. Since there's touch support in both the hardware and tcMenu, I figured I'd give it a whirl.

I'm struggling. I've been through all of the permutations in Designer. Nothing works. No errors, but no sensing. I've tried both interrupt and loop. Nothing.

On a lark, I added this to my loop():
Serial.print(touchRead(4)); Serial.print(" ");
Serial.print(touchRead(13)); Serial.print(" ");
Serial.print(touchRead(32)); Serial.print(" ");
Serial.println();

... when that code is present, I see ~200 with no touch, < 100 with touch.... I also see random touches (this seems to be an ADC issue) ... and the tcMenu cursor comes to life (and sometimes moves on its own).

I've got sensors on GPIOs 4, 13, 32 and specified 9, 4, 0 in the Designer.

I've walked through the code and would like to see if I can enable a debug mode. I see lots of info getting passed over to "serdebugF2", but it doesn't appear to be enabled.

Can you point me in the right direction?

Author: davetcc
18/08/2021 18:43:26
You can define the threshold and also the parameters as per the esp manual for the esp touch pin plugin. It uses exactly the same values.

IO_LOGGING_DEBUG

Is the flag.

You could define it with plaformIo using a build flag.

On Arduino just uncomment the define in src/IoLogging.h

Author: ScubaSteve
18/08/2021 22:43:21
Hi Dave.

I'm seeing this already enabled:

// When line below commented out - no logging, when un-commented - logging. You can also define this macro in your build system
#define IO_LOGGING_DEBUG

// END user adjustable section.

... but I've never seen any debug? I'm assuming it goes to serial by default? I'm doing a Serial.begin() in my code -- could that be interfering?

Author: ScubaSteve
19/08/2021 02:44:43
Ok, this is interesting. It seems, if I wait long enough (many minutes) ... the touchpad springs to life. Prior to that, it will sit there and say intCount = 0.... and then, wham. It comes to life and works reliably.

I've tested this on a few ESPs. They all act the same way.

in ESP32TouchKeysAbstraction::readValue, I added some debug...

22:43:50.562 -> 504129:TouchKeysAbstraction::readValue: 1546
22:43:50.562 -> 504153:TouchKeysAbstraction::readValue: 5
22:43:50.562 -> 504153:TouchKeysAbstraction::readValue: 5
22:43:50.562 -> 504153:TouchKeysAbstraction::readValue: 1362
22:43:50.562 -> 504153:TouchKeysAbstraction::readValue: 1546
22:43:50.595 -> 504177:TouchKeysAbstraction::readValue: 5
22:43:50.595 -> 504177:TouchKeysAbstraction::readValue: 5
22:43:50.595 -> 504177:TouchKeysAbstraction::readValue: 1363
22:43:50.595 -> 504177:TouchKeysAbstraction::readValue: 1557
22:43:50.633 -> 504201:TouchKeysAbstraction::readValue: 220

Any ideas why the pad would randomly spring to life?

Author: ScubaSteve
19/08/2021 03:29:50
So it turns out that debug I added ... that shows the values on the pins... was extremely helpful.

Best I can tell, something randomly happens which causes all of the pins to return different values. I was hovering in the 600s with no touch, then it would bounce to 1600s with no touch. It's not an electrical issue -- I've replicated it with nothing connected. I observed the numbers briefly with a small piece of standalone test code and ran with it, unaware there was more of a range than observed.

This is my current theory. I'll play around and overthink and see if I can come up with something else..

Thank you for everything you do!

Steve


uint8_t ESP32TouchKeysAbstraction::readValue(pinid_t pin) {
if(!allOk) return 0;

ensureInterruptRegistered();

uint16_t val;
touch_pad_read_filtered((touch_pad_t)pin, &val);
+ serdebugF3("TouchKeysAbstraction::readValue: ", pin, val);
return val <= pinThreshold;
}

Author: davetcc
19/08/2021 08:00:33
For the logging I would ensure that the library you’re editing is the one that’s in use. Calling Serial.begin is needed for it to work.

In terms of the behaviour I would read the esp guide around touch pin setup. There are some requirements, I set up a test board with small coin sized metal pieces soldered to a short wire. There may even be a photo of it somewhere here. The simhub connector example uses esp touch.

I’ll try and look through the code for that later or tomorrow and see if there’s anything else I can remember.




Register / Login  |  Desktop view  |  Jump to top of page