COM port lost after uploading code on MKR Wan 1300

I bought an ARDUINO MKR WAN 1300 for the LORA functionnality because I want to discuss with another microcontroller through this communication, get some data and save it on a SD card through the dedicated shield.
But I also want to reduce the current consumption of my arduino because I just have to use it 30 seconds each hour, and turn it into sleep mode for the rest of the hour (using the RTC library for example) and because I am using a car battery (with the correct voltage adapter) to alimentate it.
But, after uploading some code using this library, the computer loose the COM port as soon as the arduino turn into standby mode. So I can't debug with the console using some "print" lines. I didn't read anything about this on forums, each time it is just a problem of printing debug messages and not the loss of the COM port.
I already tried to upload other sketchs without using this library and I get the debug message on the console.
Thank you in advance for any help you can bring me on.
Best regards.
Here is my code I found on the web for people for who it was worked:

#include <RTCZero.h>

/* Create an rtc object */
RTCZero rtc;

/* Change these values to set the current initial time */
byte seconds = 0;
byte minutes = 00;
const byte hours = 17;

/* Change these values to set the current initial date */
const byte day = 17;
const byte month = 11;
const byte year = 15;

// ISRs require them to be "volatile"
volatile bool needToSleep = false;
volatile bool sleeperChange = false;

int ledState = LOW;

void setup()
{
  // open the serial port at 9600 bps:
  Serial.begin(9600);
  
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, ledState);
  //Serial.println("Buff is full, t.i. stopped"); 

  rtc.begin();

  rtc.setTime(hours, minutes, seconds);
  rtc.setDate(day, month, year);

  rtc.setAlarmTime(17, 00, 10);
  rtc.enableAlarm(rtc.MATCH_SS);

  rtc.attachInterrupt(alarmMatch);

  rtc.standbyMode();

}

void loop() {
 if (needToSleep) {
   
   Serial.println("Go to sleep mode");
   // clear the flag
   needToSleep = false;
   

  if (sleeperChange == false) {
    seconds = 50; //means: call in 20sec (01:10 - 00:50)
    rtc.setTime(hours, minutes, seconds);
  }
  else if (sleeperChange == true){
    seconds = 30; //means: call in 40sec (01:10 - 00:30)
    rtc.setTime(hours, minutes, seconds);  
  }
  if (sleeperChange == false) sleeperChange = true;
  else sleeperChange = false;
   
   rtc.standbyMode();    // Sleep until next alarm match
 }
}

void alarmMatch()
{
  if (ledState == LOW) ledState = HIGH;
  else ledState = LOW;

  digitalWrite(LED_BUILTIN, ledState);   // turn the LED on (HIGH is the voltage level)

  // set the sleeping flag
  needToSleep = true;
}

Hi @goczilla

That's normal behaviour for a board that uses its native USB port to connect to your host computer. If the microcontroller goes to sleep, its USB module powers down and the COM port connection is lost. Waking up doesn't reestablish connection with the host's driver.

If you require the COM port connection to stay alive then it's necessary to use an intermediary processor/FTDI 3.3V USB-to-Serial board, connected to the SAMD21's Serial1 port and use that for debug instead.

Thank you for the answer. I will try to debug with the SD card so printing some message in a text file. Because I have not the money to buy another module. But thank you for he answer I keep in mind it for the future ! Best regards.

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