Arduino 101 CurieIMU Raw IMU Data Serial

In this tutorial you read the whole set of raw data from accelerometer and gyroscope.

In this tutorial you read the whole set of raw data from accelerometer and gyroscope. The function used reads the six values all together, but there are specific functions to read a single sensor or a single axis of a sensor.

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 whole set of data from the motion sensor with the readMotionSensor function.

Functions

none

Code

The sensors may need calibration to get raw data that is related to the real position of the board. To achieve this, you change this line from

int calibrateOffsets = 1;
to
int calibrateOffsets = 0;
and place the board on a flat surface, with components pointing upwards. On the Serial monitor you will see the sensors output before offset calibration and then after calibration. If you don't move the board, the reading of raw data should be close to zero, except for the third value that is Z, equal or close to 16767 that is 1g for a +/-2G range.

1/*
2
3 ===============================================
4
5 Example sketch for CurieIMU library for Intel(R) Curie(TM) devices.
6
7 Copyright (c) 2015 Intel Corporation. All rights reserved.
8
9 Based on I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050
10
11 class by Jeff Rowberg: https://github.com/jrowberg/i2cdevlib
12
13 ===============================================
14
15 I2Cdev device library code is placed under the MIT license
16
17 Copyright (c) 2011 Jeff Rowberg
18
19 Permission is hereby granted, free of charge, to any person obtaining a copy
20
21 of this software and associated documentation files (the "Software"), to deal
22
23 in the Software without restriction, including without limitation the rights
24
25 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26
27 copies of the Software, and to permit persons to whom the Software is
28
29 furnished to do so, subject to the following conditions:
30
31 The above copyright notice and this permission notice shall be included in
32
33 all copies or substantial portions of the Software.
34
35 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36
37 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
38
39 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
40
41 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
42
43 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
44
45 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
46
47 THE SOFTWARE.
48
49 ===============================================
50
51*/
52
53#include "CurieIMU.h"
54int ax, ay, az; // accelerometer values
55int gx, gy, gz; // gyrometer values
56
57const int ledPin = 13; // activity LED pin
58
59bool blinkState = false; // state of the LED
60
61int calibrateOffsets = 1; // int to determine whether calibration takes place or not
62
63void setup() {
64
65 Serial.begin(9600); // initialize Serial communication
66
67 while (!Serial); // wait for the serial port to open
68
69 // initialize device
70
71 Serial.println("Initializing IMU device...");
72
73 CurieIMU.begin();
74
75 // verify connection
76
77 Serial.println("Testing device connections...");
78
79 if (CurieIMU.begin()) {
80
81 Serial.println("CurieIMU connection successful");
82
83 } else {
84
85 Serial.println("CurieIMU connection failed");
86
87 }
88
89 // use the code below to calibrate accel/gyro offset values
90
91 if (calibrateOffsets == 1) {
92
93 Serial.println("Internal sensor offsets BEFORE calibration...");
94
95 Serial.print(CurieIMU.getAccelerometerOffset(X_AXIS));
96
97 Serial.print("\t"); // -76
98
99 Serial.print(CurieIMU.getAccelerometerOffset(Y_AXIS));
100
101 Serial.print("\t"); // -235
102
103 Serial.print(CurieIMU.getAccelerometerOffset(Z_AXIS));
104
105 Serial.print("\t"); // 168
106
107 Serial.print(CurieIMU.getGyroOffset(X_AXIS));
108
109 Serial.print("\t"); // 0
110
111 Serial.print(CurieIMU.getGyroOffset(Y_AXIS));
112
113 Serial.print("\t"); // 0
114
115 Serial.println(CurieIMU.getGyroOffset(Z_AXIS));
116
117 // To manually configure offset compensation values,
118
119 // use the following methods instead of the autoCalibrate...() methods below
120
121 //CurieIMU.setAccelerometerOffset(X_AXIS,495.3);
122
123 //CurieIMU.setAccelerometerOffset(Y_AXIS,-15.6);
124
125 //CurieIMU.setAccelerometerOffset(Z_AXIS,491.4);
126
127 //CurieIMU.setGyroOffset(X_AXIS,7.869);
128
129 //CurieIMU.setGyroOffset(Y_AXIS,-0.061);
130
131 //CurieIMU.setGyroOffset(Z_AXIS,15.494);
132
133 Serial.println("About to calibrate. Make sure your board is stable and upright");
134
135 delay(5000);
136
137 // The board must be resting in a horizontal position for
138
139 // the following calibration procedure to work correctly!
140
141 Serial.print("Starting Gyroscope calibration and enabling offset compensation...");
142
143 CurieIMU.autoCalibrateGyroOffset();
144
145 Serial.println(" Done");
146
147 Serial.print("Starting Acceleration calibration and enabling offset compensation...");
148
149 CurieIMU.autoCalibrateAccelerometerOffset(X_AXIS, 0);
150
151 CurieIMU.autoCalibrateAccelerometerOffset(Y_AXIS, 0);
152
153 CurieIMU.autoCalibrateAccelerometerOffset(Z_AXIS, 1);
154
155 Serial.println(" Done");
156
157 Serial.println("Internal sensor offsets AFTER calibration...");
158
159 Serial.print(CurieIMU.getAccelerometerOffset(X_AXIS));
160
161 Serial.print("\t"); // -76
162
163 Serial.print(CurieIMU.getAccelerometerOffset(Y_AXIS));
164
165 Serial.print("\t"); // -2359
166
167 Serial.print(CurieIMU.getAccelerometerOffset(Z_AXIS));
168
169 Serial.print("\t"); // 1688
170
171 Serial.print(CurieIMU.getGyroOffset(X_AXIS));
172
173 Serial.print("\t"); // 0
174
175 Serial.print(CurieIMU.getGyroOffset(Y_AXIS));
176
177 Serial.print("\t"); // 0
178
179 Serial.println(CurieIMU.getGyroOffset(Z_AXIS));
180
181 }
182
183
184
185 // configure Arduino LED for activity indicator
186
187 pinMode(ledPin, OUTPUT);
188}
189
190void loop() {
191
192 // read raw accel/gyro measurements from device
193
194 CurieIMU.readMotionSensor(ax, ay, az, gx, gy, gz);
195
196 // these methods (and a few others) are also available
197
198 //CurieIMU.readAcceleration(ax, ay, az);
199
200 //CurieIMU.readRotation(gx, gy, gz);
201
202 //ax = CurieIMU.readAccelerometer(X_AXIS);
203
204 //ay = CurieIMU.readAccelerometer(Y_AXIS);
205
206 //az = CurieIMU.readAccelerometer(Z_AXIS);
207
208 //gx = CurieIMU.readGyro(X_AXIS);
209
210 //gy = CurieIMU.readGyro(Y_AXIS);
211
212 //gz = CurieIMU.readGyro(Z_AXIS);
213
214 // display tab-separated accel/gyro x/y/z values
215
216 Serial.print("a/g:\t");
217
218 Serial.print(ax);
219
220 Serial.print("\t");
221
222 Serial.print(ay);
223
224 Serial.print("\t");
225
226 Serial.print(az);
227
228 Serial.print("\t");
229
230 Serial.print(gx);
231
232 Serial.print("\t");
233
234 Serial.print(gy);
235
236 Serial.print("\t");
237
238 Serial.println(gz);
239
240 // blink LED to indicate activity
241
242 blinkState = !blinkState;
243
244 digitalWrite(ledPin, blinkState);
245}

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.