I was wondering if it is possible to keep a programmed gpio-state during the deep-sleep. My purpose is to control another device which is connected to my Electron through a gpio pin. This device needs a high state to wake-up and sleeps when the state drops to a low. This is a problem because the low state becomes high (or float) during the deep sleep on Electron. Is there any possibility by using the Electron’s modules without adding any additional hardware?
Example:
Assume there is a LED connected to one of the D0. I would like to light up the LED, then go to deep-sleep for 10 seconds, and after coming back from deep sleep, disable the LED. This can only work if the chip keeps D0 high during the deep-sleep period.
Nope, that’s not possible without extra hardware.
But the HW needed to do that is minimal - just one pull-up resistor (for a HIGH level, but not to drive an LED).
If you can afford to drive an LED during sleep, you should also be able to go for Stop Mode sleep instead of deep sleep tho’
@ScruffR Thanks for your response.
The pull-up resistor make sense, but it won’t work (please correct me if I’m wrong) if I need to keep the pin in the low state (even in deep-sleep mode).
In stop mode,the device turns off the network to save power but the processor is still running. Is there anything else I can do to save power? I only need one GPIO pin to control the external device.
First, I mentioned pull-up, but if you need a LOW to be kept during Electron sleep, then you should use a pull-down of course.
And as it happens this makes things a bit easier as WKP pin will be kept LOW by default as it needs to sense a rising edge.
Next, Stop Mode sleep (e.g. System.sleep(uint16_t wakeUpPin, uint16_t edgeTriggerMode)) does not keep the controller running. It just stops the execution of code and puts the controller in a low power state.
@redM0nk, another way is use an external N-MOSFET. With a pull-up on the gate, the transistor will be ON (driving an LED) until the GPIO is driven LOW, turning off the transistor. Either way (direct GPIO or via FET), neither solution is low power as the LED will draw milliamps of current while ON.
One issue which I’m facing is that during the deep sleep mode I can only maintain either a high state (using a pull-up resistor) or a low state (using a pull-down resistor).
The above solution basically maps the undefined GPIO state (during deep sleep mode) to high (pull-up resistor) or low (pull-down resistor). However, the current task requires the device to maintain the state of the GPIO pin (which could be either high or low - depending on the logic) during the deep sleep mode.
So using the above LED example:
If the LED is ON before the deep sleep mode, it should stay ON during the deep sleep mode.
And, if it is OFF before the deep sleep mode, it should stay OFF during the deep sleep mode.
One solution on top of my head, is to use a JK-flip flop switch. But, I’m not sure if that’s the most optimal one.
Makes sense. I think the deciding factor would be the power usage. I will test both flip-flop switch and stop mode.
will share my results/findings here.
Thanks.