-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
ports/esp32:* Implementation of deep sleep, esp32 module, machine.RTC #3531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@MrSurly This patch seems to remove esp_debug stuff, is that intended? |
Unintended side-effects of the merge. Let me get that fixed up. |
f9869bd
to
c7bb301
Compare
@mactijn Fixed, squashed, pushed |
Funnily enough I ran into a similar thing yesterday. Anyway, seems to work as promised. I'll do some more testing tomorrow, and hopefully release my M5Stack framework. |
Is that a MicroPython framework for the M5Stack? I received my hardware a couple of days ago. |
Yep. Awesome stuff. Great support from the supplier. I've ordered the faces kit too, so I can add support for those modules as well. |
@MrSurly : Just to let you know, i immediately put your pr to work in my firmware version... ;-) |
@Lisa999 Glad it's working well for you. Please let me know if you have any issues. |
I'm missing a day? |
@Lisa999 I'll take a look tonight (PST). |
c7bb301
to
668abb2
Compare
@Lisa999 |
? |
@Lisa999 |
Ok, resolved (i hope)
|
The errors you're experiencing are unusual if you're simply trying to merge this PR into |
git pull origin master |
From scratch:
|
Thx! Worked like a charm! |
@MrSurly thanks very much for persisting with this and getting it moved across from the old repo to this one. Much appreciated, and sorry for letting it sit for so long. Most of it looks good, but the main two items to discuss are:
|
@@ -23,7 +23,7 @@ | |||
#define CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ 240 | |||
#define CONFIG_ESP32_DEFAULT_CPU_FREQ_240 1 | |||
#define CONFIG_ESP32_DEBUG_OCDAWARE 1 | |||
#define CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY 0 | |||
#define CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY 2000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What exactly does this do? What is 2000 measured in, seconds?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What exactly does this do?
Ensures proper wakeup
Discussion here: micropython/micropython-esp32#32 (comment)
2000 is now the default value (instead of 0) in the ESP-IDF as of 9 months ago: espressif/esp-idf@3c583a7
What is 2000 measured in, seconds?
Microseconds
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thanks, understood.
Certainly, but n the past, it has been requested (by pfalcon, IIRC) that these sorts of things be not split into multiple commits. I can split this up if desired, but would appreciate consistent policy. Also not sure if you mean separate commits, or separate PRs for RTC / deepsleep ? |
Yes, this code was written by Mr. Manning and myself. You have my full release uner the MIT license. @manningt, You ok with this? |
@MrSurly Yes - You have my full release under the MIT license and I didn't in any way use any other code. |
@MrSurly @manningt thanks for confirming re copyright/license.
Yes I understand it's not always consistent, sorry. In this case adding a new module (esp32) should be a separate commit. And ideally have a separate commit for a new class (RTC). They can just be separate commits in this PR here (no need at all for a new PR). (I would be happy to do the split myself when merging but then I couldn't retain you as the commit author.) |
668abb2
to
42c4dd0
Compare
ports/esp32/modmachine*: RTC class, sleep impiementation ports/esp32/Makefile: Changes to support RTC/sleep ports/esp32/sdkconfig: Changes to support RTC/sleep
ports/esp32/machine_pin.c: esp32 wake-on-pin changes ports/esp32/Makefile: modified to support pin wake ports/esp32/mpconfigport.h: New top-level module for esp32 wake features
e344396
to
ab6544d
Compare
@dpgeorge Split. |
This is also reported here: https://forum.micropython.org/viewtopic.php?f=18&t=4856 This is what I thought would be a simple toggling of the wake pin trigger edge, but it turns out not ! This code should get the current value of door pin, and set the wake from deepsleep edge based on the pin value high or low and then put the device into deepsleep awaiting the trigger edge. There is a 10K pull-down on pin 34 and the switch pulls it high. The purpose is to wake up and sleep again each time the interrupt is triggered on a different edge. The time.sleeps() are just to give time to view the output and should not have any other effect other than de-bouncing, but given that the esp32 startup time is 2 seconds, debouncing should not be needed. It appears to work the first time deepsleep is fired, but thereafter door.value() always reads 0 even though the switch is closed and pulled high ! boot.py
Initially the switch was low: Then switch was then enabled (high): Then, without changing the switch position, it just continuously loops, apparently unable to read the value of door any more:
|
@diginfo Please open a new issue rather than necroposting here. I can take a look next week. |
Done: #3835 |
I'm a little confused. |
When reading the touchpad, you generally just get a number. When the touch sensor is touched, this value changes. When that change crosses a certain value (the threshold), then it's considered to be triggered.
|
em...Thank you for your answer. >>> import machine
>>> from machine import Pin
>>> t = machine.TouchPad(Pin(32))
>>> t.read()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Touch pad error Could you please help me again about Touc pad error? |
@nickzoic |
It works for me on all pins mentioned (0,15,32,33) with the latest release:
The ESP32 PCB I'm using is custom and none of the aforementioned pins are connected to anything. The pin read values returned are all different, but within the expected range. |
Mystery Solved (probably)Using MP @51482ba92568a9793fea34213ed74be850920a5a (HEAD as of today): import machine
tp = {}
for i in (4,0,2,15,13,12,14,27,33,32):
tp[i] = machine.TouchPad(Pin(i))
for i,t in tp.items():
try:
print (i, end=' ')
print (t.read(), end = '')
except:
print ('error', end = '')
finally:
print() Result:
Here's whyI've checked the schematic for my board: GPIO0 is connected to an auto-reset circuit |
It's likely that the pin you're using on your PCB is already connected to something (likely internal to the PCB), resulting in an error (see above). You should use a different pin. |
@fuermohao thanks for reporting this, although this might not be quite the right place for it ... What board are you using, or if it is a custom board could you let me see a schematic? I'll check it out, but the pins work with a free-running oscillator, so just about anything connected to them, even pullups/pulldowns and LEDs, will prevent the oscillation from happening at all. I'm not sure whether this will produce the error you mentioned, but I'll check ASAP & we can add this EDIT: ... "& we can add this to the documentation", I meant to say :-) |
MTDO (gpio15) is a strapping pin used for timing of the SDIO slave... |
@MrSurly esp32.wake_on_touch(True)
machine.TouchPad(Pin(32)).config(200)
machine.deepsleep() These codes don't seem to work |
Note 1: Copied over from the old micropython-esp32 repo.
Note 2: Fixed the 1970/2000 bug in
RTC.datetime()
Current API:
Basic sleep
machine.sleep()
is implemented, but currently throws an error. If/when the IDF "light sleep" works, this can be removed.EXT0 wakeups, using the common Micropython idiom
EXT0 wakes are for a single pin, either high or low level.
This is separate from the IRQ handler; the
WAKE_LOW
andWAKE_HIGH
only setup the EXT0 type wake. Using a value other thanWAKE_LOW
orWAKE_HIGH
will clear the EXT0 wake from that pin.Additionally, any EXT0 wake will fail if
esp32.wake_from_touch(True)
has been called, since wake from touch and EXT0 are mutually exclusive in the IDF.Other changes to
machine
machine.reset_cause()
has been implemented, though usually returnsmachine.WDT_RESET
since most of the time the IDF doesn't reset properly. Does properly returnmachine.DEEPSLEEP_RESET
when waking from deep sleep.machine.wake_reason()
has been implemented.The new top-level
esp32
moduleesp32.wake_on_touch(<True|False>)
Configures waking on touch. ThrowsValueError('no resources')
in the event that EXT0 is already configured, since they are not compatible. For this to work, you need to usemachine.TouchPad().config()
to configure the threshold; an interrupt handler is not required.esp32.wake_on_ext0(<Pin>, level = <0 | 1>)
. Configures the EXT0 wake. This will raiseValueError('no resources')
ifesp32.wake_on_touch(True)
has been called. It will not raise this error if another pin has already been configured, it will simply configure the new pin for EXT0 and deconfigure the old pin. If level is not specified, then it is unchanged, and defaults to 0 (low).esp32.wake_on_ext1(pins = <sequence of Pin object>, level = <esp32.WAKEUP_ALL_LOW | esp32.WAKEUP_ANY_HIGH> )
: As described above, wake on multiple pins, either "all low" or "any high".The new
machine.RTC
modulemachine.RTC.datetime()
andmachine.RTC.init()
work as documented in mainline MicroPython.machine.RTC.memory()
Without arguments returns the RTC nonvolatile memory, asbytes
. To write memory, pass abytes
,bytearray
, orstr
object.