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
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;int calibrateOffsets = 0;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 MPU605010
11  class by Jeff Rowberg: https://github.com/jrowberg/i2cdevlib12
13  ===============================================14
15  I2Cdev device library code is placed under the MIT license16
17  Copyright (c) 2011 Jeff Rowberg18
19  Permission is hereby granted, free of charge, to any person obtaining a copy20
21  of this software and associated documentation files (the "Software"), to deal22
23  in the Software without restriction, including without limitation the rights24
25  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell26
27  copies of the Software, and to permit persons to whom the Software is28
29  furnished to do so, subject to the following conditions:30
31  The above copyright notice and this permission notice shall be included in32
33  all copies or substantial portions of the Software.34
35  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR36
37  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,38
39  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE40
41  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER42
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 IN46
47  THE SOFTWARE.48
49  ===============================================50
51*/52
53#include "CurieIMU.h"54int ax, ay, az;         // accelerometer values55int gx, gy, gz;         // gyrometer values56
57const int ledPin = 13;      // activity LED pin58
59bool blinkState = false; // state of the LED60
61int calibrateOffsets = 1; // int to determine whether calibration takes place or not62
63void setup() {64
65  Serial.begin(9600); // initialize Serial communication66
67  while (!Serial);    // wait for the serial port to open68
69  // initialize device70
71  Serial.println("Initializing IMU device...");72
73  CurieIMU.begin();74
75  // verify connection76
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 values90
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"); // -7698
99    Serial.print(CurieIMU.getAccelerometerOffset(Y_AXIS));100
101    Serial.print("\t"); // -235102
103    Serial.print(CurieIMU.getAccelerometerOffset(Z_AXIS));104
105    Serial.print("\t"); // 168106
107    Serial.print(CurieIMU.getGyroOffset(X_AXIS));108
109    Serial.print("\t"); // 0110
111    Serial.print(CurieIMU.getGyroOffset(Y_AXIS));112
113    Serial.print("\t"); // 0114
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 below120
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 for138
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"); // -76162
163    Serial.print(CurieIMU.getAccelerometerOffset(Y_AXIS));164
165    Serial.print("\t"); // -2359166
167    Serial.print(CurieIMU.getAccelerometerOffset(Z_AXIS));168
169    Serial.print("\t"); // 1688170
171    Serial.print(CurieIMU.getGyroOffset(X_AXIS));172
173    Serial.print("\t"); // 0174
175    Serial.print(CurieIMU.getGyroOffset(Y_AXIS));176
177    Serial.print("\t"); // 0178
179    Serial.println(CurieIMU.getGyroOffset(Z_AXIS));180
181  }182
183
184
185  // configure Arduino LED for activity indicator186
187  pinMode(ledPin, OUTPUT);188}189
190void loop() {191
192  // read raw accel/gyro measurements from device193
194  CurieIMU.readMotionSensor(ax, ay, az, gx, gy, gz);195
196  // these methods (and a few others) are also available197
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 values215
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 activity241
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.
