Arduino 101 CurieIMU Accelerometer

With this tutorial you learn to read the three axes of the accelerometer contained in the IMU (Inertial Measurement Unit) of the 101 board.

With this tutorial you learn to read the three axes of the accelerometer contained in the IMU (Inertial Measurement Unit) of the 101 board. Each axis measures the acceleration within a range defined by a specific function - setAccelerometerRange - and returns a raw value that needs to be converted to get a value in mg. The result of the conversion is printed on the Serial monitor as triplets of acceleration values (X, Y and Z).

Hardware Required

The Circuit

genuino101fzz

image developed using Fritzing. No additional hardware is needed to use this tutorial.

Software Essentials

Libraries

CurieIMU.h is the library that gives access to all the parameters, features and readings of the IMU chip of the 101 board. This unit contains a three axes accelerometer and a three axes gyroscope. This library is part of the 101 board core and it is loaded together with the core files for Arduino 101. In this tutorial we read the raw accelerometer values.

Functions

float convertRawAcceleration(int aRaw) - transforms the raw data read from the accelerometer (aRaw) into a value expressed in mg (thousandths of g). The formula of the function must be adjusted to match the accelerometer range set with setAccelerometerRange.

Code

This sketch is the simplest possible and doesn't include any calibration. The Accelerometer data is refreshed every 5 seconds.

1/*
2
3 * Copyright (c) 2016 Intel Corporation. All rights reserved.
4
5 * See the bottom of this file for the license terms.
6
7 */
8
9/*
10
11 This sketch example demonstrates how the BMI160 on the
12
13 Intel(R) Curie(TM) module can be used to read accelerometer data
14
15*/
16
17#include "CurieIMU.h"
18
19void setup() {
20
21 Serial.begin(9600); // initialize Serial communication
22
23 while (!Serial); // wait for the serial port to open
24
25 // initialize device
26
27 Serial.println("Initializing IMU device...");
28
29 CurieIMU.begin();
30
31 // Set the accelerometer range to 2G
32
33 CurieIMU.setAccelerometerRange(2);
34}
35
36void loop() {
37
38 float ax, ay, az; //scaled accelerometer values
39
40 // read accelerometer measurements from device, scaled to the configured range
41
42 CurieIMU.readAccelerometerScaled(ax, ay, az);
43
44 // display tab-separated accelerometer x/y/z values
45
46 Serial.print("a:\t");
47
48 Serial.print(ax);
49
50 Serial.print("\t");
51
52 Serial.print(ay);
53
54 Serial.print("\t");
55
56 Serial.print(az);
57
58 Serial.println();
59}
60
61/*
62
63 Copyright (c) 2016 Intel Corporation. All rights reserved.
64
65 This library is free software; you can redistribute it and/or
66
67 modify it under the terms of the GNU Lesser General Public
68
69 License as published by the Free Software Foundation; either
70
71 version 2.1 of the License, or (at your option) any later version.
72
73 This library is distributed in the hope that it will be useful,
74
75 but WITHOUT ANY WARRANTY; without even the implied warranty of
76
77 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
78
79 Lesser General Public License for more details.
80
81 You should have received a copy of the GNU Lesser General Public
82
83 License along with this library; if not, write to the Free Software
84
85 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
86
87*/

Suggest changes

The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.

License

The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.