Skip to content
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SparkFun_ICM-20948_ArduinoLibrary
========================================

This is the library for the [SparkFun 9DoF IMU Breakout - ICM-20948 (Qwiic)](https://www.sparkfun.com/products/15335).
This is the library for the [SparkFun 9DoF IMU Breakout - ICM-20948 (Qwiic)](https://www.sparkfun.com/products/15335).


Repository Contents
Expand All @@ -18,7 +18,7 @@ Documentation
* **[Hookup Guide](https://learn.sparkfun.com/tutorials/sparkfun-9dof-imu-icm-20948-breakout-hookup-guide)** - Basic hookup guide for the SparkFun 9DoF IMU Breakout.
* **[Installing an Arduino Library Guide](https://learn.sparkfun.com/tutorials/installing-an-arduino-library)** - Basic information on how to install an Arduino library.

Products that use this Library
Products that use this Library
---------------------------------
* [SparkFun 9DoF IMU Breakout - ICM-20948 (Qwiic)](https://www.sparkfun.com/products/15335)

Expand All @@ -28,7 +28,7 @@ License Information

This product is _**open source**_!

The **code** is released under the GPL v3 license. See the included LICENSE.md for more information.
Please see the included [License.md](./License.md) for more information.

Distributed as-is; no warranty is given.

Expand Down
19 changes: 9 additions & 10 deletions examples/Arduino/Example1_Basics/Example1_Basics.ino
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/****************************************************************
* Example1_Basics.ino
* ICM 20948 Arduino Library Demo
* ICM 20948 Arduino Library Demo
* Use the default configuration to stream 9-axis IMU data
* Owen Lyke @ SparkFun Electronics
* Original Creation Date: April 17 2019
*
* This code is beerware; if you see me (or any other SparkFun employee) at the
* local, and you've found our code helpful, please buy us a round!
*
*
* Please see License.md for the license information.
*
* Distributed as-is; no warranty is given.
***************************************************************/
#include "ICM_20948.h" // Click here to get the library: http://librarymanager/All#SparkFun_ICM_20948_IMU
Expand All @@ -20,8 +19,8 @@
#define CS_PIN 2 // Which pin you connect CS to. Used only when "USE_SPI" is defined

#define WIRE_PORT Wire // Your desired Wire port. Used when "USE_SPI" is not defined
#define AD0_VAL 1 // The value of the last bit of the I2C address.
// On the SparkFun 9DoF IMU breakout the default is 1, and when
#define AD0_VAL 1 // The value of the last bit of the I2C address.
// On the SparkFun 9DoF IMU breakout the default is 1, and when
// the ADR jumper is closed the value becomes 0

#ifdef USE_SPI
Expand All @@ -42,12 +41,12 @@ void setup() {
WIRE_PORT.begin();
WIRE_PORT.setClock(400000);
#endif

bool initialized = false;
while( !initialized ){

#ifdef USE_SPI
myICM.begin( CS_PIN, SPI_PORT );
myICM.begin( CS_PIN, SPI_PORT );
#else
myICM.begin( WIRE_PORT, AD0_VAL );
#endif
Expand All @@ -74,7 +73,7 @@ void loop() {
Serial.println("Waiting for data");
delay(500);
}

}


Expand Down
39 changes: 19 additions & 20 deletions examples/Arduino/Example2_Advanced/Example2_Advanced.ino
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/****************************************************************
* Example2_Advanced.ino
* ICM 20948 Arduino Library Demo
* ICM 20948 Arduino Library Demo
* Shows how to use granular configuration of the ICM 20948
* Owen Lyke @ SparkFun Electronics
* Original Creation Date: April 17 2019
*
* This code is beerware; if you see me (or any other SparkFun employee) at the
* local, and you've found our code helpful, please buy us a round!
*
*
* Please see License.md for the license information.
*
* Distributed as-is; no warranty is given.
***************************************************************/
#include "ICM_20948.h" // Click here to get the library: http://librarymanager/All#SparkFun_ICM_20948_IMU
Expand All @@ -21,16 +20,16 @@
#define CS_PIN 2 // Which pin you connect CS to. Used only when "USE_SPI" is defined

#define WIRE_PORT Wire // Your desired Wire port. Used when "USE_SPI" is not defined
#define AD0_VAL 1 // The value of the last bit of the I2C address.
// On the SparkFun 9DoF IMU breakout the default is 1, and when
#define AD0_VAL 1 // The value of the last bit of the I2C address.
// On the SparkFun 9DoF IMU breakout the default is 1, and when
// the ADR jumper is closed the value becomes 0

#ifdef USE_SPI
ICM_20948_SPI myICM; // If using SPI create an ICM_20948_SPI object
#else
ICM_20948_I2C myICM; // Otherwise create an ICM_20948_I2C object
#endif


void setup() {

Expand All @@ -43,12 +42,12 @@ void setup() {
WIRE_PORT.begin();
WIRE_PORT.setClock(400000);
#endif

bool initialized = false;
while( !initialized ){

#ifdef USE_SPI
myICM.begin( CS_PIN, SPI_PORT, SPI_FREQ ); // Here we are using the user-defined SPI_FREQ as the clock speed of the SPI bus
myICM.begin( CS_PIN, SPI_PORT, SPI_FREQ ); // Here we are using the user-defined SPI_FREQ as the clock speed of the SPI bus
#else
myICM.begin( WIRE_PORT, AD0_VAL );
#endif
Expand All @@ -73,7 +72,7 @@ void setup() {
SERIAL_PORT.println(myICM.statusString());
}
delay(250);

// Now wake the sensor up
myICM.sleep( false );
myICM.lowPower( false );
Expand All @@ -83,28 +82,28 @@ void setup() {
// Set Gyro and Accelerometer to a particular sample mode
// options: ICM_20948_Sample_Mode_Continuous
// ICM_20948_Sample_Mode_Cycled
myICM.setSampleMode( (ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr), ICM_20948_Sample_Mode_Continuous );
myICM.setSampleMode( (ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr), ICM_20948_Sample_Mode_Continuous );
if( myICM.status != ICM_20948_Stat_Ok){
SERIAL_PORT.print(F("setSampleMode returned: "));
SERIAL_PORT.println(myICM.statusString());
}

// Set full scale ranges for both acc and gyr
ICM_20948_fss_t myFSS; // This uses a "Full Scale Settings" structure that can contain values for all configurable sensors

myFSS.a = gpm2; // (ICM_20948_ACCEL_CONFIG_FS_SEL_e)
// gpm2
// gpm4
// gpm8
// gpm16

myFSS.g = dps250; // (ICM_20948_GYRO_CONFIG_1_FS_SEL_e)
// dps250
// dps500
// dps1000
// dps2000
myICM.setFullScale( (ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr), myFSS );

myICM.setFullScale( (ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr), myFSS );
if( myICM.status != ICM_20948_Stat_Ok){
SERIAL_PORT.print(F("setFullScale returned: "));
SERIAL_PORT.println(myICM.statusString());
Expand All @@ -131,7 +130,7 @@ void setup() {
// gyr_d11bw6_n17bw8
// gyr_d5bw7_n8bw9
// gyr_d361bw4_n376bw5

myICM.setDLPFcfg( (ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr), myDLPcfg );
if( myICM.status != ICM_20948_Stat_Ok){
SERIAL_PORT.print(F("setDLPcfg returned: "));
Expand All @@ -146,11 +145,11 @@ void setup() {
SERIAL_PORT.print(F("Enable DLPF for Gyroscope returned: ")); SERIAL_PORT.println(myICM.statusString(gyrDLPEnableStat));

SERIAL_PORT.println();
SERIAL_PORT.println(F("Configuration complete!"));
SERIAL_PORT.println(F("Configuration complete!"));
}

void loop() {

if( myICM.dataReady() ){
myICM.getAGMT(); // The values are only updated when you call 'getAGMT'
// printRawAGMT( myICM.agmt ); // Uncomment this to see the raw values, taken directly from the agmt structure
Expand All @@ -160,7 +159,7 @@ void loop() {
Serial.println("Waiting for data");
delay(500);
}

}


Expand Down
53 changes: 26 additions & 27 deletions examples/Arduino/Example3_Interrupts/Example3_Interrupts.ino
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
/****************************************************************
* Example3_Interrupts.ino
* ICM 20948 Arduino Library Demo
* ICM 20948 Arduino Library Demo
* Builds on Example2_Advanced.ino to set up interrupts when data is ready
* Owen Lyke @ SparkFun Electronics
* Original Creation Date: June 5 2019
*
* For this example you must connect the interrupt pin "INT" on the breakout
*
* For this example you must connect the interrupt pin "INT" on the breakout
* board to the pin specified by "INT_PIN" on your microcontroller.
*
* This code is beerware; if you see me (or any other SparkFun employee) at the
* local, and you've found our code helpful, please buy us a round!
*
*
* Please see License.md for the license information.
*
* Distributed as-is; no warranty is given.
***************************************************************/
#include "ICM_20948.h" // Click here to get the library: http://librarymanager/All#SparkFun_ICM_20948_IMU
Expand All @@ -29,8 +28,8 @@
#define CS_PIN 2 // Which pin you connect CS to. Used only when "USE_SPI" is defined

#define WIRE_PORT Wire // Your desired Wire port. Used when "USE_SPI" is not defined
#define AD0_VAL 1 // The value of the last bit of the I2C address.
// On the SparkFun 9DoF IMU breakout the default is 1, and when
#define AD0_VAL 1 // The value of the last bit of the I2C address.
// On the SparkFun 9DoF IMU breakout the default is 1, and when
// the ADR jumper is closed the value becomes 0

#ifdef USE_SPI
Expand Down Expand Up @@ -61,12 +60,12 @@ void setup() {
WIRE_PORT.begin();
WIRE_PORT.setClock(400000);
#endif

bool initialized = false;
while( !initialized ){

#ifdef USE_SPI
myICM.begin( CS_PIN, SPI_PORT, SPI_FREQ ); // Here we are using the user-defined SPI_FREQ as the clock speed of the SPI bus
myICM.begin( CS_PIN, SPI_PORT, SPI_FREQ ); // Here we are using the user-defined SPI_FREQ as the clock speed of the SPI bus
#else
myICM.begin( WIRE_PORT, AD0_VAL );
#endif
Expand All @@ -91,7 +90,7 @@ void setup() {
SERIAL_PORT.println(myICM.statusString());
}
delay(250);

// Now wake the sensor up
myICM.sleep( sensorSleep );
myICM.lowPower( false );
Expand All @@ -101,7 +100,7 @@ void setup() {
// Set Gyro and Accelerometer to a particular sample mode
// options: ICM_20948_Sample_Mode_Continuous
// ICM_20948_Sample_Mode_Cycled
myICM.setSampleMode( (ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr), ICM_20948_Sample_Mode_Cycled );
myICM.setSampleMode( (ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr), ICM_20948_Sample_Mode_Cycled );
SERIAL_PORT.print(F("setSampleMode returned: "));
SERIAL_PORT.println(myICM.statusString());

Expand All @@ -111,23 +110,23 @@ void setup() {
myICM.setSampleRate( ICM_20948_Internal_Gyr, mySmplrt );
SERIAL_PORT.print(F("setSampleRate returned: "));
SERIAL_PORT.println(myICM.statusString());

// Set full scale ranges for both acc and gyr
ICM_20948_fss_t myFSS; // This uses a "Full Scale Settings" structure that can contain values for all configurable sensors

myFSS.a = gpm2; // (ICM_20948_ACCEL_CONFIG_FS_SEL_e)
// gpm2
// gpm4
// gpm8
// gpm16

myFSS.g = dps250; // (ICM_20948_GYRO_CONFIG_1_FS_SEL_e)
// dps250
// dps500
// dps1000
// dps2000
myICM.setFullScale( (ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr), myFSS );

myICM.setFullScale( (ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr), myFSS );
if( myICM.status != ICM_20948_Stat_Ok){
SERIAL_PORT.print(F("setFullScale returned: "));
SERIAL_PORT.println(myICM.statusString());
Expand All @@ -154,7 +153,7 @@ void setup() {
// gyr_d11bw6_n17bw8
// gyr_d5bw7_n8bw9
// gyr_d361bw4_n376bw5

myICM.setDLPFcfg( (ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr), myDLPcfg );
if( myICM.status != ICM_20948_Stat_Ok){
SERIAL_PORT.print(F("setDLPcfg returned: "));
Expand Down Expand Up @@ -193,7 +192,7 @@ void setup() {
myICM.cfgIntLatch(true); // Latch the interrupt until cleared
SERIAL_PORT.print(F("cfgIntLatch returned: "));
SERIAL_PORT.println(myICM.statusString());

myICM.intEnableRawDataReady(true); // enable interrupts on raw data ready
SERIAL_PORT.print(F("intEnableRawDataReady returned: "));
SERIAL_PORT.println(myICM.statusString());
Expand All @@ -207,7 +206,7 @@ void setup() {
// ICM_20948_execute_w( &myICM._device, AGB0_REG_INT_ENABLE, (uint8_t*)&zero_0, sizeof(uint8_t) );

SERIAL_PORT.println();
SERIAL_PORT.println(F("Configuration complete!"));
SERIAL_PORT.println(F("Configuration complete!"));
}

void loop() {
Expand All @@ -217,19 +216,19 @@ void loop() {
// myICM.clearInterrupts(); // This would be efficient... but not compatible with Uno
}

myICM.clearInterrupts(); // clear interrupts for next time -
// usually you'd do this only if an interrupt has occurred, however
myICM.clearInterrupts(); // clear interrupts for next time -
// usually you'd do this only if an interrupt has occurred, however
// on the 328p I2C usage can block interrupts. This means that sometimes
// an interrupt is missed. When missed, if using an edge-based interrupt
// and only clearing interrupts when one was detected there will be no more
// edges to respond to, so no more interrupts will be detected. Here are
// and only clearing interrupts when one was detected there will be no more
// edges to respond to, so no more interrupts will be detected. Here are
// some possible solutions:
// 1. use a level based interrupt
// 2. use the pulse-based interrupt in ICM settings (set cfgIntLatch to false)
// 3. use a microcontroller with nestable interrupts
// 4. clear the interrupts often


if( (millis()%1000) < 5){ // This is a method to turn the sensor on and off once per second without using delays
if( canToggle ){
sensorSleep = !sensorSleep;
Expand Down
Loading