Hey gang, I'm struggling over a circuit. It kinda works (on Arduino, not at all ESP) and perhaps it's not a good idea:
I want multiple power switches for the microcontroller, and for it to know exactly which power switch was used.
The idea being that the device is generally off until a switch is flipped, which powers it, and it knows which one was flipped in order to perform a task.
(I know I could use double pole switches, but really don't want to - they'll be momentary in fact)
Correct.
Do yourself a favor, wire the buttons correctly. Switch ( or button ) between input pin and ground, then enable the internal pull up resistors or wire an external one from input to the processors working voltage. The a push will read a low and the rest is software.
Mike apparently did not realise that the intention of this is to use the switches to control power to the microcontroller.
Of course this begs the perennial question - why? It makes more sense to sleep the microcontroller and use the switches to wake it when required.
What is wrong with the proposal is that you will be putting a negative voltage on the microcontroller inputs relative to its ground. You actually need - if you were to proceed - two other diodes between the switches and the inputs (and to use the internal pull-ups), Switching the ground side is mostly quite problematical.
I appreciate the responses guys!
Mike, yeah not quite understanding, perhaps I could have explained better. I am using them as pullup inputs.
Paul, the XY comment is fair (I tell clients the same all the time hah).
I've made a few sleeping devices but they always seem to sap the battery over time. I know they shouldn't, but empirically.. it happens in my experience so I thought why not just have literal physical power buttons - which can also be detected as being in use individually.
Further description, I'm making a remote - a 433mhz TX that'll blast out various signals for a split second on button pushes
I take your point, and will go for a deep sleep. Battery sapping must be happening pretty much regardless.
Found this a little hard to draw, so I put the main grounds pointing toward the bottom.. anyway, effort was made.
For others that find their way here, I've had some luck with the following techniques:
(apologies in advance for rousing @Grumpy_Mike's ire with diagrams, but here we go)
Momentary power, with input pullups.
Specific digital pin goes low depending on which is pressed. (Thanks Paul for diode tip)
Correct, it'll only run the code during the time you hold the button down.
But that's okay in this case, its only job is to send out a quick radio transmission
Yes. If you use code to do the latching you just need to monitor digital in pins to read which one gets pressed, do the latching and then do what ever you want with the input pin info. I assume it send a different transmission. Then release the latch.
The latch could be a MOSFET, solid state relay, transistor all of which can be small SMD devices if you are making a custom board. The hardware side should be very simple. So should the code.
Now the ESP8266 - notably the ESP-01 module - has a CH_PD pin which seriously shuts down the chip, not just sleeps it, without the need to muck about with the actual power connections.
With some diode logic, this can be used to start the device up on a button press, then hold it running with a GPIO until its task is completed and then shut down again.