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

1
/*
2
* ------ [ACC_5] Waspmote Accelerometer Inertial Wake Up Example ------
3
*
4
* Explanation: This example shows how to manage the inertial wake up
5
* interruption
6
*
7
* Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
8
* http://www.libelium.com
9
*
10
* This program is free software: you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation, either version 3 of the License, or
13
* (at your option) any later version.
14
*
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
19
*
20
* You should have received a copy of the GNU General Public License
21
* along with this program. If not, see .
22
*
23
* Version: 3.0
24
* Design: David Gascón
25
* Implementation: Marcos Yarza
26
*/
27
28
void setup()
29
{
30
// open serial port
31
USB.ON();
32
USB.println(F("ACC_05 example"));
33
}
34
35
void loop()
36
{
37
///////////////////////////////////////////////
38
// 1. Starts accelerometer
39
///////////////////////////////////////////////
40
ACC.ON();
41
42
///////////////////////////////////////////////
43
// 2. Enable interruption: Inertial Wake Up
44
///////////////////////////////////////////////
45
ACC.setIWU();
46
47
///////////////////////////////////////////////
48
// 3. Set low-power consumption state
49
///////////////////////////////////////////////
50
USB.println(F("Waspmote goes into sleep mode until the Accelerometer causes an interrupt"));
51
PWR.sleep(ALL_OFF);
52
53
// Interruption event happened
54
55
///////////////////////////////////////////////
56
// 4. Disable interruption: Inertial Wake Up
57
// This is done to avoid new interruptions
58
///////////////////////////////////////////////
59
ACC.ON();
60
ACC.unsetIWU();
61
62
USB.ON();
63
USB.println(F("Waspmote wakes up"));
64
65
///////////////////////////////////////////////
66
// 5. Check the interruption source
67
///////////////////////////////////////////////
68
if( intFlag & ACC_INT )
69
{
70
// clear interruption flag
71
intFlag &= ~(ACC_INT);
72
73
// print info
74
USB.ON();
75
USB.println(F("++++++++++++++++++++++++++++"));
76
USB.println(F("++ ACC interrupt detected ++"));
77
USB.println(F("++++++++++++++++++++++++++++"));
78
USB.println();
79
80
// blink LEDs
81
for(int i=0; i<10; i++)
82
{
83
Utils.blinkLEDs(50);
84
}
85
86
/*
87
* Insert your code here if more things needed
88
*/
89
90
}
91
92
///////////////////////////////////////////////////////////////////////
93
// 6. Clear interruption pin
94
///////////////////////////////////////////////////////////////////////
95
// This function is used to make sure the interruption pin is cleared
96
// if a non-captured interruption has been produced
97
PWR.clearInterruptionPin();
98
}
Copied!

Output

1
H#
2
ACC_05 example
3
Waspmote goes into sleep mode until the Accelerometer causes an interrupt
4
Waspmote wakes up
5
++++++++++++++++++++++++++++
6
++ ACC interrupt detected ++
7
++++++++++++++++++++++++++++
8
9
Waspmote goes into sleep mode until the Accelerometer causes an interrupt
10
Waspmote wakes up
11
++++++++++++++++++++++++++++
12
++ ACC interrupt detected ++
13
++++++++++++++++++++++++++++
14
15
Waspmote goes into sleep mode until the Accelerometer causes an interrupt
Copied!
Last modified 1yr ago