SAMD21 SERIAL not WORKING AFTER WAKEUP

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.

thank you for your reply is there any way to still see the output on COM6 after reset?

Write a program on the PC that connects to every serial interface that pops up and read what is received there.

I'd have an easier solution for Linux but I have no clue how and if that can be translated into the Windows world.

can you show me plz how to do that on linux ? i have linux so i can run it on it

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.

p.e.

SUBSYSTEMS=="usb", ATTRS{idProduct}=="204b", ATTRS{idVendor}=="03eb", SYMLINK+="ttyMyProject", OWNER="root", GROUP="root", MODE="0777"

Of course you have to adapt the product and vendor ID and probably the symlink name.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.