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.

» Acc 05: Intertial wake up interrupt

This example shows how to manage the inertial wake up interruption.

Required Materials

1 x Waspmote
1 x MiniUSB wire

Notes

- When the inertial wake up interrupt is activated, a light movement of Waspmote will generate an interruption and wake up Waspmote.
- This example can be executed in Waspmote v12 and Waspmote v15

Code

/*
 *  ------ [ACC_5] Waspmote Accelerometer Inertial Wake Up Example ------
 *
 *  Explanation: This example shows how to manage the inertial wake up 
 *  interruption
 *
 *  Copyright (C) 2016 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:           3.0
 *  Design:            David Gascón 
 *  Implementation:    Marcos Yarza
 */

void setup()
{ 
  // open serial port
  USB.ON();
  USB.println(F("ACC_05 example"));

}


void loop()
{
  ///////////////////////////////////////////////
  // 1. Starts accelerometer
  ///////////////////////////////////////////////
  ACC.ON();

  ///////////////////////////////////////////////
  // 2. Enable interruption: Inertial Wake Up
  ///////////////////////////////////////////////
  ACC.setIWU(); 


  ///////////////////////////////////////////////
  // 3. Set low-power consumption state
  ///////////////////////////////////////////////  
  USB.println(F("Waspmote goes into sleep mode until the Accelerometer causes an interrupt"));
  PWR.sleep(ALL_OFF);  

  // Interruption event happened

  ///////////////////////////////////////////////
  // 4. Disable interruption: Inertial Wake Up
  //    This is done to avoid new interruptions
  ///////////////////////////////////////////////
  ACC.ON();
  ACC.unsetIWU(); 

  USB.ON();
  USB.println(F("Waspmote wakes up"));

  ///////////////////////////////////////////////
  // 5. Check the interruption source 
  ///////////////////////////////////////////////
  if( intFlag & ACC_INT )
  {
    // clear interruption flag
    intFlag &= ~(ACC_INT);
    
    // print info
    USB.ON();
    USB.println(F("++++++++++++++++++++++++++++"));
    USB.println(F("++ ACC interrupt detected ++"));
    USB.println(F("++++++++++++++++++++++++++++")); 
    USB.println(); 

    // blink LEDs
    for(int i=0; i<10; i++)
    {
      Utils.blinkLEDs(50);
    }
    
    /* 
     *  Insert your code here if more things needed
     */
    
  }

  ///////////////////////////////////////////////////////////////////////
  // 6. Clear interruption pin   
  ///////////////////////////////////////////////////////////////////////
  // This function is used to make sure the interruption pin is cleared
  // if a non-captured interruption has been produced
  PWR.clearInterruptionPin();
}


Output

H#
ACC_05 example
Waspmote goes into sleep mode until the Accelerometer causes an interrupt
Waspmote wakes up
++++++++++++++++++++++++++++
++ ACC interrupt detected ++
++++++++++++++++++++++++++++

Waspmote goes into sleep mode until the Accelerometer causes an interrupt
Waspmote wakes up
++++++++++++++++++++++++++++
++ ACC interrupt detected ++
++++++++++++++++++++++++++++

Waspmote goes into sleep mode until the Accelerometer causes an interrupt

Quick Publish: