Can a Pin hold it's value during deepsleep?
-
- Posts: 8
- Joined: Thu Dec 26, 2019 6:32 pm
- Location: UK
Can a Pin hold it's value during deepsleep?
Basically all I'm trying to do is keep a LED on while the board is sleeping.
I've came across https://github.com/micropython/micropython/pull/4561 but I have no idea what to make of it.
I've came across https://github.com/micropython/micropython/pull/4561 but I have no idea what to make of it.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Can a Pin hold it's value during deepsleep?
As I understand that GitHub thread, if you specify hold, the pin will maintain its value during deepsleep. However its drive capability in this mode is likely to be minimal, so you'd need an external mosfet and series resistor to drive an LED from such a pin.
Note I haven't tested this - the above is based on reading that thread with a general knowledge of electronics.
Note I haven't tested this - the above is based on reading that thread with a general knowledge of electronics.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Can a Pin hold it's value during deepsleep?
The TinyPICO board uses a PNP transistor to control power to an onboard Dotstar RGB LED. The schematic is on Github here: https://github.com/tinypico/tinypico-ha ... ematic.pdf
Seon put the code to do this into a helper library. The source code is on Github here: https://github.com/tinypico/tinypico-mi ... inypico.py
Hope this helps.
Seon put the code to do this into a helper library. The source code is on Github here: https://github.com/tinypico/tinypico-mi ... inypico.py
Hope this helps.
-
- Posts: 8
- Joined: Thu Dec 26, 2019 6:32 pm
- Location: UK
Re: Can a Pin hold it's value during deepsleep?
Thanks, but I'm using an Adafruit Feather: htps://cdn-learn.adafruit.com/assets/assets/000/041/630/original/feather_schem.png?1494449413
Does it have anything similar?
Does it have anything similar?
-
- Posts: 8
- Joined: Thu Dec 26, 2019 6:32 pm
- Location: UK
Re: Can a Pin hold it's value during deepsleep?
I've figured it out. Pin.PIN_HOLD does the job, but it's usage is a bit confusing at first.
There are three things to keep in mind:
- if an GPIO value has been held previously, you can read it's current value only by creating the Pin with pull=machine.Pin.PULL_HOLD
- in order to be able to update the GPIO value you need to re-create the Pin with pull=None explicitly
- the newly assigned GPIO value can be held by re-creating the Pin with pull=machine.Pin.PULL_HOLD
Here's a working example:
There are three things to keep in mind:
- if an GPIO value has been held previously, you can read it's current value only by creating the Pin with pull=machine.Pin.PULL_HOLD
- in order to be able to update the GPIO value you need to re-create the Pin with pull=None explicitly
- the newly assigned GPIO value can be held by re-creating the Pin with pull=machine.Pin.PULL_HOLD
Here's a working example:
Code: Select all
def set_led_value(pin_addr, desired_value):
led = machine.Pin(pin_addr, machine.Pin.OUT, pull=machine.Pin.PULL_HOLD)
current_value = led.value()
if current_value != desired_value:
led = machine.Pin(pin_addr, machine.Pin.OUT, pull=None)
led.value(desired_value)
led = machine.Pin(pin_addr, machine.Pin.OUT, pull=machine.Pin.PULL_HOLD)
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Can a Pin hold it's value during deepsleep?
That is useful information. In deepsleep what is the drive capability of the pin? Do you have any information or measurements?
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
-
- Posts: 8
- Joined: Thu Dec 26, 2019 6:32 pm
- Location: UK
Re: Can a Pin hold it's value during deepsleep?
3.3V and 1.13 mA. Does that make sense? I'm still getting to grips with my multimeter and my electronics knowledge.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Can a Pin hold it's value during deepsleep?
It sounds plausible and backs up my suggestion of using a MOSFET or other device if you want to drive an LED - you'll probably want more current for reasonable brightness.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
-
- Posts: 8
- Joined: Thu Dec 26, 2019 6:32 pm
- Location: UK
Re: Can a Pin hold it's value during deepsleep?
Hmm, the 5mm Blue diffused led is quite bright tbh. I've set it with a small resistor, 470 Ohm.
Re: Can a Pin hold it's value during deepsleep?
All I/O pins capable of output have a hold function (there are some input-only pins).
The hold function is useful during reset, reprogramming, and sleep.
Only the pins in the RTC power domain can hold during deep sleep because the cpu power domain, which includes the "digital I/O" pins, is turned off. Those latter pins continue the hold when power comes back on.
The hold function uses the normal output transistors, so the current capability is the same as during normal operation.
The esp32 pins can source and sink plenty of current to power a signaling LED, no need for an external FET (unless you attach a bright LED to every pin...).
Pro tip: it's worth looking into the datasheet, technical reference manual, and ESP-IDF docs...
The hold function is useful during reset, reprogramming, and sleep.
Only the pins in the RTC power domain can hold during deep sleep because the cpu power domain, which includes the "digital I/O" pins, is turned off. Those latter pins continue the hold when power comes back on.
The hold function uses the normal output transistors, so the current capability is the same as during normal operation.
The esp32 pins can source and sink plenty of current to power a signaling LED, no need for an external FET (unless you attach a bright LED to every pin...).
Pro tip: it's worth looking into the datasheet, technical reference manual, and ESP-IDF docs...