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;
}