@@ -64,19 +64,22 @@ BNO08x myIMU;
64
64
// variables to store all our incoming values
65
65
66
66
// raw accel
67
- uint16_t x;
68
- uint16_t y;
69
- uint16_t z;
67
+ int16_t x;
68
+ int16_t y;
69
+ int16_t z;
70
70
71
71
// raw gyros
72
- uint16_t gx;
73
- uint16_t gy;
74
- uint16_t gz;
72
+ int16_t gx;
73
+ int16_t gy;
74
+ int16_t gz;
75
75
76
76
// raw mags
77
- uint16_t mx;
78
- uint16_t my;
79
- uint16_t mz;
77
+ int16_t mx;
78
+ int16_t my;
79
+ int16_t mz;
80
+
81
+ unsigned long previousDebugMillis = 0 ;
82
+ #define DEBUG_INTERVAL_MILLISECONDS 30
80
83
81
84
void setup () {
82
85
Serial.begin (115200 );
@@ -99,7 +102,7 @@ void setup() {
99
102
}
100
103
Serial.println (" BNO08x found!" );
101
104
102
- Wire.setClock (400000 ); // Increase I2C data rate to 400kHz
105
+ // Wire.setClock(400000); //Increase I2C data rate to 400kHz
103
106
104
107
setReports ();
105
108
@@ -111,37 +114,37 @@ void setup() {
111
114
void setReports (void ) {
112
115
Serial.println (" Setting desired reports" );
113
116
114
- if (myIMU.enableAccelerometer () == true ) {
117
+ if (myIMU.enableAccelerometer (1 ) == true ) {
115
118
Serial.println (F (" Accelerometer enabled" ));
116
119
} else {
117
120
Serial.println (" Could not enable accelerometer" );
118
121
}
119
122
120
- if (myIMU.enableRawAccelerometer () == true ) {
123
+ if (myIMU.enableRawAccelerometer (1 ) == true ) {
121
124
Serial.println (F (" Raw Accelerometer enabled" ));
122
125
} else {
123
126
Serial.println (" Could not enable raw accelerometer" );
124
127
}
125
128
126
- if (myIMU.enableGyro () == true ) {
129
+ if (myIMU.enableGyro (1 ) == true ) {
127
130
Serial.println (F (" Gyro enabled" ));
128
131
} else {
129
132
Serial.println (" Could not enable gyro" );
130
133
}
131
134
132
- if (myIMU.enableRawGyro () == true ) {
135
+ if (myIMU.enableRawGyro (1 ) == true ) {
133
136
Serial.println (F (" Raw Gyro enabled" ));
134
137
} else {
135
138
Serial.println (" Could not enable raw gyro" );
136
139
}
137
140
138
- if (myIMU.enableMagnetometer () == true ) {
141
+ if (myIMU.enableMagnetometer (1 ) == true ) {
139
142
Serial.println (F (" Magnetometer enabled" ));
140
143
} else {
141
144
Serial.println (" Could not enable Magnetometer" );
142
145
}
143
146
144
- if (myIMU.enableRawMagnetometer () == true ) {
147
+ if (myIMU.enableRawMagnetometer (1 ) == true ) {
145
148
Serial.println (F (" Raw Magnetometer enabled" ));
146
149
} else {
147
150
Serial.println (" Could not enable Raw Magnetometer" );
@@ -152,7 +155,7 @@ void setReports(void) {
152
155
}
153
156
154
157
void loop () {
155
- delay (10 );
158
+ delayMicroseconds (10 );
156
159
157
160
if (myIMU.wasReset ()) {
158
161
Serial.print (" sensor was reset " );
@@ -188,11 +191,19 @@ void loop() {
188
191
break ;
189
192
}
190
193
191
- // Only print data to terminal if one of the report IDs we want came
192
- // in on the bus
193
- if ( (reportID == SENSOR_REPORTID_RAW_ACCELEROMETER) ||
194
- (reportID == SENSOR_REPORTID_RAW_GYROSCOPE) ||
195
- (reportID == SENSOR_REPORTID_RAW_MAGNETOMETER))
194
+ // Only print data to the terminal at a user defined interval
195
+ // Each data type (accel or gyro or mag) is reported from the
196
+ // BNO086 as separate messages.
197
+ // To allow for all these separate messages to arrive, and thus
198
+ // have updated data on all axis/types,
199
+ // The report intervals for each datatype must be much faster
200
+ // than our debug interval.
201
+
202
+ // time since last debug data printed to terminal
203
+ int timeSinceLastSerialPrint = (millis () - previousDebugMillis);
204
+
205
+ // Only print data to the terminal at a user deficed interval
206
+ if (timeSinceLastSerialPrint > DEBUG_INTERVAL_MILLISECONDS)
196
207
{
197
208
Serial.print (x);
198
209
Serial.print (" \t " );
@@ -215,7 +226,12 @@ void loop() {
215
226
Serial.print (mz);
216
227
Serial.print (" \t " );
217
228
229
+ Serial.print (timeSinceLastSerialPrint);
230
+
218
231
Serial.println ();
232
+
233
+ previousDebugMillis = millis ();
234
+
219
235
}
220
236
}
221
237
}
0 commit comments