Help with ESP32 Button Pad

This is kicking me in the rear and I feel like I’m just missing something.

I have this board that I’m using with this config:

substitutions:
  name: keypad-test
  friendly_name: Keypad Test

esphome:
  name: ${name}
  friendly_name: ${friendly_name}
  name_add_mac_suffix: False

esp32:
  board: esp32dev
  framework:
    type: esp-idf

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

api:
logger:
  level: DEBUG
ota:
  - platform: esphome

sensor:
  - platform: internal_temperature
    name: ESP Temperature
    unit_of_measurement: °C
    device_class: TEMPERATURE
    update_interval: 30s
    entity_category: "diagnostic"

binary_sensor:
  - platform: gpio
    pin: GPIO2
    name: "Key Press Toggle"

I have a simple momentary push button wired to D2 (GPIO2) and ground:
image

When I press the button…nothing happens. I know the board is up as I am getting the temp reading.

Anyone see what I’m missing?

ok, so, by “nothing happens”, I assume you mean that the binary_sensor isn’t registering as being “on” for the time period that you pushed down your button?

I don’t have anything that’s using the same port as you’re trying to, but here’s an example I have with a reed switch:

binary_sensor:
- platform: gpio
  pin:
    number: GPIO16
    mode: INPUT_PULLDOWN
    inverted: False
  name: "$humanName Right State"
  id: garage_door_right
  device_class: garage_door
  filters:
    - delayed_off: 250ms

Maybe you need an INPUT_PULLDOWN ?

Why pulldown if button is connected to gnd?
Should be pullup.

1 Like

Correct.

Neither adding INPUT_PULLDOWN nor INPUT_PULLUP make a difference.

Yeah, that’s a good point … now I wonder what’s going on with mine since I normally connect to ground … but, it’s working, so I won’t investigate it further!
-=-=-=-=-=-=-=-=
Of all stupid questions OP, is it possible your switch is bad?

I tried changing out the switch and switched over to GPIO18 with no change.

EDIT: I lied. This worked:

binary_sensor:
  - platform: gpio
    pin: 
      number: GPIO18
      mode: INPUT_PULLUP
    name: "Key Press Button"

Now, I’m wondering why GPIO2 didn’t work.

It should work, maybe just bad connection?
Or esphome decided not to use it because it’s onboard led pin…

Very glad it’s working!

Every now and then that happens to me too where a pin won’t work (or it works, but continuously flaps up and down) (╯°□°)╯︵ ┻━┻)

End of the day, there are a lot of pins on there and as long as you weren’t looking to use all/most of them, you should be good for this project at least!

That’s what I’m wondering. I did find a reddit thread talking about the resistor on that pin causing issues. I was hoping to be able to nail down the reason so I’d know moving forward what to look out for.

From esp32 point of view, there should not be problems.
I don’t know about esphome, but it should be known and documented if you can’t use gpio2 as input.
So still voting wiring problem (or damaged pin).

It’s definitely something with using that pin for input with a button. The same button worked fine on a different pin. The wiring was soldered to the header pins.