-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTJ_ICM20948_libV4.ino
65 lines (52 loc) · 1.49 KB
/
TJ_ICM20948_libV4.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <ICM_20948.h>
#include "AHRS_ICM20948.h"
#include <Wire.h>
#include <stdint.h>
#define ARDUINOJSON_DECODE_UNICODE 1
#define PROTOCOL_ITEM_NUMBER 6
#include "Protocol.h"
#define SERIAL_PORT Serial
#define WIRE_PORT Wire
ICM_20948_I2C myICM;
AHRS myAHRS(myICM);
const bool tuning = 1;
bool itint_print = 1;
void setup(){
SERIAL_PORT.begin(115200);
while(!SERIAL_PORT){};
SERIAL_PORT.flush();
WIRE_PORT.begin();
WIRE_PORT.setClock(100000);
bool initialized = false;
while( !initialized ){
myICM.begin( WIRE_PORT, 0x68 );
//myICM.begin( WIRE_PORT, 0x0C );
delay(500);
if (itint_print){
SERIAL_PORT.print( F("Initialization of the sensor returned: ") );
SERIAL_PORT.println( myICM.statusString() );
}
if( myICM.status != ICM_20948_Stat_Ok ){
if (itint_print){
SERIAL_PORT.println( "Trying again..." );
}
delay(500);
}
else{
initialized = true;
}
}
ARHS_start(&myICM, &myAHRS);
if (tuning) {
AHRS_init_tuning(&myICM, &myAHRS);
}
myAHRS.setAHRS_MagneticDeclination(0.44);
}
void loop () {
if( myICM.dataReady() ){
myICM.getAGMT(); // The values are only updated when you call 'getAGMT'
myAHRS.AHRS_update();
//myAHRS.print_MotionCals(false,false,"all");//uni true or false, correction true or false, selection
myAHRS.print_AHRS(true,false);// bool all (true) or yaw only (false), rad (true) or degrees (false) //ACESS AHRS VALUES HERE (YAW AND THE REST)
}
}