Development

Sensors / Accelerometer:

» Acc 05: Intertial wake up interrupt

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

Required Materials

1 x Waspmote PRO
1 x MiniUSB wire

Notes

When the intertial wake up interrupt is activated, a light movement of Waspmote will generate an interruption and wake up Waspmote PRO.

Code

/*
 *  ------ [ACC_5] Waspmote Accelerometer Inertial Wake Up Example ------
 *
 *  Explanation: This example shows how to manage the inertial wake up 
 *  interruption
 *
 *  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
 */

long previous = 0;

void setup()
{
  ACC.ON();
  USB.ON(); // starts using the serial port
  USB.println(F("ACC_05 example"));
}


void loop()
{
  ACC.ON();
  USB.println(F("Accelerometer ON"));
  ACC.setIWU();
  USB.println("Inertial Wake-UP interrupt configured");
  
  USB.println("Go to sleep and wait Inertial Wake-UP interrupt");
  PWR.sleep(ALL_OFF);
   
  if( intFlag & ACC_INT )
  {
    // clear the accelerometer interrupt flag on the general interrupt vector
    intFlag &= ~(ACC_INT);
    ACC.unsetIWU();
    // read the acceleration source register
    delay(200);
    USB.ON();
    USB.println(F("+++++++++++++++++++++++++++++++++++++++++"));
    USB.println(F("++ Inertial Wake-UP interrupt detected ++"));
    USB.println(F("+++++++++++++++++++++++++++++++++++++++++"));
    
  }
  delay(2000);
}

Output

B#
ACC_05 example
Accelerometer ON
Inertial Wake-UP interrupt configured
Go to sleep and wait Inertial Wake-UP interrupt
+++++++++++++++++++++++++++++++++++++++++
++ Inertial Wake-UP interrupt detected ++
+++++++++++++++++++++++++++++++++++++++++

Quick Publish: