Development

General / Interrupts:

» Int 05a: Sensor Event interrupt

This example shows how to setup a threshold to the Sensor Event Board and enter sleep mode until an interruption occurs. Then show the value returned by the sensor board and print it.

Required Materials

1 x Waspmote
1 x MiniUSB wire
1 x Battery
1 x Sensor Event Board
1 x Pressure Sensor

Notes

* Remember to turn on the manual switch for socket 1 in the Events 2.0 Sensor Board
* Pressure sensor is the one used in this example, but other resistive sensors can be placed instead (take a look at the Sensor Compatibility guide)

Code

/*
 *  ------ [Int_05] Setting battery level interrupt example -------- 
 *
 *  Explanation: This example shows how to setup a threshold to the 
 *  Sensor Event Board and enter sleep mode until an interruption 
 *  occurs. Then show the value returned by the sensor board and print
 *  it.
 *
 *  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 Gascon
 *  Implementation:         Manuel Calahorra
 */


// Inclusion of the Events Sensor Board v20 library
#include <WaspSensorEvent_v20.h>

// Variable to store the sensor read value
float value = 0;



void setup()
{
  USB.ON();
  USB.println(F("int_05 example"));
  
  // Turn on the Events Sensor Board
  SensorEventv20.ON();
  
  // Init the RTC
  RTC.ON();
  
  // Configure the sensor threshold
  SensorEventv20.setThreshold(SENS_SOCKET1, 1);
}



void loop()
{
  // Enable interruptions from the board
  SensorEventv20.attachInt();
 
  // Put the mote to sleep
  USB.println(F("Enter sleep mode..."));  
  PWR.sleep(UART0_OFF | UART1_OFF | BAT_OFF | RTC_OFF);
  USB.println(F("...wake up")); 
  
  // Disable interruptions from the board
  SensorEventv20.detachInt();
  
  // Load the interruption register
  SensorEventv20.loadInt();

  // Compare the interruption received with the sensor identifier
  if (SensorEventv20.intFlag & SENS_SOCKET1)
  {    
    USB.println(F("---------------------------"));    
    USB.println(F("Sensor Events board interruption captured!!"));    
    USB.println(F("---------------------------"));    
    
    // Read the sensor
    value = SensorEventv20.readValue(SENS_SOCKET1, SENS_RESISTIVE);
    
    // Print the resistance of the sensor
    USB.print(F("Resistance: "));    
    USB.print(value);
    USB.println(F("kohms"));

  } 


}

Output

B#
int_05 example
Enter sleep mode...
...wake up
---------------------------
Sensor Events board interruption captured!!
---------------------------
Resistance: 172.5831909179kohms
Enter sleep mode...
...wake up
---------------------------
Sensor Events board interruption captured!!
---------------------------
Resistance: 147.2592468261kohms
Enter sleep mode...

...

Quick Publish: