1
1
/*
2
- ===============================================
3
- Example sketch for CurieImu library for Intel(R) Curie(TM) devices.
4
- Copyright (c) 2015 Intel Corporation. All rights reserved.
5
-
6
- Based on I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050
7
- class by Jeff Rowberg: https://github.com/jrowberg/i2cdevlib
8
-
9
- ===============================================
10
- I2Cdev device library code is placed under the MIT license
11
- Copyright (c) 2011 Jeff Rowberg
12
-
13
- Permission is hereby granted, free of charge, to any person obtaining a copy
14
- of this software and associated documentation files (the "Software"), to deal
15
- in the Software without restriction, including without limitation the rights
16
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
- copies of the Software, and to permit persons to whom the Software is
18
- furnished to do so, subject to the following conditions:
19
-
20
- The above copyright notice and this permission notice shall be included in
21
- all copies or substantial portions of the Software.
22
-
23
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29
- THE SOFTWARE.
30
- ===============================================
2
+ ===============================================
3
+ Example sketch for CurieImu library for Intel(R) Curie(TM) devices.
4
+ Copyright (c) 2015 Intel Corporation. All rights reserved.
5
+
6
+ Based on I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050
7
+ class by Jeff Rowberg: https://github.com/jrowberg/i2cdevlib
8
+
9
+ ===============================================
10
+ I2Cdev device library code is placed under the MIT license
11
+ Copyright (c) 2011 Jeff Rowberg
12
+
13
+ Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ of this software and associated documentation files (the "Software"), to deal
15
+ in the Software without restriction, including without limitation the rights
16
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ copies of the Software, and to permit persons to whom the Software is
18
+ furnished to do so, subject to the following conditions:
19
+
20
+ The above copyright notice and this permission notice shall be included in
21
+ all copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29
+ THE SOFTWARE.
30
+ ===============================================
31
31
*/
32
32
33
33
#include " CurieImu.h"
34
34
35
- int16_t ax, ay, az;
36
- int16_t gx, gy, gz;
35
+ int16_t ax, ay, az; // accelerometer values
36
+ int16_t gx, gy, gz; // gyrometer values
37
37
38
- // uncomment "OUTPUT_READABLE_ACCELGYRO" if you want to see a tab-separated
39
- // list of the accel X/Y/Z and then gyro X/Y/Z values in decimal. Easy to read,
40
- // not so easy to parse, and slow(er) over UART.
41
- #define OUTPUT_READABLE_ACCELGYRO
42
-
43
- // uncomment "OUTPUT_BINARY_ACCELGYRO" to send all 6 axes of data as 16-bit
44
- // binary, one right after the other. This is very fast (as fast as possible
45
- // without compression or data loss), and easy to parse, but impossible to read
46
- // for a human.
47
- // #define OUTPUT_BINARY_ACCELGYRO
48
-
49
- // uncomment "CALIBRATE_ACCELGRYO_OFFSETS" to perform auto-calibration of all 6 axes during start-up
50
- // This requires the device to be resting in a horizontal position during the start-up phase
51
- // #define CALIBRATE_ACCELGRYO_OFFSETS
52
-
53
-
54
- #define LED_PIN 13
55
- bool blinkState = false ;
38
+ const int ledPin = 13 ; // activity LED pin
39
+ boolean blinkState = false ; // state of the LED
56
40
57
41
void setup () {
58
- // initialize Serial communication
59
- Serial.begin (115200 );
60
-
61
- // initialize device
62
- Serial.println (" Initializing IMU device..." );
63
- CurieImu.initialize ();
64
-
65
- // verify connection
66
- Serial.println (" Testing device connections..." );
67
- Serial.println (CurieImu.testConnection () ? " CurieImu connection successful" : " CurieImu connection failed" );
68
-
69
- #ifdef CALIBRATE_ACCELGRYO_OFFSETS
70
- // use the code below to calibrate accel/gyro offset values
71
- Serial.println (" Internal sensor offsets BEFORE calibration..." );
72
- Serial.print (CurieImu.getXAccelOffset ()); Serial.print (" \t " ); // -76
73
- Serial.print (CurieImu.getYAccelOffset ()); Serial.print (" \t " ); // -235
74
- Serial.print (CurieImu.getZAccelOffset ()); Serial.print (" \t " ); // 168
75
- Serial.print (CurieImu.getXGyroOffset ()); Serial.print (" \t " ); // 0
76
- Serial.print (CurieImu.getYGyroOffset ()); Serial.print (" \t " ); // 0
77
- Serial.print (CurieImu.getZGyroOffset ()); Serial.print (" \t " ); // 0
78
- Serial.println (" " );
79
-
80
- // To manually configure offset compensation values, use the following methods instead of the autoCalibrate...() methods below
81
- // CurieImu.setXGyroOffset(220);
82
- // CurieImu.setYGyroOffset(76);
83
- // CurieImu.setZGyroOffset(-85);
84
- // CurieImu.setXAccelOffset(-76);
85
- // CurieImu.setYAccelOffset(--235);
86
- // CurieImu.setZAccelOffset(168);
87
-
88
- // IMU device must be resting in a horizontal position for the following calibration procedure to work correctly!
89
- Serial.print (" Starting Gyroscope calibration..." );
90
- CurieImu.autoCalibrateGyroOffset ();
91
- Serial.println (" Done" );
92
- Serial.print (" Starting Acceleration calibration..." );
93
- CurieImu.autoCalibrateXAccelOffset (0 );
94
- CurieImu.autoCalibrateYAccelOffset (0 );
95
- CurieImu.autoCalibrateZAccelOffset (1 );
96
- Serial.println (" Done" );
97
-
98
- Serial.println (" Internal sensor offsets AFTER calibration..." );
99
- Serial.print (CurieImu.getXAccelOffset ()); Serial.print (" \t " ); // -76
100
- Serial.print (CurieImu.getYAccelOffset ()); Serial.print (" \t " ); // -2359
101
- Serial.print (CurieImu.getZAccelOffset ()); Serial.print (" \t " ); // 1688
102
- Serial.print (CurieImu.getXGyroOffset ()); Serial.print (" \t " ); // 0
103
- Serial.print (CurieImu.getYGyroOffset ()); Serial.print (" \t " ); // 0
104
- Serial.print (CurieImu.getZGyroOffset ()); Serial.print (" \t " ); // 0
105
- Serial.println (" " );
106
-
107
- Serial.println (" Enabling Gyroscope/Acceleration offset compensation" );
108
- CurieImu.setGyroOffsetEnabled (true );
109
- CurieImu.setAccelOffsetEnabled (true );
110
- #endif
111
-
112
- // configure Arduino LED for
113
- pinMode (LED_PIN, OUTPUT);
42
+ Serial.begin (9600 ); // initialize Serial communication
43
+ while (!Serial); // wait for the serial port to open
44
+
45
+ // initialize device
46
+ Serial.println (" Initializing IMU device..." );
47
+ CurieImu.initialize ();
48
+
49
+ // verify connection
50
+ Serial.println (" Testing device connections..." );
51
+ if (CurieImu.testConnection ()) {
52
+ Serial.println (" CurieImu connection successful" );
53
+ } else {
54
+ Serial.println (" CurieImu connection failed" );
55
+ }
56
+
57
+ // 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 );
82
+
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
+ // configure Arduino LED for activity indicator
112
+ pinMode (ledPin, OUTPUT);
114
113
}
115
114
116
115
void loop () {
117
- // read raw accel/gyro measurements from device
118
- CurieImu.getMotion6 (&ax, &ay, &az, &gx, &gy, &gz);
119
-
120
- // these methods (and a few others) are also available
121
- // CurieImu.getAcceleration(&ax, &ay, &az);
122
- // CurieImu.getRotation(&gx, &gy, &gz);
123
-
124
- #ifdef OUTPUT_READABLE_ACCELGYRO
125
- // display tab-separated accel/gyro x/y/z values
126
- Serial.print (" a/g:\t " );
127
- Serial.print (ax); Serial.print (" \t " );
128
- Serial.print (ay); Serial.print (" \t " );
129
- Serial.print (az); Serial.print (" \t " );
130
- Serial.print (gx); Serial.print (" \t " );
131
- Serial.print (gy); Serial.print (" \t " );
132
- Serial.println (gz);
133
- #endif
134
-
135
- #ifdef OUTPUT_BINARY_ACCELGYRO
136
- Serial.write ((uint8_t )(ax >> 8 )); Serial.write ((uint8_t )(ax & 0xFF ));
137
- Serial.write ((uint8_t )(ay >> 8 )); Serial.write ((uint8_t )(ay & 0xFF ));
138
- Serial.write ((uint8_t )(az >> 8 )); Serial.write ((uint8_t )(az & 0xFF ));
139
- Serial.write ((uint8_t )(gx >> 8 )); Serial.write ((uint8_t )(gx & 0xFF ));
140
- Serial.write ((uint8_t )(gy >> 8 )); Serial.write ((uint8_t )(gy & 0xFF ));
141
- Serial.write ((uint8_t )(gz >> 8 )); Serial.write ((uint8_t )(gz & 0xFF ));
142
- #endif
143
-
144
- // blink LED to indicate activity
145
- blinkState = !blinkState;
146
- digitalWrite (LED_PIN, blinkState);
147
- }
116
+ // read raw accel/gyro measurements from device
117
+ CurieImu.getMotion6 (&ax, &ay, &az, &gx, &gy, &gz);
118
+
119
+ // these methods (and a few others) are also available
120
+ // CurieImu.getAcceleration(&ax, &ay, &az);
121
+ // CurieImu.getRotation(&gx, &gy, &gz);
122
+
123
+ // display tab-separated accel/gyro x/y/z values
124
+ Serial.print (" a/g:\t " );
125
+ Serial.print (ax);
126
+ Serial.print (" \t " );
127
+ Serial.print (ay);
128
+ Serial.print (" \t " );
129
+ Serial.print (az);
130
+ Serial.print (" \t " );
131
+ Serial.print (gx);
132
+ Serial.print (" \t " );
133
+ Serial.print (gy);
134
+ Serial.print (" \t " );
135
+ Serial.println (gz);
136
+
137
+ // blink LED to indicate activity
138
+ blinkState = !blinkState;
139
+ digitalWrite (ledPin, blinkState);
140
+ }
0 commit comments