MKRZero Wake from Sleep on RX

Hi there,

I am trying to put together a data logger that sleeps, until it is woken by a host device that will be sending 200 bytes of data every minute +/- a few seconds.

Can anyone offer me some advice on how to implement this or point me at a relevant tutorial for achieving this on a MKRZero.

Many Thanks

Andy

I am trying to put together a data logger that sleeps, until it is woken by a host device that will be sending 200 bytes of data every minute +/- a few seconds.

What's a host device in this context? You can put the MKRzero to sleep (standby mode) and it will wake up at every interrupt received (which can be an external event). Don't put the Arduino to sleep if connected by USB.

I am connecting to a serial device via the RX/TX pins on the MKRZero header (Serial1).

Do you have some sample code I could take a look at? All the samples I have seen use the AVR sleep module, as far as I know the MKRZero uses an ARM M0+

I have kind of solved my own issue by hard wiring pin 6 to the RX pin - I would rather not have to use the pin interrupt method, as I am pretty sure an interrupt must be generated in the micro when a uart Rx occurs.

Here is my code… How can I attach a ISR for the RX interrupt???

#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 = 0;
const byte hours = 0;

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

const byte interruptPin = 6;

unsigned char IntSource = 0;


void setup()
{
 pinMode(LED_BUILTIN, OUTPUT);
 digitalWrite(LED_BUILTIN, LOW);  
 Serial1.begin(9600);
 rtc.begin();

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

 rtc.setAlarmTime(0, 0, 20);
 rtc.enableAlarm(rtc.MATCH_HHMMSS);

 rtc.attachInterrupt(alarmMatch);

 pinMode(interruptPin, INPUT);
 attachInterrupt(digitalPinToInterrupt(interruptPin), wakeUp, LOW);  

 Serial1.println("******** Setup Complete ********");

 delay(2000);
 

}

void loop()
{
 digitalWrite(LED_BUILTIN, HIGH);
 delay(1000);
 digitalWrite(LED_BUILTIN, LOW);
 delay(1000);
 Serial1.println("Going to Sleep");
 Serial1.println();  
 delay(1000);
 /* ****** GOTO SLEEP ****** */
 rtc.standbyMode();
 /* ************************ */

 
 Serial1.println("Woken from Sleep");
 if ( IntSource == 3)
 {
     Serial1.println("Rx WakeUp");
 }  

 if ( IntSource == 1)
 {
     Serial1.println("Timer WakeUp");
 }  
 if ( IntSource == 2)
 {
     Serial1.println("Pin WakeUp");
     delay(1000);
     while (Serial1.available()) {      // If anything comes in Serial (USB),
       Serial1.print(Serial1.read(),HEX);   // read it and send it out Serial1 (pins 0 & 1)
     }
     Serial1.println();
 }
 IntSource = 0;    
}

void alarmMatch()
{
 rtc.setTime(0, 0, 0);
 IntSource = 1;

}

void wakeUp()
{
 IntSource = 2;
}