Development v12

Warning - Product Update

All the resources present on this section belong to Waspmote v12, Waspmote Plug & Sense! v12 and Meshlium v3.8.

If you have a Waspmote v15, Waspmote Plug & Sense! v15 or Meshlium v4.0 please go to the new Development Section.

Check what is your version and what are the differences between the old and the new one in this document.

» Int 02: RTC alarm interrupt

This example shows how to set time alarms in the Waspmote RTC.

Required Materials

1 x Waspmote
1 x MiniUSB wire
1 x Battery

Notes

This example can be executed in Waspmote v12

Code

/*  
 *  ------ [Int_2] Setting RTC interrupt example -------- 
 *  
 *  Explanation: This example shows how to set time alarms in
 *  the Waspmote RTC
 *  
 *  Copyright (C) 2012 Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details. 
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 *  
 *  Version:           0.1 
 *  Design:            David Gascón 
 *  Implementation:    Marcos Yarza
 */

void setup()
{
  // Setup for Serial port over USB
  USB.ON();
  USB.println(F("Int_2 example"));

  // Powers RTC up, init I2C bus and read initial values
  USB.println(F("Init RTC"));
  RTC.ON(); 
}

void loop()
{
  USB.println(F("++++++++++++++++++++++++++++++++++++++++++++++++++++++++"));
  
  // Setting time
  RTC.ON(); 
  RTC.setTime("12:07:20:06:11:25:00");
  USB.print(F("Time: "));
  USB.println(RTC.getTime());
  
  // Alarm 1 Absolute mode - mode 2
  
  // Setting alarm 1 in absolute mode:
  // 20:11:25:15 => Date 20
  // time 11:25:15 
  // Alarm 1 is set 15 seconds later
  RTC.setAlarm1("20:11:25:15",RTC_ABSOLUTE,RTC_ALM1_MODE2);
  
  // Checking Alarm 1  
  USB.print(F("Alarm1: "));
  USB.print(RTC.getAlarm1());
  USB.println(F(" Absolute mode - Mode 2"));
  
  // Setting Waspmote to Low-Power Consumption Mode
  USB.println(F("Waspmote goes into sleep mode until the RTC alarm causes an interrupt"));
  PWR.sleep(ALL_OFF);
  
  // After setting Waspmote to power-down, UART is closed, so it
  // is necessary to open it again
  USB.ON();
  USB.println(F("\r\nWaspmote wake up - RTC interrupt detected!!\r\n"));
  
  // Waspmote wakes up at '11:25:15'
  if( intFlag & RTC_INT )
  {
    intFlag &= ~(RTC_INT); // Clear flag
    Utils.blinkLEDs(1000); // Blinking LEDs
    Utils.blinkLEDs(1000); // Blinking LEDs
  }

  USB.print(F("Time: "));
  RTC.ON(); 
  USB.println(RTC.getTime());
    
  delay(5000);  
}

Output

B#
Int_2 example
Init RTC
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Time: Fri, 12/07/20, 11:25:00
Alarm1: 20, 12:07:20 - 11:25:15 Absolute mode - Mode 2
Waspmote goes into sleep mode until the RTC alarm causes an interrupt

Waspmote wake up - RTC interrupt detected!!

Time: Fri, 12/07/20, 11:25:00

Quick Publish: