ESP32-S3 touch sensor?

I’ve used touch pins on esp32 to change a lamp into a touch-controlled lamp. I’m now trying to use the M5StampS3, which uses the esp32-S3. The ESPHOME document indicates touch works differently on this chip. When I configure a touch pin I get a very high value out, but it doesn’t change at all when I touch the medal the pin is connected. Any idea on configuration to make this works. This is the configuration I’m trying to make work with a touch sensor.

 esphome:
  name: m5-esp32-s3-orange-1-relay
  friendly_name: m5 esp32 s3 orange 1 relay

esp32:
  board: esp32-s3-devkitc-1
  framework:
    #type: arduino
    type: ESP-IDF

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: !secret api_key

ota:
  password: !secret ota_password

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "FR-Lamp-Touch"
    password: !secret wifi_password

# Enable Web server.
web_server:
  port: 80
  
captive_portal:

sensor:
  # hack so the touch sensor doesn't kick off at power on
  - platform: uptime
    name: Uptime Sensor
    id: time_since_boot
    update_interval: 30s


esp32_touch:
  setup_mode: true

binary_sensor:
  - platform: esp32_touch
    name: "ESP32 Touch Pad GPIO5"
    pin: GPIO5
    threshold: 290
    filters:
      # Small filter, to debounce the spurious events.
      - delayed_on: 10ms
      - delayed_off: 10ms
    #on_press:
    on_click:
    - min_length: 10ms
      max_length: 500ms
      # Short touch to turn light on and off
      then:
        if:
          # test to ignore random event on boot
          condition:
            - lambda: 'return  id(time_since_boot).raw_state > 10;'
          then:
            - button.press: pwr_btn
        

# restart-button
button:
  - platform: restart
    name: "restart-esp32-dim-touch"

  - platform: template
    name: pwr btn
    id: pwr_btn
    on_press:
      then:
        if:
          condition:
            and:
              # if light is off
              - switch.is_off: light_state
          then:
            # then we turn it on
            - switch.turn_on: light_state
          else:
            # else it's on so we turn it off
            - switch.turn_off: light_state


switch:
  - platform: gpio
    name: "light_state"
    pin: GPIO7
    id: light_state

Hi Brian!

I just upgraded a previsiously-installed traditional ESP32 to an ESP32-S3-16/8.

In my case, the values initially were huge (significantly larger than before) and didn’t appear to change at all. The trick that worked for me was to adjust the measurement_duration value down from the default 4ms to 0.25ms. Once I did that, the values were still pretty large numbers, but changed quite reliably.

esp32_touch:
  setup_mode: false
  measurement_duration: 0.25ms

binary_sensor:
  - platform: esp32_touch
    name: "TouchPad1"
    pin: 4
    threshold: 1100000
  - platform: esp32_touch
    name: "TouchPad2"
    pin: 5
    threshold: 1300000

I’ve got ~1m lead wires running to from the ESP32-S3 to the touchpads. For me, TouchPad1 sits idle at ~ 573,000 and goes up to ~1675000 when touched. TouchPad2 sits idle at ~677000 and goes up to ~1530000 when touched.

3 Likes

Great. I’ll give it a try.

That worked great. Thanks much.

1 Like