hello, i am working on a seeeduino xio which has a samd21G18 processor. i am trying to put the microcontroller to sleep and wake it up after 5 seconds but the problems is that after he wakes up the serial port doesn't print data anymore even though the led which refer to TX lights up every sent data. i am using the LowPower arduino library. here is the code so that you know what i am talking about, can anyone help me please
#include <Arduino.h>
#include "ArduinoLowPower.h"
#include "sam.h"
void dummy() {
// This function will be called once on device wakeup
// You can do some little operations here (like changing variables which will be used in the loop)
// Remember to avoid calling delay() and long running functions since this functions executes in interrupt context
}
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9200);
while (!Serial);
Serial.println("i am going into loop") ;
}
void loop() {
Serial.println("i am awake") ;
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
Serial.println("i am going to sleep now for 5 seconds") ;
Serial.flush();
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
LowPower.sleep(5000);
Serial.begin(9200);
while(!Serial);
delay(10);
}
The "Serial" object isn't actually a serial interface but an emulation of it on USB. The library you use correctly detaches and attaches the USB bus while sleeping so the problem is most probably on the PC side. You didn't tell us what operating system you use and what terminal program on the PC side (maybe the IDE's Serial Monitor). Because the USB device disappears and appears again on the bus it will be handled as if it's a new device. On most operating systems that means you have to access another virtual serial device to see the output.
hi thank you for replying to me, i am using a windows 10 pro, and for the ide i used arduino ide and tried also platformio. the problem is at first run the three messages are printed but after sleep and wake up again nothing is printed again. can u please explain to me more this "On most operating systems that means you have to access another virtual serial device to see the output."
I translate into the Windows language: After the sleep the Seeeduino isn't on COM5 anymore but on COM6 (actual values are just examples and must not exactly match your setup).
So the program showing you the serial output (I guess that's the Serial Monitor of the IDE) is still connected to the old virtual serial interface (in the example COM5) but the operating system is receiving on another virtual serial interface already.
Write a udev rule (file in /etc/udev/rules.d) that always creates a special device link when your seeeduino connects. That way you always have the same device path and just have to open that device once the path exists.