Acc 04: Power modes
This example shows how to get the acceleration on the different axis using the power modes of the accelerometer.

Required Materials

1 x Waspmote 1 x MiniUSB wire

Notes

This example can be executed in Waspmote v12 and Waspmote v15

Code

1
/*
2
* ------ [ACC_4] Waspmote Accelerometer Power Modes --------
3
*
4
* Explanation: This example shows how to get the acceleration on the
5
* different axis using the power modes of the accelerometer
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 <http://www.gnu.org/licenses/>.
22
*
23
* Version: 3.0
24
* Design: David Gascón
25
* Implementation: Marcos Yarza
26
*/
27
28
void setup()
29
{
30
ACC.ON();
31
USB.ON(); // starts using the serial port
32
USB.println(F("ACC_4 example"));
33
}
34
35
int x_acc = 0;
36
int y_acc = 0;
37
int z_acc = 0;
38
39
void loop()
40
{
41
USB.println(F("\r\n+++++++++++++++++++++++++++++++++++++++"));
42
43
// Normal mode
44
ACC.setMode(ACC_ON);
45
x_acc = ACC.getX(); // reading X value
46
y_acc = ACC.getY(); // reading Y value
47
z_acc = ACC.getZ(); // reading Z value
48
49
USB.println(F("Accelerometer mode: ACC_ON"));
50
USB.print(F("Acceleration: X= "));
51
USB.print(x_acc, DEC);
52
USB.print(F(" | Y= "));
53
USB.print(y_acc, DEC);
54
USB.print(F(" |Z= "));
55
USB.println(z_acc, DEC);
56
57
delay(1000);
58
59
// LOW POWER 1
60
ACC.setMode(ACC_LOW_POWER_1);
61
x_acc = ACC.getX(); // reading X value
62
y_acc = ACC.getY(); // reading Y value
63
z_acc = ACC.getZ(); // reading Z value
64
65
USB.println(F("------------------------------"));
66
USB.println(F("Accelerometer mode: ACC_LOW_POWER_1"));
67
USB.print(F("Acceleration: X= "));
68
USB.print(x_acc, DEC);
69
USB.print(F(" | Y= "));
70
USB.print(y_acc, DEC);
71
USB.print(F(" |Z= "));
72
USB.println(z_acc, DEC);
73
74
delay(1000);
75
76
// LOW POWER 2
77
ACC.setMode(ACC_LOW_POWER_2);
78
x_acc = ACC.getX(); // reading X value
79
y_acc = ACC.getY(); // reading Y value
80
z_acc = ACC.getZ(); // reading Z value
81
82
USB.println(F("------------------------------"));
83
USB.println(F("Accelerometer mode: ACC_LOW_POWER_2"));
84
USB.print(F("Acceleration: X= "));
85
USB.print(x_acc, DEC);
86
USB.print(F(" | Y= "));
87
USB.print(y_acc, DEC);
88
USB.print(F(" |Z= "));
89
USB.println(z_acc, DEC);
90
91
delay(1000);
92
93
// LOW POWER 3
94
ACC.setMode(ACC_LOW_POWER_3);
95
x_acc = ACC.getX(); // reading X value
96
y_acc = ACC.getY(); // reading Y value
97
z_acc = ACC.getZ(); // reading Z value
98
99
USB.println(F("------------------------------"));
100
USB.println(F("Accelerometer mode: ACC_LOW_POWER_3"));
101
USB.print(F("Acceleration: X= "));
102
USB.print(x_acc, DEC);
103
USB.print(F(" | Y= "));
104
USB.print(y_acc, DEC);
105
USB.print(F(" |Z= "));
106
USB.println(z_acc, DEC);
107
108
delay(1000);
109
110
// LOW POWER 4
111
ACC.setMode(ACC_LOW_POWER_4);
112
x_acc = ACC.getX(); // reading X value
113
y_acc = ACC.getY(); // reading Y value
114
z_acc = ACC.getZ(); // reading Z value
115
116
USB.println(F("------------------------------"));
117
USB.println(F("Accelerometer mode: ACC_LOW_POWER_4"));
118
USB.print(F("Acceleration: X= "));
119
USB.print(x_acc, DEC);
120
USB.print(F(" | Y= "));
121
USB.print(y_acc, DEC);
122
USB.print(F(" |Z= "));
123
USB.println(z_acc, DEC);
124
125
delay(1000);
126
127
// LOW POWER 5
128
ACC.setMode(ACC_LOW_POWER_5);
129
x_acc = ACC.getX(); // reading X value
130
y_acc = ACC.getY(); // reading Y value
131
z_acc = ACC.getZ(); // reading Z value
132
133
USB.println(F("------------------------------"));
134
USB.println(F("Accelerometer mode: ACC_LOW_POWER_5"));
135
USB.print(F("Acceleration: X= "));
136
USB.print(x_acc, DEC);
137
USB.print(F(" | Y= "));
138
USB.print(y_acc, DEC);
139
USB.print(F(" |Z= "));
140
USB.println(z_acc, DEC);
141
142
delay(1000);
143
144
// ACC POWER DOWN
145
ACC.setMode(ACC_POWER_DOWN);
146
147
ACC.OFF();
148
149
USB.println(F("------------------------------"));
150
USB.println(F("Accelerometer mode: ACC_POWER_DOWN"));
151
152
delay(5000);
153
}
Copied!

Output

1
H#
2
ACC_4 example
3
4
+++++++++++++++++++++++++++++++++++++++
5
Accelerometer mode: ACC_ON
6
Acceleration: X= -20 | Y= 18 |Z= 976
7
------------------------------
8
Accelerometer mode: ACC_LOW_POWER_1
9
Acceleration: X= -18 | Y= 23 |Z= 971
10
------------------------------
11
Accelerometer mode: ACC_LOW_POWER_2
12
Acceleration: X= -17 | Y= 21 |Z= 979
13
------------------------------
14
Accelerometer mode: ACC_LOW_POWER_3
15
Acceleration: X= -19 | Y= 23 |Z= 976
16
------------------------------
17
Accelerometer mode: ACC_LOW_POWER_4
18
Acceleration: X= -21 | Y= 27 |Z= 978
19
------------------------------
20
Accelerometer mode: ACC_LOW_POWER_5
21
Acceleration: X= -18 | Y= 16 |Z= 976
22
------------------------------
23
Accelerometer mode: ACC_POWER_DOWN
Copied!
Last modified 1yr ago