Skip to content

Commit 2865253

Browse files
author
Jim Lindblom
committed
Merge commit '17051b5ca8315b8b138d17a91812da3ebf3e0627' as 'Libraries/Arduino'
2 parents 499d78f + 17051b5 commit 2865253

28 files changed

+8281
-0
lines changed

Libraries/Arduino/LICENSE.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
SparkFun License Information
2+
============================
3+
4+
**SparkFun code, firmware, and software is released under the [MIT License](http://opensource.org/licenses/MIT).**
5+
6+
The MIT License (MIT)
7+
8+
Copyright (c) 2016 SparkFun Electronics, Inc.
9+
10+
Permission is hereby granted, free of charge, to any person obtaining a copy
11+
of this software and associated documentation files (the "Software"), to deal
12+
in the Software without restriction, including without limitation the rights
13+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
copies of the Software, and to permit persons to whom the Software is
15+
furnished to do so, subject to the following conditions:
16+
17+
The above copyright notice and this permission notice shall be included in all
18+
copies or substantial portions of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26+
SOFTWARE.
27+
28+

Libraries/Arduino/README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
SparkFun MPU-9250 Digital Motion Processor (DMP) Arduino Library
2+
========================================
3+
4+
[![SparkFun MPU-9250](https://cdn.sparkfun.com//assets/parts/1/1/3/0/6/13762-00a.jpg)](https://www.sparkfun.com/products/13762)
5+
6+
[*SparkFun MPU-9250 (SEN-13762)*](https://www.sparkfun.com/products/13762)
7+
8+
Advanced Arduino library for the Invensense MPU-9250 inertial measurement unit (IMU), which enables the sensor's digital motion processing (DMP) features. Along with configuring and reading from the accelerometer, gyroscope, and magnetometer, this library also supports the chip's DMP features like:
9+
10+
* Quaternion calculation
11+
* Pedometer
12+
* Gyroscope calibration
13+
* Tap detection
14+
* Orientation dtection
15+
16+
For help getting started with this library, refer to the [Using the MPU-9250 DMP Arduino Library](https://learn.sparkfun.com/tutorials/9dof-razor-imu-m0-hookup-guide#using-the-mpu-9250-dmp-arduino-library) section of the 9DoF Razor IMU M0 Hookup Guide.
17+
18+
**Note**: This library currently only supports and is tested on **SAMD processors**. It's a major part of the [SparkFun 9DoF Razor IMU M0](https://www.sparkfun.com/products/14001) firmware.
19+
20+
Repository Contents
21+
-------------------
22+
23+
* **/examples** - Example sketches for the library (.ino). Run these from the Arduino IDE.
24+
* **/src** - Source files for the library (.cpp, .h).
25+
* **/src/util** - Source and headers for the MPU-9250 driver and dmp configuration. These are available and adapted from [Invensene's downloads page](https://www.invensense.com/developers/software-downloads/#sla_content_45).
26+
* **keywords.txt** - Keywords from this library that will be highlighted in the Arduino IDE.
27+
* **library.properties** - General library properties for the Arduino package manager.
28+
29+
Documentation
30+
--------------
31+
32+
* **[Installing an Arduino Library Guide](https://learn.sparkfun.com/tutorials/installing-an-arduino-library)** - Basic information on how to install an Arduino library.
33+
* **[SparkFun 9DoF Razor IMU M0 Repository](https://github.com/sparkfun/9DOF_Razor_IMU)** - Main repositor (including hardware files) for the MPU-9250-based SparkFun 9DoF Razor IMU M0
34+
* **[MPU-9250 Breakout Repository](https://github.com/sparkfun/MPU-9250_Breakout)** - Main repository (including hardware files) for the MPU-9250 Breakout.
35+
* **[Hookup Guide](https://learn.sparkfun.com/tutorials/9dof-razor-imu-m0-hookup-guide)** - Basic hookup guide for the SparkFun 9DoF Razor IMU M0, including a [section on using this library](https://learn.sparkfun.com/tutorials/9dof-razor-imu-m0-hookup-guide#using-the-mpu-9250-dmp-arduino-library).
36+
37+
Products that use this Library
38+
---------------------------------
39+
40+
* [SparkFun 9DoF Razor IMU M0 (SEN-14001)](https://www.sparkfun.com/products/14001)- An MPU-9250 development board, which includes an Arduino-compatible SAMD21 processor, LiPo battery charger, and USB interface.
41+
* [SparkFun MPU-9250 Breakout (SEN-13762)](https://www.sparkfun.com/products/13762)- Easily adaptible breakout board for the MPU-9250.
42+
43+
Version History
44+
---------------
45+
46+
47+
License Information
48+
-------------------
49+
50+
This product is _**open source**_!
51+
52+
Please review the LICENSE.md file for license information.
53+
54+
If you have any questions or concerns on licensing, please contact [email protected].
55+
56+
Distributed as-is; no warranty is given.
57+
58+
- Your friends at SparkFun.
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/************************************************************
2+
MPU9250_Basic
3+
Basic example sketch for MPU-9250 DMP Arduino Library
4+
Jim Lindblom @ SparkFun Electronics
5+
original creation date: November 23, 2016
6+
https://github.com/sparkfun/SparkFun_MPU9250_DMP_Arduino_Library
7+
8+
This example sketch demonstrates how to initialize the
9+
MPU-9250, and stream its sensor outputs to a serial monitor.
10+
11+
Development environment specifics:
12+
Arduino IDE 1.6.12
13+
SparkFun 9DoF Razor IMU M0
14+
15+
Supported Platforms:
16+
- ATSAMD21 (Arduino Zero, SparkFun SAMD21 Breakouts)
17+
*************************************************************/
18+
#include <SparkFunMPU9250-DMP.h>
19+
20+
#define SerialPort SerialUSB
21+
22+
MPU9250_DMP imu;
23+
24+
void setup()
25+
{
26+
SerialPort.begin(115200);
27+
28+
// Call imu.begin() to verify communication with and
29+
// initialize the MPU-9250 to it's default values.
30+
// Most functions return an error code - INV_SUCCESS (0)
31+
// indicates the IMU was present and successfully set up
32+
if (imu.begin() != INV_SUCCESS)
33+
{
34+
while (1)
35+
{
36+
SerialPort.println("Unable to communicate with MPU-9250");
37+
SerialPort.println("Check connections, and try again.");
38+
SerialPort.println();
39+
delay(5000);
40+
}
41+
}
42+
43+
// Use setSensors to turn on or off MPU-9250 sensors.
44+
// Any of the following defines can be combined:
45+
// INV_XYZ_GYRO, INV_XYZ_ACCEL, INV_XYZ_COMPASS,
46+
// INV_X_GYRO, INV_Y_GYRO, or INV_Z_GYRO
47+
// Enable all sensors:
48+
imu.setSensors(INV_XYZ_GYRO | INV_XYZ_ACCEL | INV_XYZ_COMPASS);
49+
50+
// Use setGyroFSR() and setAccelFSR() to configure the
51+
// gyroscope and accelerometer full scale ranges.
52+
// Gyro options are +/- 250, 500, 1000, or 2000 dps
53+
imu.setGyroFSR(2000); // Set gyro to 2000 dps
54+
// Accel options are +/- 2, 4, 8, or 16 g
55+
imu.setAccelFSR(2); // Set accel to +/-2g
56+
// Note: the MPU-9250's magnetometer FSR is set at
57+
// +/- 4912 uT (micro-tesla's)
58+
59+
// setLPF() can be used to set the digital low-pass filter
60+
// of the accelerometer and gyroscope.
61+
// Can be any of the following: 188, 98, 42, 20, 10, 5
62+
// (values are in Hz).
63+
imu.setLPF(5); // Set LPF corner frequency to 5Hz
64+
65+
// The sample rate of the accel/gyro can be set using
66+
// setSampleRate. Acceptable values range from 4Hz to 1kHz
67+
imu.setSampleRate(10); // Set sample rate to 10Hz
68+
69+
// Likewise, the compass (magnetometer) sample rate can be
70+
// set using the setCompassSampleRate() function.
71+
// This value can range between: 1-100Hz
72+
imu.setCompassSampleRate(10); // Set mag rate to 10Hz
73+
}
74+
75+
void loop()
76+
{
77+
// dataReady() checks to see if new accel/gyro data
78+
// is available. It will return a boolean true or false
79+
// (New magnetometer data cannot be checked, as the library
80+
// runs that sensor in single-conversion mode.)
81+
if ( imu.dataReady() )
82+
{
83+
// Call update() to update the imu objects sensor data.
84+
// You can specify which sensors to update by combining
85+
// UPDATE_ACCEL, UPDATE_GYRO, UPDATE_COMPASS, and/or
86+
// UPDATE_TEMPERATURE.
87+
// (The update function defaults to accel, gyro, compass,
88+
// so you don't have to specify these values.)
89+
imu.update(UPDATE_ACCEL | UPDATE_GYRO | UPDATE_COMPASS);
90+
printIMUData();
91+
}
92+
}
93+
94+
void printIMUData(void)
95+
{
96+
// After calling update() the ax, ay, az, gx, gy, gz, mx,
97+
// my, mz, time, and/or temerature class variables are all
98+
// updated. Access them by placing the object. in front:
99+
100+
// Use the calcAccel, calcGyro, and calcMag functions to
101+
// convert the raw sensor readings (signed 16-bit values)
102+
// to their respective units.
103+
float accelX = imu.calcAccel(imu.ax);
104+
float accelY = imu.calcAccel(imu.ay);
105+
float accelZ = imu.calcAccel(imu.az);
106+
float gyroX = imu.calcGyro(imu.gx);
107+
float gyroY = imu.calcGyro(imu.gy);
108+
float gyroZ = imu.calcGyro(imu.gz);
109+
float magX = imu.calcMag(imu.mx);
110+
float magY = imu.calcMag(imu.my);
111+
float magZ = imu.calcMag(imu.mz);
112+
113+
SerialPort.println("Accel: " + String(accelX) + ", " +
114+
String(accelY) + ", " + String(accelZ) + " g");
115+
SerialPort.println("Gyro: " + String(gyroX) + ", " +
116+
String(gyroY) + ", " + String(gyroZ) + " dps");
117+
SerialPort.println("Mag: " + String(magX) + ", " +
118+
String(magY) + ", " + String(magZ) + " uT");
119+
SerialPort.println("Time: " + String(imu.time) + " ms");
120+
SerialPort.println();
121+
}
122+
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/************************************************************
2+
MPU9250_Basic_Interrupt
3+
Basic interrupt sketch for MPU-9250 DMP Arduino Library
4+
Jim Lindblom @ SparkFun Electronics
5+
original creation date: November 23, 2016
6+
https://github.com/sparkfun/SparkFun_MPU9250_DMP_Arduino_Library
7+
8+
This example sketch demonstrates how to initialize the
9+
MPU-9250, and stream its sensor outputs to a serial monitor.
10+
It uses the MPU-9250's interrupt output to indicate when
11+
new data is ready.
12+
13+
Development environment specifics:
14+
Arduino IDE 1.6.12
15+
SparkFun 9DoF Razor IMU M0 (interrupt on pin 4)
16+
17+
Supported Platforms:
18+
- ATSAMD21 (Arduino Zero, SparkFun SAMD21 Breakouts)
19+
*************************************************************/
20+
#include <SparkFunMPU9250-DMP.h>
21+
22+
#define SerialPort SerialUSB
23+
#define INTERRUPT_PIN 4
24+
25+
MPU9250_DMP imu;
26+
27+
void setup()
28+
{
29+
pinMode(INTERRUPT_PIN, INPUT_PULLUP);
30+
SerialPort.begin(115200);
31+
32+
if (imu.begin() != INV_SUCCESS)
33+
{
34+
while (1)
35+
{
36+
SerialPort.println("Unable to communicate with MPU-9250");
37+
SerialPort.println("Check connections, and try again.");
38+
SerialPort.println();
39+
delay(5000);
40+
}
41+
}
42+
43+
// Enable all sensors, and set sample rates to 4Hz.
44+
// (Slow so we can see the interrupt work.)
45+
imu.setSensors(INV_XYZ_GYRO | INV_XYZ_ACCEL | INV_XYZ_COMPASS);
46+
imu.setSampleRate(4); // Set accel/gyro sample rate to 4Hz
47+
imu.setCompassSampleRate(4); // Set mag rate to 4Hz
48+
49+
// Use enableInterrupt() to configure the MPU-9250's
50+
// interrupt output as a "data ready" indicator.
51+
imu.enableInterrupt();
52+
53+
// The interrupt level can either be active-high or low.
54+
// Configure as active-low, since we'll be using the pin's
55+
// internal pull-up resistor.
56+
// Options are INT_ACTIVE_LOW or INT_ACTIVE_HIGH
57+
imu.setIntLevel(INT_ACTIVE_LOW);
58+
59+
// The interrupt can be set to latch until data has
60+
// been read, or to work as a 50us pulse.
61+
// Use latching method -- we'll read from the sensor
62+
// as soon as we see the pin go LOW.
63+
// Options are INT_LATCHED or INT_50US_PULSE
64+
imu.setIntLatched(INT_LATCHED);
65+
}
66+
67+
void loop()
68+
{
69+
// The interrupt pin is pulled up using an internal pullup
70+
// resistor, and the MPU-9250 is configured to trigger
71+
// the input LOW.
72+
if ( digitalRead(INTERRUPT_PIN) == LOW )
73+
{
74+
// Call update() to update the imu objects sensor data.
75+
imu.update(UPDATE_ACCEL | UPDATE_GYRO | UPDATE_COMPASS);
76+
printIMUData();
77+
}
78+
}
79+
80+
void printIMUData(void)
81+
{
82+
// After calling update() the ax, ay, az, gx, gy, gz, mx,
83+
// my, mz, time, and/or temerature class variables are all
84+
// updated. Access them by placing the object. in front:
85+
86+
// Use the calcAccel, calcGyro, and calcMag functions to
87+
// convert the raw sensor readings (signed 16-bit values)
88+
// to their respective units.
89+
float accelX = imu.calcAccel(imu.ax);
90+
float accelY = imu.calcAccel(imu.ay);
91+
float accelZ = imu.calcAccel(imu.az);
92+
float gyroX = imu.calcGyro(imu.gx);
93+
float gyroY = imu.calcGyro(imu.gy);
94+
float gyroZ = imu.calcGyro(imu.gz);
95+
float magX = imu.calcMag(imu.mx);
96+
float magY = imu.calcMag(imu.my);
97+
float magZ = imu.calcMag(imu.mz);
98+
99+
SerialPort.println("Accel: " + String(accelX) + ", " +
100+
String(accelY) + ", " + String(accelZ) + " g");
101+
SerialPort.println("Gyro: " + String(gyroX) + ", " +
102+
String(gyroY) + ", " + String(gyroZ) + " dps");
103+
SerialPort.println("Mag: " + String(magX) + ", " +
104+
String(magY) + ", " + String(magZ) + " uT");
105+
SerialPort.println("Time: " + String(imu.time) + " ms");
106+
SerialPort.println();
107+
}
108+
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/************************************************************
2+
MPU9250_DMP_Gyro_Cal
3+
Gyro calibration example for MPU-9250 DMP Arduino Library
4+
Jim Lindblom @ SparkFun Electronics
5+
original creation date: November 23, 2016
6+
https://github.com/sparkfun/SparkFun_MPU9250_DMP_Arduino_Library
7+
8+
This example sketch demonstrates how to use the MPU-9250's
9+
digital motion processor (DMP) to calibrate the gyroscope.
10+
After eight seconds of no motion, the DMP will compute
11+
gyro biases and subtract them.
12+
13+
Development environment specifics:
14+
Arduino IDE 1.6.12
15+
SparkFun 9DoF Razor IMU M0
16+
17+
Supported Platforms:
18+
- ATSAMD21 (Arduino Zero, SparkFun SAMD21 Breakouts)
19+
*************************************************************/
20+
#include <SparkFunMPU9250-DMP.h>
21+
22+
#define SerialPort SerialUSB
23+
24+
MPU9250_DMP imu;
25+
26+
void setup()
27+
{
28+
SerialPort.begin(115200);
29+
30+
// Call imu.begin() to verify communication and initialize
31+
if (imu.begin() != INV_SUCCESS)
32+
{
33+
while (1)
34+
{
35+
SerialPort.println("Unable to communicate with MPU-9250");
36+
SerialPort.println("Check connections, and try again.");
37+
SerialPort.println();
38+
delay(5000);
39+
}
40+
}
41+
42+
imu.setSensors(INV_XYZ_GYRO); // Enable gyroscope only
43+
imu.setGyroFSR(2000); // Set gyro to 2000 dps
44+
45+
imu.dmpBegin(DMP_FEATURE_GYRO_CAL | // Enable gyro cal
46+
DMP_FEATURE_SEND_CAL_GYRO,// Send cal'd gyro values
47+
10); // Set DMP rate to 10 Hz
48+
}
49+
50+
void loop()
51+
{
52+
// Check for new data in the FIFO
53+
if ( imu.fifoAvailable() )
54+
{
55+
// Use dmpUpdateFifo to update the ax, gx, mx, etc. values
56+
if ( imu.dmpUpdateFifo() == INV_SUCCESS)
57+
{
58+
printIMUData();
59+
}
60+
}
61+
}
62+
63+
void printIMUData(void)
64+
{
65+
// After calling dmpUpdateFifo() the ax, gx, mx, etc. values
66+
// are all updated.
67+
float gyroX = imu.calcGyro(imu.gx);
68+
float gyroY = imu.calcGyro(imu.gy);
69+
float gyroZ = imu.calcGyro(imu.gz);
70+
71+
SerialPort.println("Gyro: " + String(gyroX) + ", " +
72+
String(gyroY) + ", " + String(gyroZ) + " dps");
73+
SerialPort.println("Time: " + String(imu.time) + " ms");
74+
SerialPort.println();
75+
}
76+

0 commit comments

Comments
 (0)