How to access ESP touch sensor properly in Arduino framework

Hello!
I am using Platformio with an ESP32 D1 MINI in Arduino framework:

[env:wemos_d1_mini32]
platform = espressif32
board = wemos_d1_mini32
framework = arduino
lib_deps =
   janelia-arduino/TMC2209@^9.0.7
   adafruit/Adafruit GFX Library@^1.11.9
   adafruit/Adafruit SSD1306@^2.5.9

Works beautifully so far :slight_smile:

I build a capacitive fluid level sensor using the touch API. Espressif provides a pretty good description how that capacity measurement works incl. API:
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/touch_pad.html

This in general works good for, let’s say human body touch detection. However I want to modify the voltage thresholds, measurement time and filter settings to tune the measurement quality of my design.

However Arduino framework encapsulates most of that:
https://espressif-docs.readthedocs-hosted.com/projects/arduino-esp32/en/latest/api/touch.html

If I, for example, try to call “touch_pad_get_voltage()” I get an error:
src/main.cpp:60:2: error: ‘touch_pad_get_voltage’ was not declared in this scope
(Yes I know I don’t call the function correctly with pointers etc, but it should complain then about the arguments and not say “not found”…)

I tried to locate the library source code in the Arduino framework, but only found layers of layers of .h files, but wasn’t able to figure out how to access the “lower levels”. Well there are actually comments in the header files not to do so, but what shall I do? Quite confusing to me and clearly out of my C++ capabilities :frowning:

So I guess my question sums up to: How do I bypass the Arduino HAL and access the ESP HW directly from main.cpp? Is there simply an “#include…” missing to make the EspressIF API available on top level?? Also EspressIF uses Python, when I understand correctly? I have no idea how that actually relates, but that may also be a different story… :wink:

Anybody able to help?

Best regards
Daniel

But those docs don’t tell you to call into touch_pad_get_voltage()? Please try a regular example sketch first:

https://github.com/espressif/arduino-esp32/blob/2.0.14/libraries/ESP32/examples/Touch/TouchButton/TouchButton.ino

Or

https://github.com/espressif/arduino-esp32/blob/2.0.14/libraries/ESP32/examples/Touch/TouchRead/TouchRead.ino

To get access to these functions, you must include the corresponding header file as described in the section API reference / Header File:

#include "driver/touch_sensor.h"

Hello!

These examples work fine, also using the Arduino API to the touch sensor works. My problem is, that the Arduino API does not provide full access to the original EpsressIf API below. There is e.g no fuction to change the voltage thresholds or the measurement time…So i am trying to bypass the Arduino API somehow…

Best regards
Daniel

Threshhold is an argument inside

And measuring time is changeable with

because

Ahhh okay. Now it works!

Thanks for the answer and sorry for the obviously stupid question then.

I thought these header files are all included in “Arduino.h” anyway.

Best regards
Daniel

Thanks for the answer. The only issue was indeed, that I didn’t include the necessaey header as @sivar2311 mentioned.

Best regards
Daniel