Raspberry Pi Pico Deep Sleep Low Power Tutorial | Rising Signal Wake-Up on the RP2040

แชร์
ฝัง
  • เผยแพร่เมื่อ 13 มิ.ย. 2024
  • In this video, we explore different "deep sleep" methods on the Raspberry Pi Pico RP2040. By putting the processor into a "deep sleep" we can use less power during times where executing code isn't important. Deep sleep on the RP2040 allows us to use less power and ultimately make our Raspberry Pi Pico projects way more efficient.
    Check out my channel for more videos like this on the Raspberry Pi Pico, ARM Assembly, debugging, and much much more!
    Buy the RP2040: amzn.to/3uISUGn
    Chapters
    0:00 Intro
    0:11 Baseline
    1:10 Sleep?
    1:49 How Does Sleep Work?
    2:38 Deep Sleep Library
    3:00 RTC Alarm Sleep
    4:44 Rising Edge Deep Sleep
    6:39 Outro
    #raspberrypi #raspberrypipico #rp2040
    Join us on Discord: / discord
    ===
    yeah and you'll see here the results are pretty disappointing actually we lose a little bit of current which means that the power has gone down a little bit but we're still pulling in the same amount of power as just no opting in a loop so you gotta ask why does that happen well let's dive into the instructions of the actual sleep code and see how that works so here we are in the picosdk we're actually at the code that executes the sleep ms function sleep ms is just sleep milliseconds and it ends up just calling sleep microseconds with your time times a thousand if you go to the sleep microseconds function that is just a sleep until function if alarm pools are not disabled which they're not by default and then if you actually go into the code after a couple checks get done to see if you've gotten to the point where you should be done sleeping the code is just the wfe micro instruction which is an assembly instruction in c um and wfe is just wait for event which executes as a knob on the target so again our sleep functionality which you would think gives you lower power consumption faster code execution while sleeping no it's just a knob now when i was making this video i was starting to get really disappointed because i felt like there was no code in the pico sdk library that actually implemented the deep sleep functionality of the arm cortex processor but then in looking around i discovered that raspberry pi put out this extra library literally called pico extras and it exports this sleep interface and the sleep interface has some functionality one of them is a sleep go to sleep until where you can specify a real-time counter alarm and a callback to execute once the alarm has gone off and within this api they actually use the deep sleep functionality of the processor and you'll see here in a second the power consumption is significantly lower so basically what this code does here i'll kind of walk y'all through it we turn the processor on it is not awake we put it into real-time clock sleep we basically say that this is the date now and then we say that this is the time we want to wake up which is just this previous date 10 seconds later we initialize the real time clock and then we set the date time to the time we say it is and then we say go to sleep until this alarm goes off and when it goes off execute the sleep call back the sleep callback just says the global variable awake is true and what that does for us is that means that we should never get here because we should be sleeping until we are awake
    ===

ความคิดเห็น • 73

  • @LowLevelLearning
    @LowLevelLearning  3 ปีที่แล้ว +41

    The power consumption in the tight_loop_contents(...) test is 95.7mW, for some reason my video editor decided to cut it out and I missed it D:

    • @trya2l
      @trya2l ปีที่แล้ว

      Thanks! After a few months, going back through this video, I'm starting to understand its value. Good low-level job 👍

    • @niewazneniewazne1890
      @niewazneniewazne1890 หลายเดือนก่อน

      Baseline: 95.7mW
      Sleep: 85.8mW
      RTC sleep: 33mW -> 85.8mW -> 33mW -> ...
      Rising edge sleep: 6.6mW, 13.2mW

  • @hclchgm
    @hclchgm 2 ปีที่แล้ว +9

    Finally something useful from someone who isn't trying to sell me a device.

  • @WisseSpring
    @WisseSpring 3 ปีที่แล้ว +31

    Thanks for doing this tests! Would like to add, for those that are not very familiar with this topic, that 6 mW draw in sleep is not low by modern standards. Low power was definitely not a priority with RP2040, but there are many ARM microcontrollers out there that can go down to a few uW during (useful) sleep. Just something to keep in mind if one ever considers a project powered by a small battery that shouldn't go dead in a few days.

    • @LowLevelLearning
      @LowLevelLearning  3 ปีที่แล้ว +5

      Good to know, thank you!

    • @tonysofla
      @tonysofla 2 ปีที่แล้ว +1

      But where is the power draw from? I assume you can turn off core sysclk? and only run a timer on 32KHz that when its ISR wakes up, the core starts running on hfrc first until PLL is ready? as I assume you can turn off the two PLL's? as those are a power hog. Can you turn off ram banks to save power?

    • @MrGamelover23
      @MrGamelover23 2 ปีที่แล้ว

      Can you give me some examples? i'm interested in creating a modern version of the alphasmart word processors. there's nothing wrong with them, they were just discontinued like over a decade ago. i'm thinking an e-ink display and fonts for every single language in the world. Something that I can have 700 hours of use if you're a slow typist by going into sleep mode between each case stroke. My idea is to basically make it stand alone without a keyboard so it can sell for a lot cheaper and you can use whatever typing experience you prefer, we had a cheap membrane keyboard or a $300 split ergonomic mechanical keyboard.

    • @WisseSpring
      @WisseSpring 2 ปีที่แล้ว +3

      @@MrGamelover23 Looking at what e-readers use would be a good starting point. Your product seems ambitious enough to benefit from one of the "application processors" (e.g. Cortex-A family), which are more powerful and can run OS like Linux, as opposed to microcontrollers (e.g. Cortex-M family), which are not really meant to handle complex, modern user interfaces. This is very important design choice that requires thorough investigation! I sadly don't have any experience with Cortex-A parts. Microcontrollers that I brought down or under single digit uW in sleep were from NXP (Kinetis family) and Nordic (nRF52 family). I know for a fact that there's a whole plethora of parts from different manufacturers that could do the same.

    • @MrGamelover23
      @MrGamelover23 2 ปีที่แล้ว

      @@WisseSpring the original alphasmart neo could go for $700 off of 3 AA batteries. That's why I think it might be better to be a single software instead of a software running within an os. it doesn't exactly need a complex user interface, but you're right that is something that requires thorough investigation. Thank you. The neo used a 33MHz DragonballVZ, which is a 68000-based processor made by Freescale/Motorola. Any idea what the modern equivalent would be? (The VZ saves every keystroke to RAM, which is unnoticeable in operation but makes it quite important to keep a fresh coin cell on board.) Edit: apparently this is the family of processors that replaced it en.m.wikipedia.org/wiki/I.MX

  • @test40323
    @test40323 2 ปีที่แล้ว +2

    A very useful tip for a data collector in the field.

  • @pro-nav
    @pro-nav 3 ปีที่แล้ว +8

    Nice, Do USB host next, maybe PIO, or RTC? There are so many things to do with this little guy. Great Video as always.

  • @hardware4200
    @hardware4200 ปีที่แล้ว

    This content is amazing.

  • @yahmk3978
    @yahmk3978 2 ปีที่แล้ว

    Thank you very much!

  • @ashleycawley5816
    @ashleycawley5816 ปีที่แล้ว

    Really enjoyed that, thank you for sharing and presenting it all so nicely. Out of curiosity what make/model is the bench power supply you're using there? I've never owned one but I'm thinking of getting one, I don't want one which is too big or bulky but that looked a nice size.

  • @DrJonD
    @DrJonD ปีที่แล้ว +1

    Nice video. Should be noted that pico extra is experimental code. Clocks are not returned to normal state after return from sleep. My tests and others online are unable to get returning from sleep/dormant repeatable which is annoying.

  • @JavaMike71
    @JavaMike71 2 ปีที่แล้ว +4

    This was quite helpful, thanks for the detail in the video. Have you tested anything like a simple sensor and running on battery power? I have an infrared sensor that I want to use on battery with the Pico, but I would need it to last 1-2 weeks on low usage. Any thoughts on that or trials you have done?

    • @LowLevelLearning
      @LowLevelLearning  2 ปีที่แล้ว +3

      Unfortunately not yet, but I plan on doing some longer form project videos with the Pico where I might experiment with battery capacity.

  • @pup4301
    @pup4301 3 ปีที่แล้ว +4

    Thank you. Can be used when using a low power battery.

    • @LowLevelLearning
      @LowLevelLearning  3 ปีที่แล้ว +1

      Exactly!

    • @tonysofla
      @tonysofla 2 ปีที่แล้ว +1

      A Coincell battery like CR2450 (600mAh), say you sleep 95% at 0.18mA and a awake 5% at 10mA (not including bright LED etc) = 36days.
      not good but you would not use something this powerful as a Pico with a coin cell product, on the other hand using a 5000mAh USB power bank = 306 days.

    • @pavelperina7629
      @pavelperina7629 2 หลายเดือนก่อน

      @@tonysofla Maybe I missed something, but it's 2mA@3.3V which is not great. Spec says something like 0.8mA@5V, With 3x NiMH or alkaline battery that has 2500mA capacity, it's very roughly about 1000 hours or a month. But it's hard to say how it's measured, from scheme there's 10+5.6K voltage divider on VBUS which is the first problem - this is 0.3mA at 5V.
      EDIT: ops there are specs for RPI Pico (stating what I wrote) vs RP2040 core (stating yours 0.18mA@1.1V) which makes 0.2mW vs 4mW difference.

    • @tonysofla
      @tonysofla 2 หลายเดือนก่อน

      @@pavelperina7629 specs of the RP or the development board as a whole? If 5V battery powered connect that at VSYS, or if 4.2V tolerant connect a lithium at 3V3.
      RP is not really made for ultra-low power as it does not have 32K crystal support.

    • @pavelperina7629
      @pavelperina7629 2 หลายเดือนก่อน

      @@tonysofla Yep. I was considering replacing old arduino micro pro with rpi for data logger project if possible. First to learn something new and second it's cheaper and more capable. And use of Arduino is also hit and miss, it depends on voltage regulators it uses.

  • @MattFixesStuff
    @MattFixesStuff 2 หลายเดือนก่อน

    Thanks for the video. I keep coming back to it :D
    is there any updates on this (using Arduino IDE) ?
    I still have picos lying around I wonder if the implementation changed or was improved in the meantime.
    I switched to the esp32 that comes with 150 µA deep sleep mode that doesnt require any extra libraries. But I still also like the pico but avoided it so far for battery projects.

  • @daedalus5483
    @daedalus5483 10 หลายเดือนก่อน

    Total newbie here; would you recommend using a Pico (W) for a battery powered project in combination with an e-paper display in a lora (mesh) configuration? Hard to tell what the wake / sleep ration is because I'm not sure how (often) lora nodes can / should relay messages. In a normal use case, the board receives instructions, displays some stuff and waits for some sort of acknowledgement, sleeps for ~ 5 - 10 minutes, sends input from the node and then goes back to sleep. While it wakes up, it should remember its "state" (or know to request the last state from the "server").

  • @SobhitPanda
    @SobhitPanda 2 ปีที่แล้ว

    Can you share some nice resources on Low Power IoT and RTOS, like the books or courses you took to learn them.

  • @kimrnhof107
    @kimrnhof107 4 หลายเดือนก่อน

    WOW

  • @murmanmurman
    @murmanmurman ปีที่แล้ว

    I don't see the full picture here. For me I see that on resume (from sleep_goto_dormant_until_edge_high()) some clocks are degraded by a factor 10 and the performance is also lost by this factor. It possibly could be seen in the tight loop if some "clock_get_hz(.. enumed clock.. ) was present. For me I also have core1 going and I don't know if that is messing things up.

  • @thesidneychan
    @thesidneychan 2 ปีที่แล้ว

    From the title my first thought was there's a lo fi Pi ASMR beats thing to sleep to.

  • @Vikassy
    @Vikassy 16 วันที่ผ่านมา

    Thanks for sharing. But I can't seem to find any way to add the pico extras library to Arduino.

  • @bergflyer6499
    @bergflyer6499 2 ปีที่แล้ว

    Nice video! Wish these sleep modes would be supported in the Pico Python SDK. Both, machine.lightsleep and machine.deepsleep don't seem to help much in reducing power consumption. My only effective way of reducing power consumption under Python was to reduce the MCU clock frequency. Going down to 10MHz, my Pi Pico board consumed 4.5mA, vs. 21.4mA at standard f(clk). But you need to make sure you crank it back up to 125MHz before your Python code finishes, to make the USB i/f work properly.

    • @conorstewart2214
      @conorstewart2214 2 ปีที่แล้ว

      That’s probably a limitation of micro Python itself, does sleep work correctly on the esp32 using micro Python? The reason it doesn’t work at least with the pico is probably because it always needs to run the interpreter at all times, to decide what to do and it might be difficult but not impossible to sleep the interpreter too. They may have decided that anyone programming in Python doesn’t care as much about performance or power consumption which to be fair if you are serious about either then you’d use a compiled language like c or rust anyway.

    • @bergflyer6499
      @bergflyer6499 2 ปีที่แล้ว

      @@conorstewart2214 Agreed, Low Power Apps might not have been high on the list when creating the MicroPython build for RP2040. However, the interpreter is an 'overhead' part of the Python script code that runs on the RP2040, not running as a separate thread. To resume a script after a sleep, the RP2040 needs an interrupt from either its Timer module or an external (e.g. GPIO) source. That's part of the current MicroPython implementation, so I can't think of a showstopper to make lightsleep() a real power saver function in MicroPython, including the clock switch to XOSC and back, like it's possible in C.

  • @niewazneniewazne1890
    @niewazneniewazne1890 หลายเดือนก่อน

    Baseline: 95.7mW
    Sleep: 85.8mW
    RTC sleep: 33mW -> 85.8mW -> 33mW -> ...
    Rising edge sleep: 6.6mW -> 13.2mW

  • @DuyPham-eg2cc
    @DuyPham-eg2cc ปีที่แล้ว

    Thanks for doing this tests! Can you tell me what CMakeList file you write in it?

    • @sotw1610
      @sotw1610 ปีที่แล้ว

      I have the same question

  • @dragonofmissingno170
    @dragonofmissingno170 3 ปีที่แล้ว +1

    I'm still wanting to get a few Pi Picos. They are starting to be more in stock at the nearest Micro Center which is about an hour away. (Depending on traffic) Just don't have the money to spend atm.
    Besides, I still have some ATmega based arduinos to mess with for lower processing projects.
    I do think it would be fun to turn a Pico into a fantasy handheld console instead of yet another emulation box. A decently fast SPI screen, some buttons, and a DAC should be more than enough. Maybe even an SD card port to load the "ROMs" from.
    Do you think the Pico would be powerful enough to have one core be the main loading and processing for games and the other create GBA like graphics and sounds?

    • @pro-nav
      @pro-nav 3 ปีที่แล้ว

      If you have cheap PCB manufacturing and shipping available then you should definitely make a custom handheld gaming console like the ones sold by Adafruit. It would be a great project.

    • @LowLevelLearning
      @LowLevelLearning  3 ปีที่แล้ว

      Yeah they became hard to get very fast

  • @_mwalker
    @_mwalker 3 ปีที่แล้ว +1

    Perhaps this isn't as easy as I'd think (hope) it is, but how do you go about porting across libraries to run on Pico? E.g. I2Cdevlib or RF24.

    • @LowLevelLearning
      @LowLevelLearning  3 ปีที่แล้ว +1

      It really depends what the library does. If its something simple like crypto or maybe an I2C parser then you can trick CMake into building it into your project. Anything that relies on hardware directly wont work.
      The pico-sdk links in parts of glibc, so if your library sits on top of that, youre good

    • @_mwalker
      @_mwalker 3 ปีที่แล้ว +1

      @@LowLevelLearning take the I2Cdevlib for example. It's written predominantly for Arduino. There is libraries for specific chips with a I2C file that deals with read/write separately. Hence would it just be a case of altering this to use Pico I2C and including in CMakeLists, or is there something more that I'm missing? Apologies if this is an obvious question.

    • @wayland7150
      @wayland7150 ปีที่แล้ว

      Yeah, don't port libraries, look for similar libraries on the pico. You will have to alter your program to use the pico libraries.

  • @FirstLast-ih6ec
    @FirstLast-ih6ec 3 ปีที่แล้ว +1

    What IDE do you use for the PIco examples?

    • @LowLevelLearning
      @LowLevelLearning  3 ปีที่แล้ว

      No IDE, just Sublime Text and a command line.

  • @aratroniccnc
    @aratroniccnc 2 ปีที่แล้ว +1

    Hi, what IDE you use for programming pico?

  • @juanmontes8905
    @juanmontes8905 2 ปีที่แล้ว

    someone can test if RTC is still working this Deep Sleep method? Thanks!

  • @tonysofla
    @tonysofla 2 ปีที่แล้ว +2

    I prefer using mA and uA and not mW.
    So dormant mode is 180uA per data sheet, a little high as smaller MCU Cortex sleeps around 2uA-5uA.
    I guess the 264KB of RAM is the reason, they should had implemented the option to just have one bank on during dormant sleep.
    A 2000 mAh lipo and doing 98% sleep is still a year worth, as 2000*1000uA/180uA/24hrs = 416days of just sleeping and not taking it to account battery self-discharge.

    • @slimhazard
      @slimhazard 2 ปีที่แล้ว +3

      The RP2040 chip on the pico does have the means to turn off SRAM and the USB DPRAM, see section 2.11.4 of the RP2040 datasheet. But there is no support for it in the SDK, other than the fact they provide structs that wrap the hardware registers, which you can use to set the necessary bits. Manipulating the registers isn‘t actually that hard, if you read the docs carefully to get it right; but it would be nice to have SDK code that gets it right for you.
      They mention in that chapter of the datasheet that you can also turn off the flash cache, but that it probably won‘t save you much power when it‘s fetching code from flash anyway.
      The sleep source code in pico-extras mentioned in the video has this comment:
      // TODO: Optionally, memories can also be powered down.
      So it looks like they released the pico and the SDK with some of the power-saving support on the SDK to-do list. More may be coming up in future versions.

    • @tonysofla
      @tonysofla 2 ปีที่แล้ว

      @@slimhazard I see that dormant options is ram-static-mode, not power down mode , that if some ram banks complete loss of data was OK, could save more power if it was implemented.

    • @erdem--
      @erdem-- 2 หลายเดือนก่อน

      ​@@tonysofla MEMPOWERDOWN register actually disables all ram. But it is not possible to go dormant because all ram was power down a few cycles ago. If there was a way to set irq bits and mempowerdown at the same time, we can make a very low power rp2040.
      And i guess it is not possible to use external low voltage source for ram power.

  • @Cptnbond
    @Cptnbond 3 ปีที่แล้ว +1

    Quick question, which IDE are you using?

    • @LowLevelLearning
      @LowLevelLearning  3 ปีที่แล้ว +1

      No IDE, just Sublime Text and a command line

  • @localixdots9698
    @localixdots9698 9 วันที่ผ่านมา

    RP2040 Minimal achievable power consumption is 0.18mA in “Dormant” and 0.39mA in “Sleep” modes. See RP2040 datasheet, section 5.7 Power Consumption. Your consumption is 3 mA, why?

  • @Lugeix
    @Lugeix ปีที่แล้ว

    Still too high for some function. The ESP can achieve 3uA at 3.3V = about 20uW. I was hoping to get the Pico W to that level to conserve battery.

  • @gammaray4850
    @gammaray4850 3 ปีที่แล้ว

    you can use "no-button-boot" in pico, that pulling pressing plugging process is very annoying.

  • @anthonypeters1797
    @anthonypeters1797 2 ปีที่แล้ว

    is this only in C?

  • @ObligedTester
    @ObligedTester ปีที่แล้ว

    Very interesting demonstration of the different sleep modes.
    However I think it is very difficult for the power supply to accurately measure and show real life current draw in this situation.
    The pico uses a onboard buck-boost SMPS which is probably operating at a frequency which can not be sampled by the psu current display.
    This might pose a risk to either over or under estimating the current draw

  • @ozanh
    @ozanh ปีที่แล้ว

    There is one thing. I'm trying to use this library but the problem is when the pico wakes up it starts running the code so slow, idk maybe processor slows down but definitely something happens. Does any one experienced this issue with a real world project?
    (Updated question, read below)
    Yes guys, keep in mind when the pico wakes up, clocks are not functioning well, here is the before after output
    Clock speeds before after
    Before sleep:
    PERI: 125000000
    GP0: 0
    GP1: 0
    GP2: 0
    GP3: 0
    REF: 12000000
    SYS: 125000000
    USB: 48000000
    ADC: 48000000
    RTC: 46875
    After wake up:
    PERI: 12000000
    GP0: 0
    GP1: 0
    GP2: 0
    GP3: 0
    REF: 12000000
    SYS: 12000000
    USB: 0
    ADC: 0
    RTC: 46875

  • @anthonypeters1797
    @anthonypeters1797 2 ปีที่แล้ว

    how do i get this is python

    • @BrianG61UK
      @BrianG61UK 2 ปีที่แล้ว +3

      Don't use a toy language. Switch to C.

    • @duckyblender
      @duckyblender 2 ปีที่แล้ว +1

      @@BrianG61UK based

  • @amazingpower2761
    @amazingpower2761 ปีที่แล้ว

    you have had way too much coffee! duh, the sleep function is just a loop!