How to access ESP touch sensor properly in Arduino framework

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

platform = espressif32
board = wemos_d1_mini32
framework = arduino
lib_deps =
   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:

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:

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

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


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"


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

Threshhold is an argument inside

And measuring time is changeable with


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

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

Best regards