Page 1 of 1

ESP01 GPIO2 doesn't pull up HIGH when it is loaded

PostPosted: Tue Aug 31, 2021 4:11 am
by Marko Mocilac

I am doing latching circuit using ESP01.
In short, once motion is detected, EPS01 will be turned on with 3.3V.
Now it should do stuff and select GPIO2 OUTPUT to HIGH, this opens MOSFET which cut off power supply for ESP01.

I noticed problem with ESP01 GPIO.
In case pin have some load (10k pull down resistor prior mosfets gate) measured voltage on pin is 1.3V, when I leave GPIO2 open (no load) everything seems to be fine and I am measuring expected 3.3V.

Could you please help me clarify this?
Any proposal for a solution.

In case you would need code, it is very simple:

Code: Select allvoid setup() {
  pinMode(PIN, OUTPUT);
  mqtt_client.setServer(MQTT_SERVER, MQTT_PORT);

  Serial.println("setup(): State on pin " + String(PIN) + " is: " + String(digitalRead(PIN)));

/* Main loop() */
void loop()
  digitalWrite(PIN, HIGH);
  Serial.println("loop(): Current state on pin " + String(PIN) + " is: " + String(digitalRead(PIN)));

Re: ESP01 GPIO2 doesn't pull up HIGH when it is loaded

PostPosted: Sun Sep 05, 2021 3:50 am
by eriksl
I don't think it's smart to use ESP01's GPIO2 for driving a MOSFET. A MOSFET is required to have a strong signal at it's gate, which transitions as fast as possible and charges the gate, or drains any remaining charge from the gate as fast as possible. With the obligatory pull up resistor connected that is hard(er) to achieve. Also keep in mind GPIO2 will go completely wild during booting, the default routing of the GPIO's is all sorts of clock signals so imagine what the load on your MOSFET would do.

To solve the first problem I'd really recommend using a MOSFET gate driver IC (like IR4427). It also inclused a schmitt trigger, so the gate will always be at one of two defined levels - completely off or completely on.

To solve the second problem use a GPIO that's more or less defined during boot. I don't think there are any available on the ESP01, may the UART input (GPIO3). Otherwise better use an I2C I/O expander, their output is always defined (doesn't change without explicit command to do so).

Re: ESP01 GPIO2 doesn't pull up HIGH when it is loaded

PostPosted: Mon Sep 13, 2021 11:28 am
by Marko Mocilac
Thank you very match for your feedback and detail explanation!

Regarding driving the mosfet I am aware that for properly usage I should use mosfet driver.
However, for my purpose I guess it should be fine without it.
This suppose to be kind of door alarm functionality.
I really do not use mosfet and esp01 for high speed switching. I thought that having pull down resistor on mosfets gate and maybe adding current limiting serial resistor could balanced things.
I already used this approach in simple circuits for dimming LEDs which actually uses PWM signal up to 1kHz I think. So far I didn't experienced problems for a year.

I test this latching circuit with ESP8266 NodeMcuV3 board, it works fine.
My main problem here is than obviously related with ESP01 and GPIO2 I choose to use.
I am a bit noob, I wasn't aware that ESP01 will go wild during boot on GPIO2.

After I try to use GPIO3 it works fine.