Skip to content

Commit 308debf

Browse files
committed
better examples for Rob
1 parent fb2b983 commit 308debf

File tree

7 files changed

+367
-924
lines changed

7 files changed

+367
-924
lines changed

examples/Arduino/Example1_Basics/Example1_Basics.ino

Lines changed: 29 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,19 @@ void setup() {
5050
void loop() {
5151

5252
if( myICM.dataReady() ){
53-
myICM.getAGMT();
54-
// printRawAGMT( myICM.agmt );
55-
printScaledAGMT( myICM.agmt);
53+
myICM.getAGMT(); // The values are only updated when you call 'getAGMT'
54+
// printRawAGMT( myICM.agmt ); // Uncomment this to see the raw values, taken directly from the agmt structure
55+
printScaledAGMT( myICM.agmt); // This function takes into account the sclae settings from when the measurement was made to calculate the values with units
5656
delay(30);
5757
}else{
58-
Serial.println("0");
58+
Serial.println("Waiting for data");
59+
delay(500);
5960
}
61+
6062
}
6163

6264

63-
65+
// Below here are some helper functions to print the data nicely!
6466

6567
void printPaddedInt16b( int16_t val ){
6668
if(val > 0){
@@ -104,61 +106,28 @@ void printRawAGMT( ICM_20948_AGMT_t agmt){
104106
SERIAL_PORT.println();
105107
}
106108

107-
float getAccMG( int16_t raw, uint8_t fss ){
108-
switch(fss){
109-
case 0 : return (((float)raw)/16.384); break;
110-
case 1 : return (((float)raw)/8.192); break;
111-
case 2 : return (((float)raw)/4.096); break;
112-
case 3 : return (((float)raw)/2.048); break;
113-
default : return 0; break;
114-
}
115-
}
116-
117-
float getGyrDPS( int16_t raw, uint8_t fss ){
118-
switch(fss){
119-
case 0 : return (((float)raw)/131); break;
120-
case 1 : return (((float)raw)/65.5); break;
121-
case 2 : return (((float)raw)/32.8); break;
122-
case 3 : return (((float)raw)/16.4); break;
123-
default : return 0; break;
124-
}
125-
}
126-
127-
float getMagUT( int16_t raw ){
128-
return (((float)raw)*0.15);
129-
//todo: this is a much more complicated formula, atually
130-
}
131-
132-
float getTmpC( int16_t raw ){
133-
return (((float)raw)/333.87) + 21;
134-
}
135109

136110
void printFormattedFloat(float val, uint8_t leading, uint8_t decimals){
137111
float aval = abs(val);
138-
139112
if(val < 0){
140113
SERIAL_PORT.print("-");
141114
}else{
142115
SERIAL_PORT.print(" ");
143116
}
144-
145117
for( uint8_t indi = 0; indi < leading; indi++ ){
146-
147118
uint32_t tenpow = 0;
148119
if( indi < (leading-1) ){
149120
tenpow = 1;
150121
}
151122
for(uint8_t c = 0; c < (leading-1-indi); c++){
152123
tenpow *= 10;
153124
}
154-
155125
if( aval < tenpow){
156126
SERIAL_PORT.print("0");
157127
}else{
158128
break;
159129
}
160130
}
161-
162131
if(val < 0){
163132
SERIAL_PORT.print(-val, decimals);
164133
}else{
@@ -167,26 +136,26 @@ void printFormattedFloat(float val, uint8_t leading, uint8_t decimals){
167136
}
168137

169138
void printScaledAGMT( ICM_20948_AGMT_t agmt){
170-
Serial.print("Scaled. Acc (mg) [ ");
171-
printFormattedFloat( getAccMG(agmt.acc.axes.x, agmt.fss.a ), 5, 2 );
172-
Serial.print(", ");
173-
printFormattedFloat( getAccMG(agmt.acc.axes.y, agmt.fss.a ), 5, 2 );
174-
Serial.print(", ");
175-
printFormattedFloat( getAccMG(agmt.acc.axes.z, agmt.fss.a ), 5, 2 );
176-
Serial.print(" ], Gyr (DPS) [ ");
177-
printFormattedFloat( getGyrDPS(agmt.gyr.axes.x, agmt.fss.g ), 5, 2 );
178-
Serial.print(", ");
179-
printFormattedFloat( getGyrDPS(agmt.gyr.axes.y, agmt.fss.g ), 5, 2 );
180-
Serial.print(", ");
181-
printFormattedFloat( getGyrDPS(agmt.gyr.axes.z, agmt.fss.g ), 5, 2 );
182-
Serial.print(" ], Mag (uT) [ ");
183-
printFormattedFloat( getMagUT(agmt.mag.axes.x), 5, 2 );
184-
Serial.print(", ");
185-
printFormattedFloat( getMagUT(agmt.mag.axes.y), 5, 2 );
186-
Serial.print(", ");
187-
printFormattedFloat( getMagUT(agmt.mag.axes.z), 5, 2 );
188-
Serial.print(" ], Tmp (C) [ ");
189-
printFormattedFloat( getTmpC(agmt.tmp.val), 5, 2 );
190-
Serial.print(" ]");
191-
Serial.println();
139+
SERIAL_PORT.print("Scaled. Acc (mg) [ ");
140+
printFormattedFloat( myICM.accX(), 5, 2 );
141+
SERIAL_PORT.print(", ");
142+
printFormattedFloat( myICM.accY(), 5, 2 );
143+
SERIAL_PORT.print(", ");
144+
printFormattedFloat( myICM.accZ(), 5, 2 );
145+
SERIAL_PORT.print(" ], Gyr (DPS) [ ");
146+
printFormattedFloat( myICM.gyrX(), 5, 2 );
147+
SERIAL_PORT.print(", ");
148+
printFormattedFloat( myICM.gyrY(), 5, 2 );
149+
SERIAL_PORT.print(", ");
150+
printFormattedFloat( myICM.gyrZ(), 5, 2 );
151+
SERIAL_PORT.print(" ], Mag (uT) [ ");
152+
printFormattedFloat( myICM.magX(), 5, 2 );
153+
SERIAL_PORT.print(", ");
154+
printFormattedFloat( myICM.magY(), 5, 2 );
155+
SERIAL_PORT.print(", ");
156+
printFormattedFloat( myICM.magZ(), 5, 2 );
157+
SERIAL_PORT.print(" ], Tmp (C) [ ");
158+
printFormattedFloat( myICM.temp(), 5, 2 );
159+
SERIAL_PORT.print(" ]");
160+
SERIAL_PORT.println();
192161
}

examples/Arduino/Example1_Basics_SPI/Example1_Basics_SPI.ino

Lines changed: 0 additions & 205 deletions
This file was deleted.

0 commit comments

Comments
 (0)