Should the pins on an ESP32 be high (3v) when set to input?!

Related to this Reddit post I’m going nuts as my ESP32 pins are mostly (with about three exceptions) all HIGH at 3v even though they’re either NOT configured at all to be anything OR configured to be input??

What exactly is the problem? What are you trying to solve?

Most of the ESP I/O pins are floating when not configured as input or output.

Hi @stevemann & @nickrout

The problem I’m trying to solve is I’m trying to connect an AM312 PIR sensor to Pin 13 of my ESP32-POE.

This pin is ALWAYS at 3v unless it’s pulled down via an external resistor OR if it’s configured as an output. So I guess I’m confused why I can’t (from Esphome) tell the pin not to use the internal pullup if clearly this is doable given it’s achieved when I configure the pin as an output.

Does that make sense?

I just tried (again) and:-

  - platform: gpio
    name: "check"
    pin:
      number: 13
      mode:
        input: true
        pullup: false

doesn’t stop the pin being HIGH

but

switch:
  - platform: gpio
    pin:
      number: 13
    name: "Relay"

does

That is the same sensor I use on an ESP8266 (Sonoff Mini). Here’s my code:

  # PIR on GPIO14  
  - platform: gpio
    pin: 
      number: GPIO14                # PIR Sensor
      inverted: False
      mode: INPUT_PULLUP
    name: ${devicename} sensor

Just a tip: Your code is ambiguous when you say “pin: 13”. Say, instead “pin: GPIO13”. There’s no question that you mean GPIO13.

1 Like

No, you can use 13 or gpio13.

Thanks, I’ve tried this code already and sadly it doesn’t help, the sensor just shows ‘detected’ full time. The pull up resistor on the pin just prevents the AM312 ‘overpowering’ it.
Thank you though!

It was just a suggestion to reduce the potential ambiguity.
Simply saying “Pin number” could imply the physical pin number on the board which is often different from the GPIO number.

For instance, on the ESP32-PoE, GPIO13 is on pin 10. On the Raspberry Pi Pico, pin 13 is ground and GPIO13 is pin 17.

Using

pin:
   number: GPIO13

eliminates that ambiguity.

Do you have an external pullup resistor on the pin?
Looking at my code, it should work with
mode: INPUT
because the AM312 is an active high/low. No pullup or pulldown is needed.

I just tested mine with this code:

# PIR on D2
  - platform: gpio
    pin:
      number: D2
    name: ${devicename} PIR

Works fine.

Nope - the board has a permanent pull-up on that pin can’t disable

Pretty sure I have pointed you to these docs already, and quite recently

ESPHome always uses the chip-internal GPIO numbers . These internal numbers are always integers like 16 and can be prefixed by GPIO . For example to use the pin with the internal GPIO number 16, you could type GPIO16 or just 16 .

@daneboom , I note that the datasheet you linked to says gpio 2,14,15 are tied to the sd card. However the diagram shows gpio 13 is connected to sd_data3.

Also the colour coding indicates which gpios are free, and which aren’t. 13 isn’t in the free list.

Conclusion, try one that is listed as free.

Which board? Where did you read this? There are many iterations of ESP32 development boards and a hard pullup on a GPIO pin would be unusual.

And to a new user coming from an Arduino or Raspberry background, pin number usually refers to the physical pin on the development board. So, what’s wrong with encouraging an unambiguous “GPIO16”?

It is free, it’s just their diagram is a bit confusing(!). They have two levels of ‘free to use’. There’s regular ‘free to use’ and there’s ‘free to use+on the UEXT’.

Pin 13 is so free to use they’ve stuck it on the UEXT port too. It says so on the left of the diagram and I’ve also linked to a forum post where Olimex say it’s free to use.

This board :slight_smile:

Tell me about it.

Where did you read this?

I’ve already linked to the page, but here’s the specific post :slight_smile:

I would like to see the schematic of the board. Also the specific product datasheet that might reveal why there is a pullup on that pin.

Do you have to use GPIO13? If you have to use GPIO13, invert the data line from the sensor with a NPN transistor:
de2f85400982674bead66773c2652d2904210eaa

Since, as you say, the pin has an external pullup resistor then just set the pin to INPUT in the device YAML code.

I have already suggested using a different pin.

@daneboom if this is the correct schematic ESP32-POE/ESP32-PoE_Rev_K.pdf at e0e8954ca8d748a45915777ff10a10dd8edc758e · OLIMEX/ESP32-POE · GitHub

Then there is definitely a pullup on GPIO13 - see the block where it lists the UEXT connections.