Page 1 of 1

pico sleep modes

Posted: Wed Oct 06, 2021 6:15 am
by KJM
I really like the detective work that has gone into https://ghubcoder.github.io/posts/awaking-the-pico/ & its promise of 1.3mA sleep with wakeup from an internal timer. Unfortunately I only know micropython, no C++ experience.

Would the code have to be re-written in micropython to be usable in micropython or could it be run somehow using pioasm or some other technique for running C++ code from within a micropython program?

Re: pico sleep modes

Posted: Wed Oct 06, 2021 12:38 pm
by hippy
It is not clear what part of that effort you need or want to use but it seems to me the best way would be to include the required code in a MicroPython C Extension Module and include that in your own MicroPython build.

Others would be able to create such a C Extension for you if you can indicate what code should be included, how you want to call it.

I had embarked upon doing that after a similar post to the Raspberry Pi Pico forum, but haven't done much, and would need those details to know what it should include.

Re: pico sleep modes

Posted: Wed Oct 06, 2021 10:34 pm
by KJM
I just want to use the pico to take a sensor reading then sleep itself for a nominated time before taking the next reading, I guess I was thinking something like machine.deepsleep(nominated time). The thought of a custom build fills me with trepidation. Is there no way for micropython to call C++ code as a subroutine or def function? https://docs.micropython.org/en/latest/ ... dules.html sort of suggests that a C++ program in a .mpy file can be imported without doing a custom build?

Re: pico sleep modes

Posted: Wed Oct 13, 2021 6:21 pm
by hippy
C Extensions are an integrated part of MicroPython so have access to pretty much anything. But one needs a custom build to include one's own.

Native C Modules from which a '.mpy' file can be created, and used just by placing it on the file system, allows C code to be used without a custom build, but the problem is that such modules don't have access to everything.

I am guessing you will want to call library functions in the Pico SDK to do what you want and I doubt they will be available for use in such a Native C Module.

Rebuilding custom firmware, adding your own C Extensions, isn't that hard, and there's help at hand for doing that.