M5stickc plus2 DeepSleep
-
Hello!
I use UIFlow 1.13.4 and M5stickc plus2
def buttonA_wasDoublePress():
global peer_mac, data, Sleep, Speed, Rudder_Angle, Select, cnt_succes, flag_cb
M5pwr.brightness(0)
p37 = machine.Pin(37, mode = machine.Pin.IN, pull = machine.Pin.PULL_UP)
p37.irq(trigger = machine.Pin.WAKE_LOW, wake = machine.DEEPSLEEP)
machine.deepsleep(20000)
pass
btnA.wasDoublePress(buttonA_wasDoublePress)I'm trying to add a deep sleep mode. But the device simply turns off when you press button A twice.
Tell me how to realize deep sleep in UIFlow on M5stickc plus2.
Thanks a lot.
-
The "deepsleep" function of the M5StickC PLUS2 is taken care of by an external hardware-RTC (
RTCBM8563). Have a look at the electric diagram on the doc page. I don't think you can use the "generic" Micropython machine.deepsleep()You should use the Power.timerSleep(sec) which is a part of the "built-in" M5 library.
A tip if you are programming directly in Micropython and uploading via the serial port. You can use the UIFlowl web site as a kind of "API-reference". Go in and find the UIFlow "brick/function" you'll like to use and then see what Micropython code it generates.Here is an example:
-
And maybe also upgrade to version 2.0.4:
-
The problem is that I created a fairly large project in Flow 1.13 using functions that are not in Flow 2. Therefore, the question is rather how to implement deep sleep specifically in Flow 1.13. And I don't understand why the standard function doesn't work(
The whole project is written in blocks in flow and in python I want to finish writing a deep sleep.
-
Hello @Hopichek
the HOLD pin (GPIO4) needs to stay high during deep sleep to keep the ESP32 powered.
Try the following to keep the value of the HOLD pin during deep sleep:from machine import Pin, deepsleep Pin(4, Pin.OUT, value=1, pull=Pin.PULL_HOLD) # HOLD PIN - UIFlow1 #Pin(4, Pin.OUT, value=1, hold=True) # HOLD PIN - UIFlow2 deepsleep(20000)
Note: verified with an M5Paper which has a similar power architecture.
Thanks
Felix -
If you look at the electric diagram I referenced you'll see that there is a power circuit that relies on a software implemented power-on hold function.
The ESP32 must pull up GPIO4 ("HOLD") to keep the system power on which include the power for the ESP32 itself.
When you call the standard machine.deepsleep() which is designed to use the ESP32 internal deep-sleep which relies on power to the ESP32, then the GPIO4 will turn low and cause the external power circuit to cut power to the entire system - expect for the BM8563 RTC. Now the ESP32 has no power and will never wake up again.
The only way to power on again is to press the power button (designated S3 on the diagram) or if the BM8563 RTC pulls down the INT signal at some point. The BM8563 must be set up on beforehand with a timeout or date to pull the the INT signal.
"Under the hood" in UIFlow firmware the GPIO4 will be pulled high just after boot i.e. when the power is turned on either by the power button or the INT signal from the BM8563 RTC. That is also why you have to keep the power button pressed a few seconds for the system to start - the ESP32 has to reach the point where it holds power on by itself - i.e. pulling GPIO4 high.I had a look at the UIFlow 1.x for M5stickC Plus 2 and there are some functions under RTC where you can set timeout and interrupt. I think you might bee able to do the following:
- Enable timer interrupt (from RTC section)
- set timer value (from RTC section)
- power off (from Power section)
-
@felmue said in M5stickc plus2 DeepSleep:
the HOLD pin (GPIO4) needs to stay high during deep sleep to keep the ESP32 powered.
Try the following to keep the value of the HOLD pin during deep sleep:
from machine import Pin, deepsleep
Pin(4, Pin.OUT, value=1, pull=Pin.PULL_HOLD) # HOLD PIN - UIFlow1
#Pin(4, Pin.OUT, value=1, hold=True) # HOLD PIN - UIFlow2
deepsleep(20000)Here the system power is kept on - how is the power consumption compared to when only the BM8563 RTC is powered?
-
Hello @Cognitive5525
I don't have an M5StickCPlus2 so I cannot do the necessary measurements. But in the past I measured the M5Paper power consumption for both sleep and shutdown modes. Please see here. The power consumption in shutdown mode (only RTC running) drops to about 2.7 uA.
Thanks
Felix -
@felmue Thanks a lot, everything is working!
-
@hopichek,
While Felix's method do work, please note it is only putting the ESP32 itself in deep sleep not the rest of the board. I don't know your power saving requirements for the sleeping periods, but with the suggestion* I described above you'll probably get an even lower power consumption during deep sleep.*) if it works 😏