1
1
/*
2
2
===============================================
3
- Example sketch for CurieImu library for Intel(R) Curie(TM) devices.
3
+ Example sketch for CurieIMU library for Intel(R) Curie(TM) devices.
4
4
Copyright (c) 2015 Intel Corporation. All rights reserved.
5
5
6
6
Based on I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050
31
31
*/
32
32
33
33
#include " CurieImu.h"
34
-
35
- int16_t ax, ay, az; // accelerometer values
36
- int16_t gx, gy, gz; // gyrometer values
34
+ short int ax, ay, az; // accelerometer values
35
+ short int gx, gy, gz; // gyrometer values
37
36
38
37
const int ledPin = 13 ; // activity LED pin
39
38
boolean blinkState = false ; // state of the LED
40
39
40
+ int calibrateOffsets = 1 ; // int to determine whether calibration takes place or not
41
+
41
42
void setup () {
42
43
Serial.begin (9600 ); // initialize Serial communication
43
44
while (!Serial); // wait for the serial port to open
44
45
45
46
// initialize device
46
47
Serial.println (" Initializing IMU device..." );
47
- CurieImu. initialize ();
48
+ CurieIMU. begin ();
48
49
49
50
// verify connection
50
51
Serial.println (" Testing device connections..." );
51
- if (CurieImu. testConnection ()) {
52
- Serial.println (" CurieImu connection successful" );
52
+ if (CurieIMU. begin ()) {
53
+ Serial.println (" CurieIMU connection successful" );
53
54
} else {
54
- Serial.println (" CurieImu connection failed" );
55
+ Serial.println (" CurieIMU connection failed" );
55
56
}
56
-
57
+
57
58
// use the code below to calibrate accel/gyro offset values
58
- Serial.println (" Internal sensor offsets BEFORE calibration..." );
59
- Serial.print (CurieImu.getXAccelOffset ());
60
- Serial.print (" \t " ); // -76
61
- Serial.print (CurieImu.getYAccelOffset ());
62
- Serial.print (" \t " ); // -235
63
- Serial.print (CurieImu.getZAccelOffset ());
64
- Serial.print (" \t " ); // 168
65
- Serial.print (CurieImu.getXGyroOffset ());
66
- Serial.print (" \t " ); // 0
67
- Serial.print (CurieImu.getYGyroOffset ());
68
- Serial.print (" \t " ); // 0
69
- Serial.println (CurieImu.getZGyroOffset ());
70
-
71
- // To manually configure offset compensation values,
72
- // use the following methods instead of the autoCalibrate...() methods below
73
- // CurieImu.setXGyroOffset(220);
74
- // CurieImu.setYGyroOffset(76);
75
- // CurieImu.setZGyroOffset(-85);
76
- // CurieImu.setXAccelOffset(-76);
77
- // CurieImu.setYAccelOffset(-235);
78
- // CurieImu.setZAccelOffset(168);
79
-
80
- Serial.println (" About to calibrate. Make sure your board is stable and upright" );
81
- delay (5000 );
59
+ if (calibrateOffsets == 1 ) {
60
+ Serial.println (" Internal sensor offsets BEFORE calibration..." );
61
+ Serial.print (CurieIMU.getAccelerometerOffset (X_AXIS));
62
+ Serial.print (" \t " ); // -76
63
+ Serial.print (CurieIMU.getAccelerometerOffset (Y_AXIS));
64
+ Serial.print (" \t " ); // -235
65
+ Serial.print (CurieIMU.getAccelerometerOffset (Z_AXIS));
66
+ Serial.print (" \t " ); // 168
67
+ Serial.print (CurieIMU.getGyroOffset (X_AXIS));
68
+ Serial.print (" \t " ); // 0
69
+ Serial.print (CurieIMU.getGyroOffset (Y_AXIS));
70
+ Serial.print (" \t " ); // 0
71
+ Serial.println (CurieIMU.getGyroOffset (Z_AXIS));
72
+
73
+ // To manually configure offset compensation values,
74
+ // use the following methods instead of the autoCalibrate...() methods below
75
+ // CurieIMU.setAccelerometerOffset(X_AXIS,128);
76
+ // CurieIMU.setAccelerometerOffset(Y_AXIS,-4);
77
+ // CurieIMU.setAccelerometerOffset(Z_AXIS,127);
78
+ // CurieIMU.setGyroOffset(X_AXIS,129);
79
+ // CurieIMU.setGyroOffset(Y_AXIS,-1);
80
+ // CurieIMU.setGyroOffset(Z_AXIS, 254);
81
+
82
+ Serial.println (" About to calibrate. Make sure your board is stable and upright" );
83
+ delay (5000 );
84
+
85
+ // The board must be resting in a horizontal position for
86
+ // the following calibration procedure to work correctly!
87
+ Serial.print (" Starting Gyroscope calibration..." );
88
+ CurieIMU.autoCalibrateGyroOffset ();
89
+ Serial.println (" Done" );
90
+
91
+ Serial.print (" Starting Acceleration calibration..." );
92
+ CurieIMU.autoCalibrateAccelerometerOffset (X_AXIS, 0 );
93
+ CurieIMU.autoCalibrateAccelerometerOffset (Y_AXIS, 0 );
94
+ CurieIMU.autoCalibrateAccelerometerOffset (Z_AXIS, 1 );
95
+ Serial.println (" Done" );
96
+
97
+ Serial.println (" Internal sensor offsets AFTER calibration..." );
98
+ Serial.print (CurieIMU.getAccelerometerOffset (X_AXIS));
99
+ Serial.print (" \t " ); // -76
100
+ Serial.print (CurieIMU.getAccelerometerOffset (Y_AXIS));
101
+ Serial.print (" \t " ); // -2359
102
+ Serial.print (CurieIMU.getAccelerometerOffset (Z_AXIS));
103
+ Serial.print (" \t " ); // 1688
104
+ Serial.print (CurieIMU.getGyroOffset (X_AXIS));
105
+ Serial.print (" \t " ); // 0
106
+ Serial.print (CurieIMU.getGyroOffset (Y_AXIS));
107
+ Serial.print (" \t " ); // 0
108
+ Serial.println (CurieIMU.getGyroOffset (Z_AXIS));
109
+
110
+ Serial.println (" Enabling Gyroscope/Acceleration offset compensation" );
111
+ CurieIMU.enableGyroOffset (false );
112
+ CurieIMU.enableAccelerometerOffset (true );
113
+
114
+ Serial.println (CurieIMU.accelerometerOffsetEnabled ());
115
+ Serial.println (CurieIMU.gyroOffsetEnabled ());
116
+ }
82
117
83
- // The board must be resting in a horizontal position for
84
- // the following calibration procedure to work correctly!
85
- Serial.print (" Starting Gyroscope calibration..." );
86
- CurieImu.autoCalibrateGyroOffset ();
87
- Serial.println (" Done" );
88
- Serial.print (" Starting Acceleration calibration..." );
89
- CurieImu.autoCalibrateXAccelOffset (0 );
90
- CurieImu.autoCalibrateYAccelOffset (0 );
91
- CurieImu.autoCalibrateZAccelOffset (1 );
92
- Serial.println (" Done" );
93
-
94
- Serial.println (" Internal sensor offsets AFTER calibration..." );
95
- Serial.print (CurieImu.getXAccelOffset ());
96
- Serial.print (" \t " ); // -76
97
- Serial.print (CurieImu.getYAccelOffset ());
98
- Serial.print (" \t " ); // -2359
99
- Serial.print (CurieImu.getZAccelOffset ());
100
- Serial.print (" \t " ); // 1688
101
- Serial.print (CurieImu.getXGyroOffset ());
102
- Serial.print (" \t " ); // 0
103
- Serial.print (CurieImu.getYGyroOffset ());
104
- Serial.print (" \t " ); // 0
105
- Serial.println (CurieImu.getZGyroOffset ());
106
-
107
- Serial.println (" Enabling Gyroscope/Acceleration offset compensation" );
108
- CurieImu.setGyroOffsetEnabled (true );
109
- CurieImu.setAccelOffsetEnabled (true );
110
-
111
118
// configure Arduino LED for activity indicator
112
119
pinMode (ledPin, OUTPUT);
113
120
}
114
121
115
122
void loop () {
116
123
// read raw accel/gyro measurements from device
117
- CurieImu. getMotion6 (& ax, & ay, & az, & gx, & gy, & gz);
124
+ CurieIMU. readMotionSensor ( ax, ay, az, gx, gy, gz);
118
125
119
126
// these methods (and a few others) are also available
120
- // CurieImu.getAcceleration(&ax, &ay, &az);
121
- // CurieImu.getRotation(&gx, &gy, &gz);
127
+
128
+ // CurieIMU.readAcceleration(ax, ay, az);
129
+ // CurieIMU.readRotation(gx, gy, gz);
130
+
131
+ // ax = CurieIMU.readAccelerometer(X_AXIS);
132
+ // ay = CurieIMU.readAccelerometer(Y_AXIS);
133
+ // az = CurieIMU.readAccelerometer(Z_AXIS);
134
+ // gx = CurieIMU.readGyro(X_AXIS);
135
+ // gy = CurieIMU.readGyro(Y_AXIS);
136
+ // gz = CurieIMU.readGyro(Z_AXIS);
122
137
123
138
// display tab-separated accel/gyro x/y/z values
124
139
Serial.print (" a/g:\t " );
125
- Serial.print (ax );
140
+ Serial.print (az );
126
141
Serial.print (" \t " );
127
142
Serial.print (ay);
128
143
Serial.print (" \t " );
@@ -137,4 +152,4 @@ void loop() {
137
152
// blink LED to indicate activity
138
153
blinkState = !blinkState;
139
154
digitalWrite (ledPin, blinkState);
140
- }
155
+ }
0 commit comments