Skip to content

Commit e5a1c21

Browse files
committed
Example updates from Helena
1 parent 0b57d5e commit e5a1c21

File tree

4 files changed

+117
-102
lines changed

4 files changed

+117
-102
lines changed
Lines changed: 81 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
===============================================
3-
Example sketch for CurieImu library for Intel(R) Curie(TM) devices.
3+
Example sketch for CurieIMU library for Intel(R) Curie(TM) devices.
44
Copyright (c) 2015 Intel Corporation. All rights reserved.
55
66
Based on I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050
@@ -31,98 +31,113 @@
3131
*/
3232

3333
#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
3736

3837
const int ledPin = 13; // activity LED pin
3938
boolean blinkState = false; // state of the LED
4039

40+
int calibrateOffsets = 1; // int to determine whether calibration takes place or not
41+
4142
void setup() {
4243
Serial.begin(9600); // initialize Serial communication
4344
while (!Serial); // wait for the serial port to open
4445

4546
// initialize device
4647
Serial.println("Initializing IMU device...");
47-
CurieImu.initialize();
48+
CurieIMU.begin();
4849

4950
// verify connection
5051
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");
5354
} else {
54-
Serial.println("CurieImu connection failed");
55+
Serial.println("CurieIMU connection failed");
5556
}
56-
57+
5758
// 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+
}
82117

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-
111118
// configure Arduino LED for activity indicator
112119
pinMode(ledPin, OUTPUT);
113120
}
114121

115122
void loop() {
116123
// 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);
118125

119126
// 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);
122137

123138
// display tab-separated accel/gyro x/y/z values
124139
Serial.print("a/g:\t");
125-
Serial.print(ax);
140+
Serial.print(az);
126141
Serial.print("\t");
127142
Serial.print(ay);
128143
Serial.print("\t");
@@ -137,4 +152,4 @@ void loop() {
137152
// blink LED to indicate activity
138153
blinkState = !blinkState;
139154
digitalWrite(ledPin, blinkState);
140-
}
155+
}

libraries/CurieImu/examples/ShockDetect/ShockDetect.ino

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ void setup() {
3030
Serial.begin(9600);
3131

3232
/* Initialise the IMU */
33-
CurieImu.initialize();
34-
CurieImu.attachInterrupt(eventCallback);
33+
CurieIMU.begin();
34+
CurieIMU.attachInterrupt(eventCallback);
3535

3636
/* Enable Shock Detection */
37-
CurieImu.setShockDetectionThreshold(192); // 1.5g
38-
CurieImu.setShockDetectionDuration(11); // 30ms
39-
CurieImu.setIntShockEnabled(true);
37+
CurieIMU.setDetectionThreshold(CURIE_IMU_SHOCK, 192); // 1.5g
38+
CurieIMU.setDetectionDuration(CURIE_IMU_SHOCK,11); // 30ms
39+
CurieIMU.enableInterrupt(CURIE_IMU_SHOCK,true);
4040

4141
/* Enable Interrupts Notifications */
42-
CurieImu.setIntEnabled(true);
42+
CurieIMU.setIntEnabled(true);
4343

4444
Serial.println("IMU initialisation complete, waiting for events...");
4545
}
@@ -54,18 +54,18 @@ void loop() {
5454

5555
static void eventCallback(void)
5656
{
57-
if (CurieImu.getIntShockStatus()) {
58-
if (CurieImu.getXNegShockDetected())
57+
if (CurieIMU.getInterruptStatus(CURIE_IMU_SHOCK)) {
58+
if (CurieIMU.shockDetected(X_AXIS,POSITIVE))
5959
Serial.println("Negative shock detected on X-axis");
60-
if (CurieImu.getXPosShockDetected())
60+
if (CurieIMU.shockDetected(X_AXIS,NEGATIVE))
6161
Serial.println("Positive shock detected on X-axis");
62-
if (CurieImu.getYNegShockDetected())
62+
if (CurieIMU.shockDetected(Y_AXIS,POSITIVE))
6363
Serial.println("Negative shock detected on Y-axis");
64-
if (CurieImu.getYPosShockDetected())
64+
if (CurieIMU.shockDetected(Y_AXIS,NEGATIVE))
6565
Serial.println("Positive shock detected on Y-axis");
66-
if (CurieImu.getZNegShockDetected())
66+
if (CurieIMU.shockDetected(Z_AXIS,POSITIVE))
6767
Serial.println("Negative shock detected on Z-axis");
68-
if (CurieImu.getZPosShockDetected())
68+
if (CurieIMU.shockDetected(Z_AXIS,NEGATIVE))
6969
Serial.println("Positive shock detected on Z-axis");
7070
}
71-
}
71+
}

libraries/CurieImu/examples/StepCount/StepCount.ino

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,18 @@ void setup() {
4242
Serial.begin(9600);
4343
// pinMode(13, OUTPUT);
4444
// intialize the sensor:
45-
CurieImu.initialize();
45+
CurieIMU.begin();
4646
// turn on step detection mode:
47-
CurieImu.setStepDetectionMode(BMI160_STEP_MODE_NORMAL);
47+
CurieIMU.setStepDetectionMode(CURIE_IMU_STEP_MODE_NORMAL);
4848
// enable step counting:
49-
CurieImu.setStepCountEnabled(true);
49+
CurieIMU.setStepCountEnabled(true);
5050

5151
if (stepEventsEnabeled) {
5252
// attach the eventCallback function as the
5353
// step event handler:
54-
CurieImu.attachInterrupt(eventCallback);
55-
CurieImu.setIntStepEnabled(true); // turn on step detection
56-
CurieImu.setIntEnabled(true); // enable interrupts
54+
CurieIMU.attachInterrupt(eventCallback);
55+
CurieIMU.enableInterrupt(CURIE_IMU_STEP,true); // turn on step detection
56+
CurieIMU.setIntEnabled(true); // enable interrupts
5757

5858
Serial.println("IMU initialisation complete, waiting for events...");
5959
}
@@ -72,7 +72,7 @@ void loop() {
7272

7373
static void updateStepCount() {
7474
// get the step count:
75-
int stepCount = CurieImu.getStepCount();
75+
int stepCount = CurieIMU.getStepCount();
7676

7777
// if the step count has changed, print it:
7878
if (stepCount != lastStepCount) {
@@ -84,6 +84,6 @@ static void updateStepCount() {
8484
}
8585

8686
static void eventCallback(void) {
87-
if (CurieImu.getIntStepStatus())
87+
if (CurieIMU.stepsDetected())
8888
updateStepCount();
8989
}

libraries/CurieImu/examples/TapDetect/TapDetect.ino

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,23 @@ void setup() {
2828
Serial.begin(9600);
2929

3030
// Initialise the IMU
31-
CurieImu.initialize();
32-
CurieImu.attachInterrupt(eventCallback);
31+
CurieIMU.begin();
32+
CurieIMU.attachInterrupt(eventCallback);
3333

3434
// Increase Accelerometer range to allow detection of stronger taps (< 4g)
35-
CurieImu.setFullScaleAccelRange(BMI160_ACCEL_RANGE_4G);
35+
CurieIMU.setAccelerometerRange(4);
3636

3737
// Reduce threshold to allow detection of weaker taps (>= 750mg)
38-
CurieImu.setTapDetectionThreshold(6); // (6 x 125mg)
38+
CurieIMU.setDetectionThreshold(CURIE_IMU_TAP,6); // (6 x 125mg)
3939

4040
// Set the time window for 2 taps to be registered as a double-tap (<= 250 milliseconds)
41-
CurieImu.setDoubleTapDetectionDuration(BMI160_DOUBLE_TAP_DURATION_250MS);
41+
CurieIMU.setDetectionDuration(CURIE_IMU_DOUBLE_TAP,250);
4242

4343
// Enable Double-Tap detection
44-
CurieImu.setIntDoubleTapEnabled(true);
44+
CurieIMU.enableInterrupt(CURIE_IMU_DOUBLE_TAP,true);
4545

4646
// Enable Interrupts Notifications
47-
CurieImu.setIntEnabled(true);
47+
CurieIMU.setIntEnabled(true);
4848

4949
Serial.println("IMU initialisation complete, waiting for events...");
5050
}
@@ -56,18 +56,18 @@ void loop() {
5656

5757
static void eventCallback()
5858
{
59-
if (CurieImu.getIntDoubleTapStatus()) {
60-
if (CurieImu.getXNegTapDetected())
59+
if (CurieIMU.getInterruptStatus(CURIE_IMU_DOUBLE_TAP)) {
60+
if (CurieIMU.tapDetected(X_AXIS,NEGATIVE))
6161
Serial.println("Double Tap detected on negative X-axis");
62-
if (CurieImu.getXPosTapDetected())
62+
if (CurieIMU.tapDetected(X_AXIS,POSITIVE))
6363
Serial.println("Double Tap detected on positive X-axis");
64-
if (CurieImu.getYNegTapDetected())
64+
if (CurieIMU.tapDetected(Y_AXIS,NEGATIVE))
6565
Serial.println("Double Tap detected on negative Y-axis");
66-
if (CurieImu.getYPosTapDetected())
66+
if (CurieIMU.tapDetected(Y_AXIS,POSITIVE))
6767
Serial.println("Double Tap detected on positive Y-axis");
68-
if (CurieImu.getZNegTapDetected())
68+
if (CurieIMU.tapDetected(Z_AXIS,NEGATIVE))
6969
Serial.println("Double Tap detected on negative Z-axis");
70-
if (CurieImu.getZPosTapDetected())
70+
if (CurieIMU.tapDetected(Z_AXIS,POSITIVE))
7171
Serial.println("Double Tap detected on positive Z-axis");
7272
}
7373
}

0 commit comments

Comments
 (0)