Acc 01: Reading acceleration
This example shows how to get the acceleration on the different axis using the most basic functions related with Waspmote 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_1] Waspmote Accelerometer Reading acceleration --------
3
*
4
* Explanation: This example shows how to get the acceleration on the
5
* different axis using the most basic functions related with Waspmote
6
* accelerometer
7
*
8
* Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
9
* http://www.libelium.com
10
*
11
* This program is free software: you can redistribute it and/or modify
12
* it under the terms of the GNU General Public License as published by
13
* the Free Software Foundation, either version 3 of the License, or
14
* (at your option) any later version.
15
*
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU General Public License for more details.
20
*
21
* You should have received a copy of the GNU General Public License
22
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23
*
24
* Version: 3.0
25
* Design: David Gascón
26
* Implementation: Marcos Yarza
27
*/
28
29
uint8_t status;
30
int x_acc;
31
int y_acc;
32
int z_acc;
33
34
void setup()
35
{
36
ACC.ON();
37
USB.ON(); // starts using the serial port
38
USB.println(F("ACC_01 example"));
39
}
40
41
void loop()
42
{
43
44
//----------Check Register-----------------------
45
// should always answer 0x32, it is used to check
46
// the proper functionality of the accelerometer
47
status = ACC.check();
48
49
//----------X Value-----------------------
50
x_acc = ACC.getX();
51
52
//----------Y Value-----------------------
53
y_acc = ACC.getY();
54
55
//----------Z Value-----------------------
56
z_acc = ACC.getZ();
57
58
//-------------------------------
59
60
USB.print(F("\n------------------------------\nCheck: 0x"));
61
USB.println(status, HEX);
62
USB.println(F("\n \t0X\t0Y\t0Z"));
63
USB.print(F(" ACC\t"));
64
USB.print(x_acc, DEC);
65
USB.print(F("\t"));
66
USB.print(y_acc, DEC);
67
USB.print(F("\t"));
68
USB.println(z_acc, DEC);
69
70
delay(1000);
71
}
Copied!

Output

1
H#
2
ACC_01 example
3
4
------------------------------
5
Check: 0x32
6
7
0X 0Y 0Z
8
ACC -133 -32 988
9
10
------------------------------
Copied!
Last modified 1yr ago