Graceful shutdown (power off, not deep sleep)
I'm currently using
to save battery, but the current in this mode is still too high for my needs.
Has anybody implemented a solution where you can gracefully shutdown the main (and its threads) ,then disconnect power and be able to reboot with ONE button?
Many thanks in advance.
@fsergeys You should measure power draw from battery, not USB. There's a lot more going on when powered via USB, it's not representative of what happens when you're running on battery.
You can definitely use the Pytrack's deep sleep (use the PyTrack library) to power down completely the WiPy, but you shouldn't see much of a difference when running from battery in the case of a WiPy 3.
@jcaron The board is a Wipy3 on a pytrack. I don't use the deep sleep shield.
When detaching the battery and connect to usb with an intermediary current meter I notice a spike of 0,2A every few seconds when in deepsleep.
I even tried to deinit the bluetooth and wireless, but to no avail.
The code does indeed call the machine.deepsleep().As the documentation states that the deepsleep API is for Deep Sleep Shields (docs: "This chapter describes the library which controls the Deep Sleep Shield"). If the API also works with pytrack: that would be wonderful news. I will try it out.
Below is the code:
def pin_handler(arg): time.sleep(0.5) if int(p_in()) == 0: print("irq on %s" % (arg.id())) print("Shutting down NMEA reader- and writer threads ...") dispatcher.keepReading = False dispatcher.keepWriting = False gc.collect() time.sleep(2) print("...done") print("Setting %s to listen for wakeup" % (arg.id())) machine.pin_deepsleep_wakeup(['P3'],machine.WAKEUP_ALL_LOW, True) print("Going into deepsleep") machine.deepsleep() p_in = Pin('P3', mode=Pin.IN, pull=Pin.PULL_UP) p_in.callback(Pin.IRQ_FALLING, pin_handler)
@fsergeys what module (LoPy 1, LoPy 4, WiPy 2, WiPy 3...) are you using? Do you also have a Pysense or PyTrack or deep sleep shield? What current draw are you observing? What’s your target?
The Deep Sleep Shield, Pysense and PyTrack do exactly what you are talking about: they completely power off the module during deep sleep (provided you use the appropriate library to control deep sleep, not
machine.deepsleep. But the newer modules should be able to achieve the same consumption with their built-in deep sleep. There are still issues with the FiPy I believe, though.
robert-hh last edited by
@fsergeys The most important part of that is an external circuitry to switch the power, mostly a P-Mos FET and a RS-Flip-Flop, there one side is connected to a GPIO port (with a proper pull resistor), and the other to the button, you mention. The only thing to may have to care about when switching off are files, that should be closed.