|
10 | 10 | * ** This example is based on the InvenSense Application Note "Programming Sequence for DMP Hardware Functions".
|
11 | 11 | * ** We are grateful to InvenSense for providing this.
|
12 | 12 | *
|
13 |
| - * ** Important note: by default the DMP functionality is disabled in the library. This is to save program memory. |
14 |
| - * ** The DMP firmware takes up 14290 Bytes of program memory. To use the DMP, you will need to: |
| 13 | + * ** Important note: by default the DMP functionality is disabled in the library |
| 14 | + * ** as the DMP firmware takes up 14290 Bytes of program memory. |
| 15 | + * ** To use the DMP, you will need to: |
15 | 16 | * ** Edit ICM_20948_C.h
|
16 | 17 | * ** Uncomment line 29: #define ICM_20948_USE_DMP
|
17 | 18 | * ** Save changes
|
18 |
| - * ** If you are using Windows, you can find ICM_20948_C.h in Documents\Arduino\libraries\SparkFun_ICM-20948_ArduinoLibrary\src\util |
| 19 | + * ** If you are using Windows, you can find ICM_20948_C.h in: |
| 20 | + * ** Documents\Arduino\libraries\SparkFun_ICM-20948_ArduinoLibrary\src\util |
19 | 21 | *
|
20 | 22 | * Please see License.md for the license information.
|
21 | 23 | *
|
@@ -169,21 +171,18 @@ void setup() {
|
169 | 171 | // Z = raw_x * CPASS_MTX_20 + raw_y * CPASS_MTX_21 + raw_z * CPASS_MTX_22
|
170 | 172 | // Magnetometer full scale is +/- 4900uT so _I think_ we need to multiply by 2^30 / 4900 = 0x000357FA
|
171 | 173 | // The magnetometer Y and Z axes are reversed compared to the accelerometer so we'll invert those
|
172 |
| -// const unsigned char mountMultiplierZero[4] = {0x00, 0x00, 0x00, 0x00}; |
173 |
| -// const unsigned char mountMultiplierPlus[4] = {0x00, 0x03, 0x57, 0xFA}; |
174 |
| -// const unsigned char mountMultiplierMinus[4] = {0xFF, 0xFC, 0xA8, 0x05}; |
175 | 174 | const unsigned char mountMultiplierZero[4] = {0x00, 0x00, 0x00, 0x00};
|
176 |
| - const unsigned char mountMultiplierPlus[4] = {0x40, 0x00, 0x00, 0x00}; |
177 |
| - const unsigned char mountMultiplierMinus[4] = {0xC0, 0x00, 0x00, 0x00}; |
| 175 | + const unsigned char mountMultiplierPlus[4] = {0x00, 0x03, 0x57, 0xFA}; |
| 176 | + const unsigned char mountMultiplierMinus[4] = {0xFF, 0xFC, 0xA8, 0x05}; |
178 | 177 | success &= (myICM.writeDMPmems(CPASS_MTX_00, 4, &mountMultiplierPlus[0]) == ICM_20948_Stat_Ok);
|
179 | 178 | success &= (myICM.writeDMPmems(CPASS_MTX_01, 4, &mountMultiplierZero[0]) == ICM_20948_Stat_Ok);
|
180 | 179 | success &= (myICM.writeDMPmems(CPASS_MTX_02, 4, &mountMultiplierZero[0]) == ICM_20948_Stat_Ok);
|
181 | 180 | success &= (myICM.writeDMPmems(CPASS_MTX_10, 4, &mountMultiplierZero[0]) == ICM_20948_Stat_Ok);
|
182 |
| - success &= (myICM.writeDMPmems(CPASS_MTX_11, 4, &mountMultiplierPlus[0]) == ICM_20948_Stat_Ok); |
| 181 | + success &= (myICM.writeDMPmems(CPASS_MTX_11, 4, &mountMultiplierMinus[0]) == ICM_20948_Stat_Ok); |
183 | 182 | success &= (myICM.writeDMPmems(CPASS_MTX_12, 4, &mountMultiplierZero[0]) == ICM_20948_Stat_Ok);
|
184 | 183 | success &= (myICM.writeDMPmems(CPASS_MTX_20, 4, &mountMultiplierZero[0]) == ICM_20948_Stat_Ok);
|
185 | 184 | success &= (myICM.writeDMPmems(CPASS_MTX_21, 4, &mountMultiplierZero[0]) == ICM_20948_Stat_Ok);
|
186 |
| - success &= (myICM.writeDMPmems(CPASS_MTX_22, 4, &mountMultiplierPlus[0]) == ICM_20948_Stat_Ok); |
| 185 | + success &= (myICM.writeDMPmems(CPASS_MTX_22, 4, &mountMultiplierMinus[0]) == ICM_20948_Stat_Ok); |
187 | 186 |
|
188 | 187 | // Enable the FIFO
|
189 | 188 | success &= (myICM.enableFIFO() == ICM_20948_Stat_Ok);
|
@@ -219,20 +218,32 @@ void setup() {
|
219 | 218 |
|
220 | 219 | void loop()
|
221 | 220 | {
|
222 |
| - uint16_t count; |
223 |
| - myICM.getFIFOcount(&count); |
| 221 | + icm_20948_DMP_data_t data; |
| 222 | + myICM.readDMPdataFromFIFO(&data); |
224 | 223 | if( myICM.status == ICM_20948_Stat_Ok )
|
225 | 224 | {
|
226 |
| - SERIAL_PORT.print("FIFO count is: "); |
227 |
| - SERIAL_PORT.println( count ); |
| 225 | + SERIAL_PORT.print("Received data! Header: "); |
| 226 | + SERIAL_PORT.println( data.header ); |
| 227 | + if ( data.header == DMP_header_bitmap_Quat9 ) // We have asked for orientation data so we should receive Quat9 |
| 228 | + { |
| 229 | + SERIAL_PORT.print("Quat9 data is: 0x"); |
| 230 | + for (int i = 0; i < 14; i++) // Quat9 data is 14 bytes long |
| 231 | + { |
| 232 | + if ( data.Quat9[i] < 16) SERIAL_PORT.print( "0" ); // Pad the zero |
| 233 | + SERIAL_PORT.print( data.Quat9[i], HEX ); |
| 234 | + } |
| 235 | + SERIAL_PORT.println(); |
| 236 | + } |
228 | 237 | }
|
229 |
| - else |
| 238 | + else if ( myICM.status != ICM_20948_Stat_FIFONoDataAvail ) |
230 | 239 | {
|
231 |
| - SERIAL_PORT.print("getFIFOcount failed! Status is: "); |
| 240 | + SERIAL_PORT.print("readDMPdataFromFIFO failed! Status is: "); |
232 | 241 | SERIAL_PORT.println( myICM.statusString() );
|
| 242 | + SERIAL_PORT.print("Header is: 0x"); |
| 243 | + SERIAL_PORT.println( data.header, HEX ); |
233 | 244 | }
|
234 | 245 |
|
235 |
| - delay(1000); |
| 246 | + delay(10); |
236 | 247 | }
|
237 | 248 |
|
238 | 249 |
|
|
0 commit comments