So I'm planning to power my esp32 with this module: Pololu 5V Step-Up Voltage Regulator U1V11F5. I've removed the 100k resistor that will pull-up the EN pin and made it so it pulled-low instead to make it so that module is powered off by default. I'm using a button to drive the EN pin high, the button is connected between VIN and EN pin. My plan is to use the same button to read if it is pressed again to turn off the EN pin. Is it okay to hookup that same button to my esp32 or will it fry my board?
Is there a reason for that? ESP32 is a 3.3V device.
Could that damage the ESP32?
That's not advisable. It would drop 5 volt into the input reading it. 3.3 volt would likely be the maximum allowed voltage.
To be sure please provide schematics and datasheets for the Step-Up converter. Which ESP32 are You using?
Please excuse the ugly drawing:
This is the schematic with the ESP32 and the 5v step-converter. The GPIO16 is there to hold the EN pin high to make the VOUT stay on. One correction to the schematic is the battery's negative terminal is directly connected to GND not to the resistor. Now I want to use that same button to be able to read by the ESP32 to turn off the EN pin.
This the schematic for 5v step-up converter U1V11F5:
In the drawing You made the converter GND is separated from battery minus by the 100 kOhm. That can't work. My guess is You made a mistake when drawing.
The converter must be running giving the controller power to detect the button/switch. That's not happening following Your description.
Yeah I messed up my drawing sir, let me re-draw it when I get home. The common grounds are all tied together. When the button is pushed the EN pin is high and the ESP32 is powered on, then GPIO16 is driven high so the EN pin is held high. Can I wire the button to the ESP32 to detect button push? If so how to do it without frying the ESP32. Btw the ESP32 Iā²m using is the wemos d1 mini32. Something like this:
Haha, that's plausible. I'm out hiking for the moment...
This way the converter is powered all the time but maybe that's okey for You.
When you close the switch, you will be applying battery voltage to a GPIO pin of an ESP32 that is not even powered up yet. So large amounts of current may flow through the protection diode. I think you should insert a diode into that line so the GPIO is only able to supply positive voltage to EN, and current can't flow in the opposite direction.
Detecting that the button is pushed during normal operation will probably require a second pin, along with an NPN transistor to convert the signal to active-low. Plus another diode. Well, I'm just guessing about that. I'm so used to seeing the active-low version of this, such as when using a P-channel mosfet to switch the power:
What is the battery voltage?
I'm using a single li-ion battery to power the 5v step-up converter. Btw I already tried using the circuit you showed but wanted to try this approach of using the 5v step-up converter and utilizing the EN pin to somehow work like the push-button power switch. How should I wire npn transistor then ?
I think this would work:
I'm a bit hazy about GPIO pins on an ESP32. This circuit would ground the input GPIO during power-up. ESP32 experts here might want to comment on whether that's ok or not.
Remember that when using a button press to trigger shutdown, your code has to wait until the button is released before actually powering down.
I only have bc547 transistor, is this ok to use? Also on the GPIO(IN) could I just program that pin into input_pullup? On the base of the npn transistor, what is the resistor value?
The BC547 should work fine. I would try 100K for the base resistor since you're already using one of those for the EN pulldown, although it could be almost anything. Current will flow through it only when the button is pressed, so it doesn't matter much.
Yes, you can configure the input GPIO as INPUT_PULLUP instead of using the external resistor.
Do you understand how the circuit works, and why the diodes are needed?
One other thing. If you will ever be putting your ESP32 to sleep, you'll have to investigate what happens to the GPIO pins during sleep. Arduino pins would maintain their state during sleep. I don't know about the ESP32. Of course you would need the output GPIO to stay high during sleep to keep the power on.
I just know the parts but don't know how this works. Can you please explain to me how it works? Will try this circuit later, and report back if it works
The diodes allow either the push button or the ESP32 to bring EN high, but eliminate any potential conflict between the two. The diode on the right prevents battery voltage from reaching the ESP32 GPIO, and the diode on the left prevents the ESP32 output GPIO from turning on the transistor. The circuit also lets you use the pushbutton as a logic input after powerup.
Tested the circuit briefly before going to work and it worked well, but just programmed it to just turn off/on the onboard led.
On the off topic(let me know if should just post this on a new post) planning on combining this with this circuit that I found on this forum. Is it ok to just connect the npn transistor collector to the EN pin on my boost converer?
I didn't realize that you were the one that created post here sir: Switching power with a DS3231 RTC module. Can you please help me combine the circuit that you created with this one?