Skip to content

Commit e093df3

Browse files
committed
Merge pull request #80 from sandeepmistry/imu
CurieImu examples updates and keywords.txt
2 parents 39881ec + f6c59c1 commit e093df3

File tree

9 files changed

+564
-258
lines changed

9 files changed

+564
-258
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,147 +1,140 @@
11
/*
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+
===============================================
3131
*/
3232

3333
#include "CurieImu.h"
3434

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
3737

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
5640

5741
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);
114113
}
115114

116115
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+
}

libraries/CurieImu/examples/RawImuDataSerial/RawImuDataSerial.txt

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,71 @@
11
/*
2-
* Copyright (c) 2015 Intel Corporation. All rights reserved.
3-
*
4-
* This library is free software; you can redistribute it and/or
5-
* modify it under the terms of the GNU Lesser General Public
6-
* License as published by the Free Software Foundation; either
7-
* version 2.1 of the License, or (at your option) any later version.
2+
Copyright (c) 2015 Intel Corporation. All rights reserved.
83
9-
* This library is distributed in the hope that it will be useful,
10-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12-
* Lesser General Public License for more details.
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
138
14-
* You should have received a copy of the GNU Lesser General Public
15-
* License along with this library; if not, write to the Free Software
16-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17-
*
18-
*/
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17+
18+
*/
1919

2020
/*
21-
* This sketch example demonstrates how the BMI160 accelerometer on the
22-
* Intel(R) Curie(TM) module can be used to detect shocks or sudden movements
23-
*/
21+
This sketch example demonstrates how the BMI160 accelerometer on the
22+
Intel(R) Curie(TM) module can be used to detect shocks or sudden movements
23+
*/
2424

2525
#include "CurieImu.h"
2626

27-
static void eventCallback(void)
28-
{
29-
if (CurieImu.getIntShockStatus()) {
30-
if (CurieImu.getXNegShockDetected())
31-
Serial.println("Negative shock detected on X-axis");
32-
if (CurieImu.getXPosShockDetected())
33-
Serial.println("Positive shock detected on X-axis");
34-
if (CurieImu.getYNegShockDetected())
35-
Serial.println("Negative shock detected on Y-axis");
36-
if (CurieImu.getYPosShockDetected())
37-
Serial.println("Positive shock detected on Y-axis");
38-
if (CurieImu.getZNegShockDetected())
39-
Serial.println("Negative shock detected on Z-axis");
40-
if (CurieImu.getZPosShockDetected())
41-
Serial.println("Positive shock detected on Z-axis");
42-
}
43-
}
27+
boolean blinkState = false; // state of the LED
4428

4529
void setup() {
46-
Serial.begin(115200);
30+
Serial.begin(9600);
4731

48-
/* Initialise the IMU */
49-
CurieImu.initialize();
50-
CurieImu.attachInterrupt(eventCallback);
32+
/* Initialise the IMU */
33+
CurieImu.initialize();
34+
CurieImu.attachInterrupt(eventCallback);
5135

52-
/* Enable Shock Detection */
53-
CurieImu.setShockDetectionThreshold(192); // 1.5g
54-
CurieImu.setShockDetectionDuration(11); // 30ms
55-
CurieImu.setIntShockEnabled(true);
36+
/* Enable Shock Detection */
37+
CurieImu.setShockDetectionThreshold(192); // 1.5g
38+
CurieImu.setShockDetectionDuration(11); // 30ms
39+
CurieImu.setIntShockEnabled(true);
5640

57-
/* Enable Interrupts Notifications */
58-
CurieImu.setIntEnabled(true);
41+
/* Enable Interrupts Notifications */
42+
CurieImu.setIntEnabled(true);
5943

60-
Serial.println("IMU initialisation complete, waiting for events...");
44+
Serial.println("IMU initialisation complete, waiting for events...");
6145
}
6246

6347
void loop() {
48+
// blink the LED in the main loop:
49+
digitalWrite(13, blinkState);
50+
blinkState = !blinkState;
51+
delay(1000);
52+
}
53+
54+
55+
static void eventCallback(void)
56+
{
57+
if (CurieImu.getIntShockStatus()) {
58+
if (CurieImu.getXNegShockDetected())
59+
Serial.println("Negative shock detected on X-axis");
60+
if (CurieImu.getXPosShockDetected())
61+
Serial.println("Positive shock detected on X-axis");
62+
if (CurieImu.getYNegShockDetected())
63+
Serial.println("Negative shock detected on Y-axis");
64+
if (CurieImu.getYPosShockDetected())
65+
Serial.println("Positive shock detected on Y-axis");
66+
if (CurieImu.getZNegShockDetected())
67+
Serial.println("Negative shock detected on Z-axis");
68+
if (CurieImu.getZPosShockDetected())
69+
Serial.println("Positive shock detected on Z-axis");
70+
}
6471
}

libraries/CurieImu/examples/ShockDetect/ShockDetect.txt

-1
This file was deleted.

0 commit comments

Comments
 (0)