You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#defineQUAT_ANIMATION// Uncomment this line to output data in the correct format for ZaneL's Node.js Quaternion animation tool: https://github.com/ZaneL/quaternion_sensor_3d_nodejs
28
+
27
29
#include"ICM_20948.h"// Click here to get the library: http://librarymanager/All#SparkFun_ICM_20948_IMU
28
30
29
31
//#define USE_SPI // Uncomment this to use SPI
@@ -48,17 +50,21 @@
48
50
voidsetup() {
49
51
50
52
SERIAL_PORT.begin(115200); // Start the serial console
53
+
#ifndef QUAT_ANIMATION
51
54
SERIAL_PORT.println(F("ICM-20948 Example"));
55
+
#endif
52
56
53
57
delay(100);
54
58
59
+
#ifndef QUAT_ANIMATION
55
60
while (SERIAL_PORT.available()) // Make sure the serial RX buffer is empty
56
61
SERIAL_PORT.read();
57
62
58
63
SERIAL_PORT.println(F("Press any key to continue..."));
59
64
60
65
while (!SERIAL_PORT.available()) // Wait for the user to press a key (send any serial character)
61
66
;
67
+
#endif
62
68
63
69
#ifdef USE_SPI
64
70
SPI_PORT.begin();
@@ -67,7 +73,9 @@ void setup() {
67
73
WIRE_PORT.setClock(400000);
68
74
#endif
69
75
76
+
#ifndef QUAT_ANIMATION
70
77
//myICM.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
78
+
#endif
71
79
72
80
bool initialized = false;
73
81
while( !initialized ){
@@ -80,17 +88,23 @@ void setup() {
80
88
myICM.begin( WIRE_PORT, AD0_VAL );
81
89
#endif
82
90
91
+
#ifndef QUAT_ANIMATION
83
92
SERIAL_PORT.print( F("Initialization of the sensor returned: ") );
84
93
SERIAL_PORT.println( myICM.statusString() );
94
+
#endif
85
95
if( myICM.status != ICM_20948_Stat_Ok ){
96
+
#ifndef QUAT_ANIMATION
86
97
SERIAL_PORT.println( F("Trying again...") );
98
+
#endif
87
99
delay(500);
88
100
}else{
89
101
initialized = true;
90
102
}
91
103
}
92
104
93
-
SERIAL_PORT.println("Device connected!");
105
+
#ifndef QUAT_ANIMATION
106
+
SERIAL_PORT.println(F("Device connected!"));
107
+
#endif
94
108
95
109
// The ICM-20948 is awake and ready but hasn't been configured. Let's step through the configuration
96
110
// sequence from InvenSense's _confidential_ Application Note "Programming Sequence for DMP Hardware Functions".
@@ -103,8 +117,9 @@ void setup() {
103
117
104
118
// Enable accel and gyro sensors through PWR_MGMT_2
105
119
// Enable Accelerometer (all axes) and Gyroscope (all axes) by writing zero to PWR_MGMT_2
106
-
uint8_t zero = 0;
107
-
success &= (myICM.write(AGB0_REG_PWR_MGMT_2, &zero, 1) == ICM_20948_Stat_Ok); // Write one byte to the PWR_MGMT_2 register
120
+
success &= (myICM.setBank(0) == ICM_20948_Stat_Ok); // Select Bank 0
121
+
uint8_t pwrMgmt2 = 0x40; // Set the reserved bit 6
122
+
success &= (myICM.write(AGB0_REG_PWR_MGMT_2, &pwrMgmt2, 1) == ICM_20948_Stat_Ok); // Write one byte to the PWR_MGMT_2 register
108
123
109
124
// Configure I2C_Master/Gyro/Accel in Low Power Mode (cycled) with LP_CONFIG
// Set gyro sample rate divider with GYRO_SMPLRT_DIV
150
167
// Set accel sample rate divider with ACCEL_SMPLRT_DIV_2
151
168
ICM_20948_smplrt_t mySmplrt;
152
-
mySmplrt.g = 43; // ODR is computed as follows: 1.1 kHz/(1+GYRO_SMPLRT_DIV[7:0]). 43 = 25Hz
153
-
mySmplrt.a = 44; // ODR is computed as follows: 1.125 kHz/(1+ACCEL_SMPLRT_DIV[11:0]). 44 = 25Hz
154
-
//myICM.setSampleRate( (ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr), mySmplrt ); // ** Note: comment this line to leave the sample rates at the maximum **
169
+
mySmplrt.g = 19; // ODR is computed as follows: 1.1 kHz/(1+GYRO_SMPLRT_DIV[7:0]). 19 = 55Hz. InvenSense Nucleo example uses 19 (0x13).
170
+
mySmplrt.a = 19; // ODR is computed as follows: 1.125 kHz/(1+ACCEL_SMPLRT_DIV[11:0]). 19 = 56.25Hz. InvenSense Nucleo example uses 19 (0x13).
171
+
myICM.setSampleRate( (ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr), mySmplrt ); // ** Note: comment this line to leave the sample rates at the maximum **
155
172
156
173
// Setup DMP start address through PRGM_STRT_ADDRH/PRGM_STRT_ADDRL
157
174
success &= (myICM.setDMPstartAddress() == ICM_20948_Stat_Ok); // Defaults to DMP_START_ADDRESS
@@ -162,14 +179,24 @@ void setup() {
162
179
// Write the 2 byte Firmware Start Value to ICM PRGM_STRT_ADDRH/PRGM_STRT_ADDRL
163
180
success &= (myICM.setDMPstartAddress() == ICM_20948_Stat_Ok); // Defaults to DMP_START_ADDRESS
164
181
182
+
// Set the Hardware Fix Disable register to 0x48
183
+
success &= (myICM.setBank(0) == ICM_20948_Stat_Ok); // Select Bank 0
0 commit comments