{"id":17884,"date":"2025-07-27T21:13:55","date_gmt":"2025-07-28T01:13:55","guid":{"rendered":"https:\/\/scruss.com\/blog\/?p=17884"},"modified":"2025-07-27T21:13:55","modified_gmt":"2025-07-28T01:13:55","slug":"lightsleep-vs-deepsleep-on-raspberry-pi-pico","status":"publish","type":"post","link":"https:\/\/scruss.com\/blog\/2025\/07\/27\/lightsleep-vs-deepsleep-on-raspberry-pi-pico\/","title":{"rendered":"lightsleep vs deepsleep on Raspberry Pi Pico"},"content":{"rendered":"\n<p class=\"has-accent-3-color has-text-color has-link-color wp-elements-a74c8656976e184eabe3794b13db2997\"><em>Hey! This code situation may be changing soon, but this article was written about MicroPython v1.25.0 on RP2040. The situation on the Raspberry Pi Pico W \/ 2W \/RP2350 might be quite different.<\/em><\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Deep Sleep (Party Mix Abum Version)\" width=\"500\" height=\"375\" src=\"https:\/\/www.youtube.com\/embed\/abTCB5OWwc4?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>Many micro-controllers have timed energy-saving modes you can engage when they are idle. These are typically one of:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>light sleep<\/strong>: where memory contents are retained, but some parts of the CPU and peripherals are turned off  to reduce current;<\/li>\n\n\n\n<li><strong>deep sleep<\/strong>: memory is cleared, most of the CPU and peripherals are powered off. The CPU will reset fully on restart, so your program has to reload.<\/li>\n<\/ul>\n\n\n\n<p>While MicroPython on the RP2040 has both <kbd>machine.lightsleep()<\/kbd> and <kbd>machine.deepsleep()<\/kbd> functions, there&#8217;s not much difference between them. In fact, the <a href=\"https:\/\/github.com\/micropython\/micropython\/blob\/ebc9525c953dfbb6c44ab99320b5278e4314dafe\/ports\/rp2\/modmachine.c#L339\"><em>deepsleep()<\/em><\/a> routine is merely <em>lightsleep()<\/em> followed by <em>reset()<\/em>. So there isn&#8217;t any efficiency gain in using deepsleep over lightsleep.<\/p>\n\n\n\n<p>The functions take one argument: the sleep time, given in milliseconds. The largest value that is accepted is 4294966, or <kbd>(2**32 \/\/ 10**3) - 1<\/kbd>. That&#8217;s 71\u2032\u00a034\u2033. If you give a larger number, this exception is thrown: <br><kbd>ValueError: sleep too long<\/kbd>, and the function returns immediately.<\/p>\n\n\n\n<p>If you&#8217;ve used <kbd>machine.deepsleep()<\/kbd>, you might want to know whether your micro-controller was started by applying power, or started from the <em>reset()<\/em> after <em>deepsleep()<\/em>. The <kbd>machine.reset_cause()<\/kbd> function returns one of two values:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><kbd>machine.PWRON_RESET<\/kbd>: if the CPU was started from power on, or by briefly grounding the <strong>RUN<\/strong> pin;<\/li>\n\n\n\n<li><kbd>machine.WDT_RESET<\/kbd>: if the CPU was soft reset, either by a watchdog timer or other software reset. This is the state returned after <em>deepsleep()<\/em>.<\/li>\n<\/ul>\n\n\n\n<p>Other MicroPython ports have more nuanced ways of handling sleep and reset states with better power saving.<\/p>\n\n\n\n<p>If you&#8217;re running a tight polling loop and still wish to save a little power, <a href=\"https:\/\/docs.micropython.org\/en\/latest\/library\/machine.html#machine.idle\">machine.idle()<\/a> is the recommended method.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey! This code situation may be changing soon, but this article was written about MicroPython v1.25.0 on RP2040. The situation on the Raspberry Pi Pico W \/ 2W \/RP2350 might be quite different. Many micro-controllers have timed energy-saving modes you can engage when they are idle. These are typically one of: While MicroPython on the [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[3315],"tags":[3094,3346],"class_list":["post-17884","post","type-post","status-publish","format-standard","hentry","category-electronics","tag-micropython","tag-rp2040"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pQNZZ-4Es","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/17884","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/comments?post=17884"}],"version-history":[{"count":3,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/17884\/revisions"}],"predecessor-version":[{"id":17887,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/17884\/revisions\/17887"}],"wp:attachment":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/media?parent=17884"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/categories?post=17884"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/tags?post=17884"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}