Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    How to use deep sleep in a loop

    Scheduled Pinned Locked Moved Discussion
    deep sleeplopy4pytrack
    11 Posts 6 Posters 1.4k Views 6 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • nespressifN Offline
      nespressif
      last edited by

      Hello @james-matthews , I don't know exactly what you want to do, but deep sleep is always used as the last function of the program, that is, you do what you want and as last instruction you put machine.deepsleep(300000). Your code will run and then the module will sleep for 5 minutes, when that time ends will be restarted and run again from the beginning, ie reset.

      Therefore, I don't think you need while nor time in your code.

      Greetings,

      1 Reply Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @james.matthews
        last edited by

        @james-matthews when the device wakes up from machine.deepsleep(), runs through the reset stages. So you cannot simply put deepsleep() into a loop like you would do with sleep(). Before deepsleep() you have to save your execution stage, after reset check the reset cause, and then resume the state you code had before deepsleep().

        1 Reply Last reply Reply Quote 0
        • J Offline
          jcaron
          last edited by

          @james-matthews just to clarify, deep sleep achieves very low power consumption by powering down nearly everything on the chip, including the cores and all associated state (registers) and RAM.

          So once it exists deep sleep, it doesn't remember a thing, and it has to start from scratch again, so you need to maintain any state you need across sleep in long-term storage (if you need any state at all).

          1 Reply Last reply Reply Quote 1
          • J Offline
            james.matthews
            last edited by

            Thanks for the help everyone, getting rid of the loop and using machine.deepsleep(300*1000) at the end of the code worked perfectly. The next problem I have, how do I save the state & reload a state?

            Thanks

            J 1 Reply Last reply Reply Quote 0
            • J Offline
              jcaron @james.matthews
              last edited by

              @james-matthews Depending on your needs, you could use pycom.nvs_set or one or several files stored on flash.

              Note that there are caveats with the latter option (number of writes to flash, not crashing the filesystem...).

              You could also use an external battery-powered NVRAM/RTC.

              1 Reply Last reply Reply Quote 0
              • D Offline
                devinv
                last edited by

                my sipy (on a pytrack) never wakes up when sent to DeepSleep
                Do you have a ultra simple code which send it to Deep Sleep for a few secondes which works?
                Thanks

                J 1 Reply Last reply Reply Quote 0
                • J Offline
                  jcaron @devinv
                  last edited by

                  @devinv Are you sure it doesn't wake up, or do you just not see it? If you have very little code with no visible effect before you go back to sleep, you may not even notice it wakes up.

                  So for instance the following code:

                  machine.deepsleep(10 * 1000)
                  

                  is a perfectly valid deep sleep loop, but you will have a hard time noticing the SiPy waking up!

                  Also, are you using machine.deepsleep or Pytrack-assisted deep sleep? The latter will shut down USB, and it'll take a few seconds for USB to come back up and to be able to connect again, so there again, if you don't keep the device awake for several seconds you won't notice it waking up.

                  The best option to actually confirm it's working is probably to turn on the LED on boot and wait for at least a few hundred milliseconds before going to deep sleep. Alternately, monitoring current consumption should also show a spike on wake up.

                  Share your code (along with the version of the SiPy firmware and Pytrack firmware, and the Pytrack libraries if you use them) if you want feedback.

                  D 1 Reply Last reply Reply Quote 0
                  • D Offline
                    devinv @jcaron
                    last edited by

                    @jcaron actually machine.deepsleep does work.
                    it put my sipy to sleep and restart the program
                    But the pytrack is not sleeping and is consuming a lot.
                    what should I use to put both of them to deepsleep?

                    rcolisteteR 1 Reply Last reply Reply Quote 0
                    • rcolisteteR Offline
                      rcolistete @devinv
                      last edited by

                      @devinv See the docs of deepsleep for PyTrack.

                      My "MicroPython Samples". My "MicroPython Firmwares" with many options (double precision, ulab, etc).

                      D 1 Reply Last reply Reply Quote 0
                      • D Offline
                        devinv @rcolistete
                        last edited by

                        @rcolistete I did.
                        And here is the result : https://forum.pycom.io/topic/4153/sipy-pytrack-deepsleep-and-power-consumption-problem
                        Can you help me?

                        1 Reply Last reply Reply Quote 0

                        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                        With your input, this post could be even better 💗

                        Register Login
                        • 1 / 1
                        • First post
                          Last post

                        Pycom on Twitter

                        Pycom