Hi,
(Arduino IDE, RP2024 SDK with pico-extras sleep)
After exist from:
sleep_run_from_xosc();
sleep_goto_dormant_until_pin(...);
Serial.print() no works.
Thanks.
Hi,
(Arduino IDE, RP2024 SDK with pico-extras sleep)
After exist from:
sleep_run_from_xosc();
sleep_goto_dormant_until_pin(...);
Serial.print() no works.
Thanks.
Hello!
After using sleep_run_from_xosc() and sleep_goto_dormant_until_pin(...), Serial.print() might not work because the UART needs reinitialization. Try adding Serial.end(); followed by Serial.begin(115200); (or your desired baud rate) after waking up to fix this issue.
Hi !
I tried that too. It still does not work.
maybe worth giving the complete code and details of how you installed pico-extras
try the following RP2040 test which blinks LED and outputs to Serial and Serial1
on Serial.read() enters delay resumes on pin 2 taken HIGH
// Raspberry Pi Pico RP2040 blink and sleep test
// RP20040 blinks LED and outputs character to Serial and Serial1 every second
// on Serial.read() enters sleep resumes on pin 2 taken HIGH
// result LED blink and Serial1 output resumes OK no output on Serial
// https://github.com/raspberrypi/pico-extras/blob/master/src/rp2_common/pico_sleep/include/pico/sleep.h
//#include "hardware/uart.h"
//#include "pico/stdio/driver.h"
#include "sleep.h"
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200);
Serial1.begin(115200);
delay(5000);
Serial.println("\n\nRaspberry Pi Pico RP2040 blink test 1");
}
// the loop function runs over and over again forever
void loop() {
static char serial1Char='!';
Serial.print('*');
Serial1.print(serial1Char);
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
if (Serial.available()) {
while (Serial.available()) Serial.read();
Serial.end();
Serial1.end();
sleep_run_from_xosc();
// \brief Send system to sleep until the specified GPIO changes
// One of the sleep_run_* functions must be called prior to this call
// \param gpio_pin The pin to provide the wake up
// \param edge true for leading edge, false for trailing edge
// \param high true for active high, false for active low
// void sleep_goto_dormant_until_pin(uint gpio_pin, bool edge, bool high);
sleep_goto_dormant_until_pin(2, 1, true);
Serial.begin(115200);
Serial1.begin(115200);
serial1Char='$';
delay(1000);
}
}
on pin 2 high LED blink and Serial1 output resumes OK no output on Serial
e.g. Serial 1 output is "!!!!!!!$$$$$$$" - character changes after sleep
Serial is the USB serial for program loading and serial monitor and appears to be disabled after sleep
to load another program the USB has to be unplugged and plugged in
That is my code. LED toggle Ok (Off in sleep, On after exit from sleep)
But only the first Serial.println("Enter to sleep") works, one time.
#include <pico/sleep.h>
#include <hardware/rosc.h>
#include <hardware/structs/scb.h>
#define BUT 19
#define LED 0
void setup()
{
pinMode(BUT, INPUT_PULLUP);
pinMode(LED, OUTPUT);
Serial.begin(115200);
while(!Serial);
Serial.println("Start...");
digitalWrite(LED, HIGH);
}
void loop()
{
delay(1000);
Serial.println("Enter to sleep");
digitalWrite(LED, LOW);
uint scb_orig = scb_hw->scr;
uint clock0_orig = clocks_hw->sleep_en0;
uint clock1_orig = clocks_hw->sleep_en1;
Serial.end();
sleep_run_from_xosc();
sleep_goto_dormant_until_pin(BUT, false, false);
// restore clock
rosc_write(&rosc_hw->ctrl, ROSC_CTRL_ENABLE_BITS);
scb_hw->scr = scb_orig;
clocks_hw->sleep_en0 = clock0_orig;
clocks_hw->sleep_en1 = clock1_orig;
clocks_init();
Serial.begin(115200);
while(!Serial);
Serial.println("exit from sleep");
digitalWrite(LED, HIGH);
}
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.