Using the esp32 s2 touch sensor

Hi, I have wemos esp32 board, the “lolin_s2_mini” and I have it set up so that a switch on it works, but when I try to connect the touch sensors, I get errors when compiling. Here is the log, has anyone successfully used an esp32s2 mini with touch?

Here is the error log.

INFO Reading configuration /config/esphome/switch.yaml...
WARNING The selected Arduino framework version is not the recommended one. If there are connectivity or build issues please remove the manual version.
WARNING The selected Arduino framework version is not the recommended one. If there are connectivity or build issues please remove the manual version.
INFO Generating C++ source...
INFO Compiling app...
Processing switch (board: lolin_s2_mini; framework: arduino; platform: platformio/espressif32 @ 5.2.0)
--------------------------------------------------------------------------------
HARDWARE: ESP32S2 240MHz, 320KB RAM, 4MB Flash
 - toolchain-riscv32-esp @ 8.4.0+2021r2-patch3 
 - toolchain-xtensa-esp32s2 @ 8.4.0+2021r2-patch3
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
Dependency Graph
|-- WiFi @ 2.0.0
|-- ESPmDNS @ 2.0.0
|-- Update @ 2.0.0
|-- noise-c @ 0.1.4
|   |-- libsodium @ 1.10018.1
Compiling /data/switch/.pioenvs/switch/src/esphome/components/api/api_connection.cpp.o
Compiling /data/switch/.pioenvs/switch/src/esphome/components/api/api_frame_helper.cpp.o
Compiling /data/switch/.pioenvs/switch/src/esphome/components/api/api_pb2.cpp.o
Compiling /data/switch/.pioenvs/switch/src/esphome/components/api/api_pb2_service.cpp.o
Compiling /data/switch/.pioenvs/switch/src/esphome/components/api/api_server.cpp.o
Compiling /data/switch/.pioenvs/switch/src/esphome/components/api/list_entities.cpp.o
Compiling /data/switch/.pioenvs/switch/src/esphome/components/api/proto.cpp.o
Compiling /data/switch/.pioenvs/switch/src/esphome/components/api/subscribe_state.cpp.o
Compiling /data/switch/.pioenvs/switch/src/esphome/components/api/user_services.cpp.o
Compiling /data/switch/.pioenvs/switch/src/esphome/components/binary_sensor/automation.cpp.o
Compiling /data/switch/.pioenvs/switch/src/esphome/components/binary_sensor/binary_sensor.cpp.o
Compiling /data/switch/.pioenvs/switch/src/esphome/components/binary_sensor/filter.cpp.o
Compiling /data/switch/.pioenvs/switch/src/esphome/components/esp32/core.cpp.o
Compiling /data/switch/.pioenvs/switch/src/esphome/components/esp32/gpio_arduino.cpp.o
Compiling /data/switch/.pioenvs/switch/src/esphome/components/esp32/gpio_idf.cpp.o
Compiling /data/switch/.pioenvs/switch/src/esphome/components/esp32/preferences.cpp.o
Compiling /data/switch/.pioenvs/switch/src/esphome/components/esp32_touch/esp32_touch.cpp.o
src/esphome/components/esp32_touch/esp32_touch.cpp: In member function 'virtual void esphome::esp32_touch::ESP32TouchComponent::setup()':
src/esphome/components/esp32_touch/esp32_touch.cpp:18:5: error: 'touch_pad_filter_start' was not declared in this scope
     touch_pad_filter_start(this->iir_filter_);
     ^~~~~~~~~~~~~~~~~~~~~~
src/esphome/components/esp32_touch/esp32_touch.cpp:18:5: note: suggested alternative: 'touch_pad_filter_enable'
     touch_pad_filter_start(this->iir_filter_);
     ^~~~~~~~~~~~~~~~~~~~~~
     touch_pad_filter_enable
src/esphome/components/esp32_touch/esp32_touch.cpp:26:47: error: too many arguments to function 'esp_err_t touch_pad_config(touch_pad_t)'
     touch_pad_config(child->get_touch_pad(), 0);
                                               ^
In file included from src/esphome/components/esp32_touch/esp32_touch.h:10,
                 from src/esphome/components/esp32_touch/esp32_touch.cpp:3:
/data/cache/platformio/packages/framework-arduinoespressif32/tools/sdk/esp32s2/include/driver/esp32s2/include/driver/touch_sensor.h:156:11: note: declared here
 esp_err_t touch_pad_config(touch_pad_t touch_num);
           ^~~~~~~~~~~~~~~~
src/esphome/components/esp32_touch/esp32_touch.cpp: In member function 'virtual void esphome::esp32_touch::ESP32TouchComponent::loop()':
src/esphome/components/esp32_touch/esp32_touch.cpp:117:7: error: 'touch_pad_read_filtered' was not declared in this scope
       touch_pad_read_filtered(child->get_touch_pad(), &value);
       ^~~~~~~~~~~~~~~~~~~~~~~
src/esphome/components/esp32_touch/esp32_touch.cpp:117:7: note: suggested alternative: 'touch_pad_read_raw_data'
       touch_pad_read_filtered(child->get_touch_pad(), &value);
       ^~~~~~~~~~~~~~~~~~~~~~~
       touch_pad_read_raw_data
src/esphome/components/esp32_touch/esp32_touch.cpp:119:7: error: 'touch_pad_read' was not declared in this scope
       touch_pad_read(child->get_touch_pad(), &value);
       ^~~~~~~~~~~~~~
src/esphome/components/esp32_touch/esp32_touch.cpp:119:7: note: suggested alternative: 'touch_pad_reset'
       touch_pad_read(child->get_touch_pad(), &value);
       ^~~~~~~~~~~~~~
       touch_pad_reset
src/esphome/components/esp32_touch/esp32_touch.cpp: In member function 'virtual void esphome::esp32_touch::ESP32TouchComponent::on_shutdown()':
src/esphome/components/esp32_touch/esp32_touch.cpp:142:5: error: 'touch_pad_filter_stop' was not declared in this scope
     touch_pad_filter_stop();
     ^~~~~~~~~~~~~~~~~~~~~
src/esphome/components/esp32_touch/esp32_touch.cpp:142:5: note: suggested alternative: 'touch_pad_fsm_stop'
     touch_pad_filter_stop();
     ^~~~~~~~~~~~~~~~~~~~~
     touch_pad_fsm_stop
src/esphome/components/esp32_touch/esp32_touch.cpp:143:5: error: 'touch_pad_filter_delete' was not declared in this scope
     touch_pad_filter_delete();
     ^~~~~~~~~~~~~~~~~~~~~~~
src/esphome/components/esp32_touch/esp32_touch.cpp:143:5: note: suggested alternative: 'touch_pad_filter_disable'
     touch_pad_filter_delete();
     ^~~~~~~~~~~~~~~~~~~~~~~
     touch_pad_filter_disable
src/esphome/components/esp32_touch/esp32_touch.cpp:155:77: error: too many arguments to function 'esp_err_t touch_pad_config(touch_pad_t)'
       touch_pad_config(child->get_touch_pad(), child->get_wakeup_threshold());
                                                                             ^
In file included from src/esphome/components/esp32_touch/esp32_touch.h:10,
                 from src/esphome/components/esp32_touch/esp32_touch.cpp:3:
/data/cache/platformio/packages/framework-arduinoespressif32/tools/sdk/esp32s2/include/driver/esp32s2/include/driver/touch_sensor.h:156:11: note: declared here
 esp_err_t touch_pad_config(touch_pad_t touch_num);
           ^~~~~~~~~~~~~~~~
Compiling /data/switch/.pioenvs/switch/src/esphome/components/gpio/switch/gpio_switch.cpp.o
*** [/data/switch/.pioenvs/switch/src/esphome/components/esp32_touch/esp32_touch.cpp.o] Error 1
========================== [FAILED] Took 8.30 seconds ==========================

and here is the config file

esphome:
  name: switch

esp32:
  board: lolin_s2_mini
  variant: esp32s2
  framework:
    type: arduino
    version: 2.0.3
    platform_version: 5.2.0

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "s1m7r/yx0ljNktEnQoIbYg/8qhpakP795XR55KC33n0="

ota:
  password: "23bf737cf5581698d5004c8da0f1bc5d"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Switch Fallback Hotspot"
    password: "dYwvkjvuaKq3"

 # Example configuration entry
switch:
  - platform: gpio
    pin: 15
    name: "Living Room Dehumidifier"

esp32_touch:
  setup_mode: True

binary_sensor:
  - platform: esp32_touch
    name: "espTouch Bed Top Left"
    id: esptouch_bed_top_left
    pin: GPIO2
    threshold: 56

thank you

Have you tried following the advice in the second line of the logs?

Just using the regular version of Arduino does not let me flash the esp at all

What happens if you remove these lines?

Also - what version ESPHome, what type of install (HA add-on, standalone)?

If standalone - what Nick said, you may be clashing with a previous Arduino install.

I just compiled and installed your YAML on ESPHome 2022.10 using HA Add-on and it works fine, so I would be safe in saying it’s something in your environment, not ESPHome.

Oh - I did leave out the framework lines.

I have the same issue as OP using the same config. Tried with the “framework” section commented out but I still have the same exact error.

Also tried deleting my ~/.platformio folder and re-compiling to eliminate any potential conflicts with previous Arduino install, but still encountering the same issue.

I’m using standalone ESPHome Version: 2022.12.3 on Mac OS.

I have exactly the same problem :frowning:

Same error with the latest versions… also tried using the latest esp-idf framework. Same errors… “touch_pad*” are not declared in this scope. Any way to work around this?

Looks like time for a github issue.

Responded to your issue, but it seems your issue is different. You are trying to use gpio1 which is not supported.