Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wemos D1 Mini S2 touch support disabled #4411

Closed
spuder opened this issue Apr 14, 2023 · 10 comments · Fixed by esphome/esphome#5116
Closed

Wemos D1 Mini S2 touch support disabled #4411

spuder opened this issue Apr 14, 2023 · 10 comments · Fixed by esphome/esphome#5116

Comments

@spuder
Copy link

spuder commented Apr 14, 2023

The problem

The datasheet for the S2 (esp32) chip shows that touch sensors are available on pins 1-14

See section 3.3.4 in the datasheet

If you attempt to enable the esp32_touch, it gives the following error:

esp32_touch:

binary_sensor:
  - platform: esp32_touch
    name: "ESP32 Touch Pad"
    pin: 13
    threshold: 1000
Failed config

esp32_touch: [source config.yaml:274]
  
  This feature is only available on ESP32.
  {}

Which version of ESPHome has the issue?

2023.3.2

What type of installation are you using?

Docker

Which version of Home Assistant has the issue?

No response

What platform are you using?

ESP32

Board

Wemos D1 Mini S2

Component causing the issue

esp32_touch

Example YAML snippet

https://www.wemos.cc/en/latest/s2/s2_mini.html

Anything in the logs that might be useful for us?

No response

Additional information

No response

@spuder
Copy link
Author

spuder commented Apr 14, 2023

@dd32
Copy link

dd32 commented Apr 14, 2023

What's your board configuration? (esphome: & esp32:)

Previously: #4194

@spuder
Copy link
Author

spuder commented Apr 14, 2023

Thanks for the information.
Here is my esphome and esp32 config:

esphome:
  name: foobar3
  friendly_name: foobar

esp32:
  board: lolin_s2_mini
  variant: esp32s2

@czechmate777
Copy link

czechmate777 commented Apr 15, 2023

I'm having the exact same issue. I traced the code a little further, and it seems to be coming from here:
https://github.com/esphome/esphome/blob/6b67acbeb5fc6fae713ed81f7ee549f53a3d42ff/esphome/components/esp32_touch/__init__.py#L79

while TOUCH_PADS specifies VARIANT_ESP32, VARIANT_ESP32S2, and VARIANT_ESP32S3 here:
https://github.com/esphome/esphome/blob/6b67acbeb5fc6fae713ed81f7ee549f53a3d42ff/esphome/components/esp32_touch/binary_sensor.py#L25

Edit:
Upon closer inspection, it seems the esp32s2 variant uses a different touch sensor driver, making it incompatible with the existing code. Nevertheless, I will continue to slowly chip away at this to see if I can figure this out.

Here are the errors I get when forcing the validation to pass:

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:12,
                 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:12,
                 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);
           ^~~~~~~~~~~~~~~~
      

@kbx81
Copy link
Member

kbx81 commented Jul 16, 2023

I'm working on this -- should have a PR ready to try later this week. 😇

@kbx81
Copy link
Member

kbx81 commented Jul 18, 2023

Hi! Would love some feedback on this PR -- let me know if it works for any of you here. 😄

Updated documentation preview is available here -- note that there are some new parameters as the S2 & S3 variants have a different interface under the hood for the touch sensor hardware.

@TaruDesigns
Copy link

@kbx81 I have tried this on the latest Esphome release (2023.8.2) and I can't seem to get any coherent readings with a LOLIN S2 MINI. The project compiles and uploads just fine, and I can see the values with setup_mode: true but the value will never change (whether up or down, it just stays the same) no matter what I do. The same setup is working fine for a regular ESP32 WROOM.

@kbx81
Copy link
Member

kbx81 commented Sep 8, 2023

@TaruDesigns that's...odd...I'm running it on an S2 here myself and it's working great. Maybe join us on Discord and some of us can help you there. If the values you see reported with setup_mode: true are not changing at all, that suggests something else is out of place somehow -- but we'd need to see your config as well as how you've wired up your device.

@TaruDesigns
Copy link

TaruDesigns commented Sep 8, 2023

So thanks to @kbx81 we managed to find the issue:

The default "measurement duration" parameter (which is also used if it's not specified) is simply too fast to get any coherent values.

A value of 100us gives pretty good results, the full config using filters can be as follows:

esp32_touch:
  measurement_duration: 100us
  denoise_grade: BIT12
  denoise_cap_level: L0
  debounce_count: 1
  filter_mode: IIR_16
  noise_threshold: 0
  jitter_step: 0
  smooth_mode: IIR_2

@kbx81
Copy link
Member

kbx81 commented Sep 8, 2023

Thanks for circling back with the solution @TaruDesigns! 🍻

In general, for others/for posterity, the key takeaway here is what's noted at the bottom of the documentation. In particular:

if you are moving your configuration from an original ESP32 to an S2 or S3 variant, expect that you’ll need to make some adjustments to your configuration to accommodate [the S2/S3].

The S2 & S3 are different from the original ESP32 when it comes to capacitive touch. This experience reflects that pretty directly. 😇

@github-actions github-actions bot locked and limited conversation to collaborators Jan 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants