Skip to content

CurieImu examples updates and keywords.txt #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
265 changes: 129 additions & 136 deletions libraries/CurieImu/examples/RawImuDataSerial/RawImuDataSerial.ino
Original file line number Diff line number Diff line change
@@ -1,147 +1,140 @@
/*
===============================================
Example sketch for CurieImu library for Intel(R) Curie(TM) devices.
Copyright (c) 2015 Intel Corporation. All rights reserved.

Based on I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050
class by Jeff Rowberg: https://github.com/jrowberg/i2cdevlib

===============================================
I2Cdev device library code is placed under the MIT license
Copyright (c) 2011 Jeff Rowberg

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
===============================================
===============================================
Example sketch for CurieImu library for Intel(R) Curie(TM) devices.
Copyright (c) 2015 Intel Corporation. All rights reserved.

Based on I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050
class by Jeff Rowberg: https://github.com/jrowberg/i2cdevlib

===============================================
I2Cdev device library code is placed under the MIT license
Copyright (c) 2011 Jeff Rowberg

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
===============================================
*/

#include "CurieImu.h"

int16_t ax, ay, az;
int16_t gx, gy, gz;
int16_t ax, ay, az; // accelerometer values
int16_t gx, gy, gz; // gyrometer values

// uncomment "OUTPUT_READABLE_ACCELGYRO" if you want to see a tab-separated
// list of the accel X/Y/Z and then gyro X/Y/Z values in decimal. Easy to read,
// not so easy to parse, and slow(er) over UART.
#define OUTPUT_READABLE_ACCELGYRO

// uncomment "OUTPUT_BINARY_ACCELGYRO" to send all 6 axes of data as 16-bit
// binary, one right after the other. This is very fast (as fast as possible
// without compression or data loss), and easy to parse, but impossible to read
// for a human.
//#define OUTPUT_BINARY_ACCELGYRO

// uncomment "CALIBRATE_ACCELGRYO_OFFSETS" to perform auto-calibration of all 6 axes during start-up
// This requires the device to be resting in a horizontal position during the start-up phase
//#define CALIBRATE_ACCELGRYO_OFFSETS


#define LED_PIN 13
bool blinkState = false;
const int ledPin = 13; // activity LED pin
boolean blinkState = false; // state of the LED

void setup() {
// initialize Serial communication
Serial.begin(115200);

// initialize device
Serial.println("Initializing IMU device...");
CurieImu.initialize();

// verify connection
Serial.println("Testing device connections...");
Serial.println(CurieImu.testConnection() ? "CurieImu connection successful" : "CurieImu connection failed");

#ifdef CALIBRATE_ACCELGRYO_OFFSETS
// use the code below to calibrate accel/gyro offset values
Serial.println("Internal sensor offsets BEFORE calibration...");
Serial.print(CurieImu.getXAccelOffset()); Serial.print("\t"); // -76
Serial.print(CurieImu.getYAccelOffset()); Serial.print("\t"); // -235
Serial.print(CurieImu.getZAccelOffset()); Serial.print("\t"); // 168
Serial.print(CurieImu.getXGyroOffset()); Serial.print("\t"); // 0
Serial.print(CurieImu.getYGyroOffset()); Serial.print("\t"); // 0
Serial.print(CurieImu.getZGyroOffset()); Serial.print("\t"); // 0
Serial.println("");

// To manually configure offset compensation values, use the following methods instead of the autoCalibrate...() methods below
// CurieImu.setXGyroOffset(220);
// CurieImu.setYGyroOffset(76);
// CurieImu.setZGyroOffset(-85);
// CurieImu.setXAccelOffset(-76);
// CurieImu.setYAccelOffset(--235);
// CurieImu.setZAccelOffset(168);

// IMU device must be resting in a horizontal position for the following calibration procedure to work correctly!
Serial.print("Starting Gyroscope calibration...");
CurieImu.autoCalibrateGyroOffset();
Serial.println(" Done");
Serial.print("Starting Acceleration calibration...");
CurieImu.autoCalibrateXAccelOffset(0);
CurieImu.autoCalibrateYAccelOffset(0);
CurieImu.autoCalibrateZAccelOffset(1);
Serial.println(" Done");

Serial.println("Internal sensor offsets AFTER calibration...");
Serial.print(CurieImu.getXAccelOffset()); Serial.print("\t"); // -76
Serial.print(CurieImu.getYAccelOffset()); Serial.print("\t"); // -2359
Serial.print(CurieImu.getZAccelOffset()); Serial.print("\t"); // 1688
Serial.print(CurieImu.getXGyroOffset()); Serial.print("\t"); // 0
Serial.print(CurieImu.getYGyroOffset()); Serial.print("\t"); // 0
Serial.print(CurieImu.getZGyroOffset()); Serial.print("\t"); // 0
Serial.println("");

Serial.println("Enabling Gyroscope/Acceleration offset compensation");
CurieImu.setGyroOffsetEnabled(true);
CurieImu.setAccelOffsetEnabled(true);
#endif

// configure Arduino LED for
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600); // initialize Serial communication
while (!Serial); // wait for the serial port to open

// initialize device
Serial.println("Initializing IMU device...");
CurieImu.initialize();

// verify connection
Serial.println("Testing device connections...");
if (CurieImu.testConnection()) {
Serial.println("CurieImu connection successful");
} else {
Serial.println("CurieImu connection failed");
}

// use the code below to calibrate accel/gyro offset values
Serial.println("Internal sensor offsets BEFORE calibration...");
Serial.print(CurieImu.getXAccelOffset());
Serial.print("\t"); // -76
Serial.print(CurieImu.getYAccelOffset());
Serial.print("\t"); // -235
Serial.print(CurieImu.getZAccelOffset());
Serial.print("\t"); // 168
Serial.print(CurieImu.getXGyroOffset());
Serial.print("\t"); // 0
Serial.print(CurieImu.getYGyroOffset());
Serial.print("\t"); // 0
Serial.println(CurieImu.getZGyroOffset());

// To manually configure offset compensation values,
// use the following methods instead of the autoCalibrate...() methods below
// CurieImu.setXGyroOffset(220);
// CurieImu.setYGyroOffset(76);
// CurieImu.setZGyroOffset(-85);
// CurieImu.setXAccelOffset(-76);
// CurieImu.setYAccelOffset(-235);
// CurieImu.setZAccelOffset(168);

Serial.println("About to calibrate. Make sure your board is stable and upright");
delay(5000);

// The board must be resting in a horizontal position for
// the following calibration procedure to work correctly!
Serial.print("Starting Gyroscope calibration...");
CurieImu.autoCalibrateGyroOffset();
Serial.println(" Done");
Serial.print("Starting Acceleration calibration...");
CurieImu.autoCalibrateXAccelOffset(0);
CurieImu.autoCalibrateYAccelOffset(0);
CurieImu.autoCalibrateZAccelOffset(1);
Serial.println(" Done");

Serial.println("Internal sensor offsets AFTER calibration...");
Serial.print(CurieImu.getXAccelOffset());
Serial.print("\t"); // -76
Serial.print(CurieImu.getYAccelOffset());
Serial.print("\t"); // -2359
Serial.print(CurieImu.getZAccelOffset());
Serial.print("\t"); // 1688
Serial.print(CurieImu.getXGyroOffset());
Serial.print("\t"); // 0
Serial.print(CurieImu.getYGyroOffset());
Serial.print("\t"); // 0
Serial.println(CurieImu.getZGyroOffset());

Serial.println("Enabling Gyroscope/Acceleration offset compensation");
CurieImu.setGyroOffsetEnabled(true);
CurieImu.setAccelOffsetEnabled(true);

// configure Arduino LED for activity indicator
pinMode(ledPin, OUTPUT);
}

void loop() {
// read raw accel/gyro measurements from device
CurieImu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

// these methods (and a few others) are also available
//CurieImu.getAcceleration(&ax, &ay, &az);
//CurieImu.getRotation(&gx, &gy, &gz);

#ifdef OUTPUT_READABLE_ACCELGYRO
// display tab-separated accel/gyro x/y/z values
Serial.print("a/g:\t");
Serial.print(ax); Serial.print("\t");
Serial.print(ay); Serial.print("\t");
Serial.print(az); Serial.print("\t");
Serial.print(gx); Serial.print("\t");
Serial.print(gy); Serial.print("\t");
Serial.println(gz);
#endif

#ifdef OUTPUT_BINARY_ACCELGYRO
Serial.write((uint8_t)(ax >> 8)); Serial.write((uint8_t)(ax & 0xFF));
Serial.write((uint8_t)(ay >> 8)); Serial.write((uint8_t)(ay & 0xFF));
Serial.write((uint8_t)(az >> 8)); Serial.write((uint8_t)(az & 0xFF));
Serial.write((uint8_t)(gx >> 8)); Serial.write((uint8_t)(gx & 0xFF));
Serial.write((uint8_t)(gy >> 8)); Serial.write((uint8_t)(gy & 0xFF));
Serial.write((uint8_t)(gz >> 8)); Serial.write((uint8_t)(gz & 0xFF));
#endif

// blink LED to indicate activity
blinkState = !blinkState;
digitalWrite(LED_PIN, blinkState);
}
// read raw accel/gyro measurements from device
CurieImu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

// these methods (and a few others) are also available
//CurieImu.getAcceleration(&ax, &ay, &az);
//CurieImu.getRotation(&gx, &gy, &gz);

// display tab-separated accel/gyro x/y/z values
Serial.print("a/g:\t");
Serial.print(ax);
Serial.print("\t");
Serial.print(ay);
Serial.print("\t");
Serial.print(az);
Serial.print("\t");
Serial.print(gx);
Serial.print("\t");
Serial.print(gy);
Serial.print("\t");
Serial.println(gz);

// blink LED to indicate activity
blinkState = !blinkState;
digitalWrite(ledPin, blinkState);
}

This file was deleted.

99 changes: 53 additions & 46 deletions libraries/CurieImu/examples/ShockDetect/ShockDetect.ino
Original file line number Diff line number Diff line change
@@ -1,64 +1,71 @@
/*
* Copyright (c) 2015 Intel Corporation. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
Copyright (c) 2015 Intel Corporation. All rights reserved.

* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

*/

/*
* This sketch example demonstrates how the BMI160 accelerometer on the
* Intel(R) Curie(TM) module can be used to detect shocks or sudden movements
*/
This sketch example demonstrates how the BMI160 accelerometer on the
Intel(R) Curie(TM) module can be used to detect shocks or sudden movements
*/

#include "CurieImu.h"

static void eventCallback(void)
{
if (CurieImu.getIntShockStatus()) {
if (CurieImu.getXNegShockDetected())
Serial.println("Negative shock detected on X-axis");
if (CurieImu.getXPosShockDetected())
Serial.println("Positive shock detected on X-axis");
if (CurieImu.getYNegShockDetected())
Serial.println("Negative shock detected on Y-axis");
if (CurieImu.getYPosShockDetected())
Serial.println("Positive shock detected on Y-axis");
if (CurieImu.getZNegShockDetected())
Serial.println("Negative shock detected on Z-axis");
if (CurieImu.getZPosShockDetected())
Serial.println("Positive shock detected on Z-axis");
}
}
boolean blinkState = false; // state of the LED

void setup() {
Serial.begin(115200);
Serial.begin(9600);

/* Initialise the IMU */
CurieImu.initialize();
CurieImu.attachInterrupt(eventCallback);
/* Initialise the IMU */
CurieImu.initialize();
CurieImu.attachInterrupt(eventCallback);

/* Enable Shock Detection */
CurieImu.setShockDetectionThreshold(192); // 1.5g
CurieImu.setShockDetectionDuration(11); // 30ms
CurieImu.setIntShockEnabled(true);
/* Enable Shock Detection */
CurieImu.setShockDetectionThreshold(192); // 1.5g
CurieImu.setShockDetectionDuration(11); // 30ms
CurieImu.setIntShockEnabled(true);

/* Enable Interrupts Notifications */
CurieImu.setIntEnabled(true);
/* Enable Interrupts Notifications */
CurieImu.setIntEnabled(true);

Serial.println("IMU initialisation complete, waiting for events...");
Serial.println("IMU initialisation complete, waiting for events...");
}

void loop() {
// blink the LED in the main loop:
digitalWrite(13, blinkState);
blinkState = !blinkState;
delay(1000);
}


static void eventCallback(void)
{
if (CurieImu.getIntShockStatus()) {
if (CurieImu.getXNegShockDetected())
Serial.println("Negative shock detected on X-axis");
if (CurieImu.getXPosShockDetected())
Serial.println("Positive shock detected on X-axis");
if (CurieImu.getYNegShockDetected())
Serial.println("Negative shock detected on Y-axis");
if (CurieImu.getYPosShockDetected())
Serial.println("Positive shock detected on Y-axis");
if (CurieImu.getZNegShockDetected())
Serial.println("Negative shock detected on Z-axis");
if (CurieImu.getZPosShockDetected())
Serial.println("Positive shock detected on Z-axis");
}
}
1 change: 0 additions & 1 deletion libraries/CurieImu/examples/ShockDetect/ShockDetect.txt

This file was deleted.

Loading