SUCCESS !!!
Delved a bit deeper into how sleep.c
and hello_sleep
work, found where I was going wrong.
Used the on board LED to indicate the program states.
5.07V supply to VSYS
Pico startup with LED ON = 20.5mA, LED OFF = 19.1mA.
Pico sleep = 1.3mA.
Wake from sleep = 3.5mA. (some clocks not activated, USB, ADC, PLL, etc)
(see pics)
So power measured is the same as the datasheet. I can now use this in my project.
In Sleep mode the Pico starts execution from the line after it goes to sleep.
In Dormant mode the Pico essentially reboots, which is exactly what I want for my project.
Next test will be dormant mode.
Program code for putting Pico to sleep.
/**
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*
* Modified 29 Dec 2021
* Add on board LED indication of program state.
*/
#include <stdio.h>
#include "pico/stdlib.h"
#include "pico/sleep.h"
#include "hardware/rtc.h"
static bool awake;
static const uint LED_PIN = PICO_DEFAULT_LED_PIN;
static void sleep_callback(void) {
awake = true;
}
static void rtc_sleep(void) {
// Start on Friday 5th of June 2020 15:45:00
datetime_t t = {
.year = 2020,
.month = 06,
.day = 05,
.dotw = 5, // 0 is Sunday, so 5 is Friday
.hour = 15,
.min = 45,
.sec = 00
};
// Alarm 10 seconds later
datetime_t t_alarm = {
.year = 2020,
.month = 06,
.day = 05,
.dotw = 5, // 0 is Sunday, so 5 is Friday
.hour = 15,
.min = 45,
.sec = 10
};
// Start the RTC
rtc_init();
rtc_set_datetime(&t);
// LED OFF to indicate in sleep mode
gpio_put(LED_PIN, 0);
// start sleep, wake after RTC time interval
sleep_goto_sleep_until(&t_alarm, &sleep_callback);
}
int main() {
// setup on board LED
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
gpio_put(LED_PIN, 1);
// load standard IO and wait 2 seconds, LED ON
stdio_init_all();
sleep_ms(2000);
// Flash LED OFF then ON, 1 second each
gpio_put(LED_PIN, 0);
sleep_ms(1000);
gpio_put(LED_PIN, 1);
sleep_ms(1000);
sleep_run_from_xosc();
awake = false;
// start sleep cycle, LED should be OFF while in sleep
rtc_sleep();
// set LED ON to indicate end of sleep cycle
// if LED does not come on after about 10 seconds, indicates program error
if (awake) {
gpio_put(LED_PIN, 1);
} else {
gpio_put(LED_PIN, 0);
}
sleep_ms(2000);
return 0;
}
Make file for the program code.
# Set minimum required version of CMake
cmake_minimum_required(VERSION 3.12)
#include build functions from Pico SDK
include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)
# We also need PICO EXTRAS
include($ENV{PICO_EXTRAS_PATH}/external/pico_extras_import.cmake)
# Set name of project (as PROJECT_NAME) and C/C++ Standards
project(sleepy C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
# Creates a pico-sdk subdirectory in our project for the libraries
pico_sdk_init()
# point out the CMake, where to find the executable source file
add_executable(${PROJECT_NAME}
main.c
)
# create map/bin/hex/uf2 files.
pico_add_extra_outputs(${PROJECT_NAME})
# Pull in our pico_stdlib which pulls in commonly used features (gpio, timer-delay etc)
target_link_libraries(${PROJECT_NAME}
pico_stdlib
pico_sleep
)
# enable usb output, disable uart output
pico_enable_stdio_usb(${PROJECT_NAME} 1)
pico_enable_stdio_uart(${PROJECT_NAME} 0)
# create map/bin/hex/uf2 file etc.
pico_add_extra_outputs(${PROJECT_NAME})
# add url via pico_set_program_url
#example_auto_set_url(${PROJECT_NAME})
Make file for the sleep library, changed from the one currently in the Pico-Extras.
if (NOT TARGET pico_sleep)
add_library(pico_sleep INTERFACE)
target_sources(pico_sleep INTERFACE
${CMAKE_CURRENT_LIST_DIR}/sleep.c
)
target_include_directories(pico_sleep INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
target_link_libraries(pico_sleep INTERFACE hardware_clocks hardware_rosc hardware_rtc)
endif()
Regards
Jim