Go Down

Topic: No Serial using MKR1000, RTC alarms and standbyMode... any suggestions? (Read 808 times) previous topic - next topic

CowboySkippy

Hello Arduino forum,

I want Serial debug capability after the MKR1000 wakes from standbyMode, but I cannot successfully demonstrate this.  Serial debug is possible before going into standbyMode.  Serial debug does not appear after waking from standbyMode.

To test this, I modified Arturo Guadalupi's "Sleep RTC Alarm for Arduino Zero" example on www.arduino.cc and available as an example sketch.  In my modifications, I added Serial statements and use the builtin LED for help.

Arturo adds the following note in the comment header:

  NOTE:
  If you use this sketch with a MKR1000 you will see no output on the serial monitor.
  This happens because the USB clock is stopped so it the USB connection is stopped too.
  **To see again the USB port you have to double tap on the reset button!**


Well, a double tap on the reset button won't help me.  I was hoping to 'work around' that by issuing various commands, such as Serial.flush(), Serial.begin(), Serial.end().  None of my modifications have worked, yet.

Refer to my code below.  But here is brief pseudocode:

void setup()
 - MKR1000 all Serial text to the COM port as expected.  No issues.
 - It is here where you attach the interupt, set the alarm and enter standbyMode.  No issues.
void alarmMatch ()
 - 'ISR' works as expected.  No issues.
void loop()
 - global variable holds alarm expiration state T/F.
 - if the alarm expired...
 - Issue Serial.begin (again) and include while loop. 
 - I send text to the Serial port. Serial.println(blah blah blah) : ERROR I never see it.
 - I issue Serial.flush() command : nothing happens
 - I wait 8s...
 - Then I enable the built-in LED.  I observe this.  This means all the preceding statements execute.

Does anyone have any suggestions?
Considering Arturo's message, does anyone know how to re-enable the USB clock without double-tap of reset line?

I would greatly appreciate any assistance from the community.

Some additional information:
 - Arduino 1.8.0 Client on Window PC
 - MKR1000 with Firmware v19.5.2
 - WiFi Library v0.14.3

Code: [Select]

/*
  MKR1000-RTC-Serial-Test-20170727

  Note: I modified the example code reference below to test
        support for the Serial command after an rtc.standby().
        The original comment header resumes, below...
       
  Sleep RTC Alarm for Arduino Zero

  Demonstrates the use an alarm to wake up an Arduino zero from Standby mode

  This example code is in the public domain

  http://arduino.cc/en/Tutorial/SleepRTCAlarm

  created by Arturo Guadalupi
  17 Nov 2015
  modified
  01 Mar 2016
 
  NOTE:
  If you use this sketch with a MKR1000 you will see no output on the serial monitor.
  This happens because the USB clock is stopped so it the USB connection is stopped too.
  **To see again the USB port you have to double tap on the reset button!**
*/

#include <RTCZero.h>

/* Create an rtc object */
RTCZero rtc;

/* Change these values to set the current initial time */
const byte seconds = 0;
const 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;

boolean alarmExpired = false;

#define __SERIAL_PRESENT__

void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);

  #ifdef __SERIAL_PRESENT__
    Serial.begin(9600);
    while (!Serial) {
      ;
    Serial.println("--------------------------------------------");
    Serial.println("MKR1000-RTC-Serial-Test-20170727");
    Serial.println("--------------------------------------------");
    Serial.println("Initializing the MKR1000 RTC...");     
    }
   
  #endif
 
  rtc.begin();

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

  #ifdef __SERIAL_PRESENT__
    Serial.println("Setting and enabling the MKR1000 RTC Alarm...");
  #endif

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

  #ifdef __SERIAL_PRESENT__
    Serial.println("Attaching the interrupt...");
  #endif

  rtc.attachInterrupt(alarmMatch);


  #ifdef __SERIAL_PRESENT__
    Serial.println("Entering MKR1000 Standby Mode...");
    Serial.flush();
    Serial.end();
  #endif
 
  rtc.standbyMode();
}

void loop()
{
  if (alarmExpired == true) {
    #ifdef __SERIAL_PRESENT__
      Serial.begin(9600);
      while (!Serial) {
        ;
      }
      // ERROR: I do not see this text in the Serial Monitor.
      // ERROR: I do not see any text after rtc.standbyMode()...
      Serial.println("The MKR1000 RTC Alarm Expired...");
      Serial.flush();
      delay(8000);     
      digitalWrite(LED_BUILTIN, HIGH);         
    #endif
//    digitalWrite(LED_BUILTIN, HIGH);   
    alarmExpired = false;
  }

  rtc.standbyMode();    // Sleep until next alarm match
}

void alarmMatch()
{
  alarmExpired = true;
}

ballscrewbob

What happens if you remove the  code

Code: [Select]

{
    #ifdef __SERIAL_PRESENT__
      Serial.begin(9600);
      while (!Serial) {
        ;
      }


And just do the "Serial.begin(9600);"
If the LED is working prior to that then clearly the board has awoken and the alarm has expired so probably no need to check again.



It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

CowboySkippy

Same result - No debug info appears in the Serial Monitor window if the Serial.print() statement is in the loop() function.

Thinking linearly, I thought that if the MKR1000 (1) entered and then (2) exited standbyMode, then the Serial would need to be re-initialized.  That's why I added the Serial.begin() call.  But it did not help.

Ballscrewbob2

Have freed up an MKR to try the sketch above.
Seeing similar in that the serial is not getting there.
It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

gbsmith

I am working on the same issue.  I want do more than just blink an LED on a timer!  I want start a WIFI connection and send a MQTT message from a temperature sensor at a time interval.   If I don't use the standbyMode my MKR1000 feels hot to the touch.  The battery connection feature will be useless because of this extreme power consumption.  I thought that I might be able to get the serial USB connection working as a first debug step.

Did you find a solution?

Go Up