Revision 463eabf7 examples/restore_offsets/restore_offsets.ino
examples/restore_offsets/restore_offsets.ino | ||
---|---|---|
37 | 37 |
|
38 | 38 |
/**************************************************************************/ |
39 | 39 |
/* |
40 |
Displays some basic information on this sensor from the unified
|
|
41 |
sensor API sensor_t type (see Adafruit_Sensor for more information)
|
|
42 |
*/
|
|
40 |
Displays some basic information on this sensor from the unified
|
|
41 |
sensor API sensor_t type (see Adafruit_Sensor for more information)
|
|
42 |
*/
|
|
43 | 43 |
/**************************************************************************/ |
44 | 44 |
void displaySensorDetails(void) |
45 | 45 |
{ |
46 |
sensor_t sensor;
|
|
47 |
bno.getSensor(&sensor);
|
|
48 |
Serial.println("------------------------------------");
|
|
49 |
Serial.print("Sensor: "); Serial.println(sensor.name);
|
|
50 |
Serial.print("Driver Ver: "); Serial.println(sensor.version);
|
|
51 |
Serial.print("Unique ID: "); Serial.println(sensor.sensor_id);
|
|
52 |
Serial.print("Max Value: "); Serial.print(sensor.max_value); Serial.println(" xxx");
|
|
53 |
Serial.print("Min Value: "); Serial.print(sensor.min_value); Serial.println(" xxx");
|
|
54 |
Serial.print("Resolution: "); Serial.print(sensor.resolution); Serial.println(" xxx");
|
|
55 |
Serial.println("------------------------------------");
|
|
56 |
Serial.println("");
|
|
57 |
delay(500);
|
|
46 |
sensor_t sensor;
|
|
47 |
bno.getSensor(&sensor);
|
|
48 |
Serial.println("------------------------------------");
|
|
49 |
Serial.print("Sensor: "); Serial.println(sensor.name);
|
|
50 |
Serial.print("Driver Ver: "); Serial.println(sensor.version);
|
|
51 |
Serial.print("Unique ID: "); Serial.println(sensor.sensor_id);
|
|
52 |
Serial.print("Max Value: "); Serial.print(sensor.max_value); Serial.println(" xxx");
|
|
53 |
Serial.print("Min Value: "); Serial.print(sensor.min_value); Serial.println(" xxx");
|
|
54 |
Serial.print("Resolution: "); Serial.print(sensor.resolution); Serial.println(" xxx");
|
|
55 |
Serial.println("------------------------------------");
|
|
56 |
Serial.println("");
|
|
57 |
delay(500);
|
|
58 | 58 |
} |
59 | 59 |
|
60 | 60 |
/**************************************************************************/ |
61 | 61 |
/* |
62 |
Display some basic info about the sensor status
|
|
63 |
*/
|
|
62 |
Display some basic info about the sensor status
|
|
63 |
*/
|
|
64 | 64 |
/**************************************************************************/ |
65 | 65 |
void displaySensorStatus(void) |
66 | 66 |
{ |
67 |
/* Get the system status values (mostly for debugging purposes) */
|
|
68 |
uint8_t system_status, self_test_results, system_error;
|
|
69 |
system_status = self_test_results = system_error = 0;
|
|
70 |
bno.getSystemStatus(&system_status, &self_test_results, &system_error);
|
|
71 |
|
|
72 |
/* Display the results in the Serial Monitor */
|
|
73 |
Serial.println("");
|
|
74 |
Serial.print("System Status: 0x");
|
|
75 |
Serial.println(system_status, HEX);
|
|
76 |
Serial.print("Self Test: 0x");
|
|
77 |
Serial.println(self_test_results, HEX);
|
|
78 |
Serial.print("System Error: 0x");
|
|
79 |
Serial.println(system_error, HEX);
|
|
80 |
Serial.println("");
|
|
81 |
delay(500);
|
|
67 |
/* Get the system status values (mostly for debugging purposes) */
|
|
68 |
uint8_t system_status, self_test_results, system_error;
|
|
69 |
system_status = self_test_results = system_error = 0;
|
|
70 |
bno.getSystemStatus(&system_status, &self_test_results, &system_error);
|
|
71 |
|
|
72 |
/* Display the results in the Serial Monitor */
|
|
73 |
Serial.println("");
|
|
74 |
Serial.print("System Status: 0x");
|
|
75 |
Serial.println(system_status, HEX);
|
|
76 |
Serial.print("Self Test: 0x");
|
|
77 |
Serial.println(self_test_results, HEX);
|
|
78 |
Serial.print("System Error: 0x");
|
|
79 |
Serial.println(system_error, HEX);
|
|
80 |
Serial.println("");
|
|
81 |
delay(500);
|
|
82 | 82 |
} |
83 | 83 |
|
84 | 84 |
/**************************************************************************/ |
85 | 85 |
/* |
86 |
Display sensor calibration status
|
|
87 |
*/
|
|
86 |
Display sensor calibration status
|
|
87 |
*/
|
|
88 | 88 |
/**************************************************************************/ |
89 | 89 |
void displayCalStatus(void) |
90 | 90 |
{ |
91 |
/* Get the four calibration values (0..3) */
|
|
92 |
/* Any sensor data reporting 0 should be ignored, */
|
|
93 |
/* 3 means 'fully calibrated" */
|
|
94 |
uint8_t system, gyro, accel, mag;
|
|
95 |
system = gyro = accel = mag = 0;
|
|
96 |
bno.getCalibration(&system, &gyro, &accel, &mag);
|
|
97 |
|
|
98 |
/* The data should be ignored until the system calibration is > 0 */
|
|
99 |
Serial.print("\t");
|
|
100 |
if (!system)
|
|
101 |
{
|
|
102 |
Serial.print("! ");
|
|
103 |
}
|
|
104 |
|
|
105 |
/* Display the individual values */
|
|
106 |
Serial.print("Sys:");
|
|
107 |
Serial.print(system, DEC);
|
|
108 |
Serial.print(" G:");
|
|
109 |
Serial.print(gyro, DEC);
|
|
110 |
Serial.print(" A:");
|
|
111 |
Serial.print(accel, DEC);
|
|
112 |
Serial.print(" M:");
|
|
113 |
Serial.print(mag, DEC);
|
|
91 |
/* Get the four calibration values (0..3) */
|
|
92 |
/* Any sensor data reporting 0 should be ignored, */
|
|
93 |
/* 3 means 'fully calibrated" */
|
|
94 |
uint8_t system, gyro, accel, mag;
|
|
95 |
system = gyro = accel = mag = 0;
|
|
96 |
bno.getCalibration(&system, &gyro, &accel, &mag);
|
|
97 |
|
|
98 |
/* The data should be ignored until the system calibration is > 0 */
|
|
99 |
Serial.print("\t");
|
|
100 |
if (!system)
|
|
101 |
{
|
|
102 |
Serial.print("! ");
|
|
103 |
}
|
|
104 |
|
|
105 |
/* Display the individual values */
|
|
106 |
Serial.print("Sys:");
|
|
107 |
Serial.print(system, DEC);
|
|
108 |
Serial.print(" G:");
|
|
109 |
Serial.print(gyro, DEC);
|
|
110 |
Serial.print(" A:");
|
|
111 |
Serial.print(accel, DEC);
|
|
112 |
Serial.print(" M:");
|
|
113 |
Serial.print(mag, DEC);
|
|
114 | 114 |
} |
115 | 115 |
|
116 | 116 |
/**************************************************************************/ |
117 | 117 |
/* |
118 |
Display the raw calibration offset and radius data
|
|
119 |
*/
|
|
118 |
Display the raw calibration offset and radius data
|
|
119 |
*/
|
|
120 | 120 |
/**************************************************************************/ |
121 | 121 |
void displaySensorOffsets(const adafruit_bno055_offsets_t &calibData) |
122 | 122 |
{ |
123 |
Serial.print("Accelerometer: ");
|
|
124 |
Serial.print(calibData.accel_offset_x); Serial.print(" ");
|
|
125 |
Serial.print(calibData.accel_offset_y); Serial.print(" ");
|
|
126 |
Serial.print(calibData.accel_offset_z); Serial.print(" ");
|
|
127 |
|
|
128 |
Serial.print("\nGyro: ");
|
|
129 |
Serial.print(calibData.gyro_offset_x); Serial.print(" ");
|
|
130 |
Serial.print(calibData.gyro_offset_y); Serial.print(" ");
|
|
131 |
Serial.print(calibData.gyro_offset_z); Serial.print(" ");
|
|
132 |
|
|
133 |
Serial.print("\nMag: ");
|
|
134 |
Serial.print(calibData.mag_offset_x); Serial.print(" ");
|
|
135 |
Serial.print(calibData.mag_offset_y); Serial.print(" ");
|
|
136 |
Serial.print(calibData.mag_offset_z); Serial.print(" ");
|
|
137 |
|
|
138 |
Serial.print("\nAccel Radius: ");
|
|
139 |
Serial.print(calibData.accel_radius);
|
|
140 |
|
|
141 |
Serial.print("\nMag Radius: ");
|
|
142 |
Serial.print(calibData.mag_radius);
|
|
123 |
Serial.print("Accelerometer: ");
|
|
124 |
Serial.print(calibData.accel_offset_x); Serial.print(" ");
|
|
125 |
Serial.print(calibData.accel_offset_y); Serial.print(" ");
|
|
126 |
Serial.print(calibData.accel_offset_z); Serial.print(" ");
|
|
127 |
|
|
128 |
Serial.print("\nGyro: ");
|
|
129 |
Serial.print(calibData.gyro_offset_x); Serial.print(" ");
|
|
130 |
Serial.print(calibData.gyro_offset_y); Serial.print(" ");
|
|
131 |
Serial.print(calibData.gyro_offset_z); Serial.print(" ");
|
|
132 |
|
|
133 |
Serial.print("\nMag: ");
|
|
134 |
Serial.print(calibData.mag_offset_x); Serial.print(" ");
|
|
135 |
Serial.print(calibData.mag_offset_y); Serial.print(" ");
|
|
136 |
Serial.print(calibData.mag_offset_z); Serial.print(" ");
|
|
137 |
|
|
138 |
Serial.print("\nAccel Radius: ");
|
|
139 |
Serial.print(calibData.accel_radius);
|
|
140 |
|
|
141 |
Serial.print("\nMag Radius: ");
|
|
142 |
Serial.print(calibData.mag_radius);
|
|
143 | 143 |
} |
144 | 144 |
|
145 | 145 |
|
146 | 146 |
/**************************************************************************/ |
147 | 147 |
/* |
148 |
Arduino setup function (automatically called at startup)
|
|
149 |
*/
|
|
148 |
Arduino setup function (automatically called at startup)
|
|
149 |
*/
|
|
150 | 150 |
/**************************************************************************/ |
151 | 151 |
void setup(void) |
152 | 152 |
{ |
153 |
Serial.begin(115200); |
|
154 |
Serial.println("Orientation Sensor Test"); Serial.println(""); |
|
155 |
|
|
156 |
/* Initialise the sensor */ |
|
157 |
if (!bno.begin()) |
|
158 |
{ |
|
159 |
/* There was a problem detecting the BNO055 ... check your connections */ |
|
160 |
Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!"); |
|
161 |
while (1); |
|
162 |
} |
|
163 |
|
|
164 |
int eeAddress = 0; |
|
165 |
long bnoID; |
|
166 |
bool foundCalib = false; |
|
167 |
|
|
168 |
EEPROM.get(eeAddress, bnoID); |
|
169 |
|
|
170 |
adafruit_bno055_offsets_t calibrationData; |
|
171 |
sensor_t sensor; |
|
172 |
|
|
173 |
/* |
|
174 |
* Look for the sensor's unique ID at the beginning oF EEPROM. |
|
175 |
* This isn't foolproof, but it's better than nothing. |
|
176 |
*/ |
|
177 |
bno.getSensor(&sensor); |
|
178 |
if (bnoID != sensor.sensor_id) |
|
179 |
{ |
|
180 |
Serial.println("\nNo Calibration Data for this sensor exists in EEPROM"); |
|
181 |
} |
|
182 |
else |
|
183 |
{ |
|
184 |
Serial.println("\nFound Calibration for this sensor in EEPROM."); |
|
185 |
eeAddress += sizeof(long); |
|
186 |
EEPROM.get(eeAddress, calibrationData); |
|
187 |
|
|
188 |
displaySensorOffsets(calibrationData); |
|
189 |
|
|
190 |
Serial.println("\n\nRestoring Calibration data to the BNO055..."); |
|
191 |
bno.setSensorOffsets(calibrationData); |
|
192 |
|
|
193 |
Serial.println("\n\nCalibration data loaded into BNO055"); |
|
153 |
Serial.begin(115200); |
|
154 |
delay(1000); |
|
155 |
Serial.println("Orientation Sensor Test"); Serial.println(""); |
|
156 |
|
|
157 |
/* Initialise the sensor */ |
|
158 |
if (!bno.begin()) |
|
159 |
{ |
|
160 |
/* There was a problem detecting the BNO055 ... check your connections */ |
|
161 |
Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!"); |
|
162 |
while (1); |
|
163 |
} |
|
164 |
|
|
165 |
int eeAddress = 0; |
|
166 |
long bnoID; |
|
167 |
bool foundCalib = false; |
|
168 |
|
|
169 |
EEPROM.get(eeAddress, bnoID); |
|
170 |
|
|
171 |
adafruit_bno055_offsets_t calibrationData; |
|
172 |
sensor_t sensor; |
|
173 |
|
|
174 |
/* |
|
175 |
* Look for the sensor's unique ID at the beginning oF EEPROM. |
|
176 |
* This isn't foolproof, but it's better than nothing. |
|
177 |
*/ |
|
178 |
bno.getSensor(&sensor); |
|
179 |
if (bnoID != sensor.sensor_id) |
|
180 |
{ |
|
181 |
Serial.println("\nNo Calibration Data for this sensor exists in EEPROM"); |
|
182 |
delay(500); |
|
183 |
} |
|
184 |
else |
|
185 |
{ |
|
186 |
Serial.println("\nFound Calibration for this sensor in EEPROM."); |
|
187 |
eeAddress += sizeof(long); |
|
188 |
EEPROM.get(eeAddress, calibrationData); |
|
189 |
|
|
190 |
displaySensorOffsets(calibrationData); |
|
191 |
|
|
192 |
Serial.println("\n\nRestoring Calibration data to the BNO055..."); |
|
193 |
bno.setSensorOffsets(calibrationData); |
|
194 |
|
|
195 |
Serial.println("\n\nCalibration data loaded into BNO055"); |
|
194 | 196 |
foundCalib = true; |
195 |
}
|
|
197 |
}
|
|
196 | 198 |
|
197 |
delay(1000);
|
|
199 |
delay(1000);
|
|
198 | 200 |
|
199 |
/* Display some basic information on this sensor */
|
|
200 |
displaySensorDetails();
|
|
201 |
/* Display some basic information on this sensor */
|
|
202 |
displaySensorDetails();
|
|
201 | 203 |
|
202 |
/* Optional: Display current status */
|
|
203 |
displaySensorStatus();
|
|
204 |
/* Optional: Display current status */
|
|
205 |
displaySensorStatus();
|
|
204 | 206 |
|
205 |
bno.setExtCrystalUse(true);
|
|
207 |
bno.setExtCrystalUse(true);
|
|
206 | 208 |
|
207 |
sensors_event_t event;
|
|
208 |
bno.getEvent(&event);
|
|
209 |
if(foundCalib){ |
|
209 |
sensors_event_t event;
|
|
210 |
bno.getEvent(&event);
|
|
211 |
if (foundCalib){
|
|
210 | 212 |
Serial.println("Move sensor slightly to calibrate magnetometers"); |
211 | 213 |
while (!bno.isFullyCalibrated()) |
212 | 214 |
{ |
... | ... | |
216 | 218 |
} |
217 | 219 |
else |
218 | 220 |
{ |
221 |
Serial.println("Please Calibrate Sensor: "); |
|
219 | 222 |
while (!bno.isFullyCalibrated()) |
220 | 223 |
{ |
221 | 224 |
bno.getEvent(&event); |
222 |
|
|
225 |
|
|
223 | 226 |
Serial.print("X: "); |
224 | 227 |
Serial.print(event.orientation.x, 4); |
225 | 228 |
Serial.print("\tY: "); |
226 | 229 |
Serial.print(event.orientation.y, 4); |
227 | 230 |
Serial.print("\tZ: "); |
228 | 231 |
Serial.print(event.orientation.z, 4); |
229 |
|
|
232 |
|
|
230 | 233 |
/* Optional: Display calibration status */ |
231 | 234 |
displayCalStatus(); |
232 |
|
|
235 |
|
|
233 | 236 |
/* New line for the next sample */ |
234 | 237 |
Serial.println(""); |
235 |
|
|
238 |
|
|
236 | 239 |
/* Wait the specified delay before requesting new data */ |
237 | 240 |
delay(BNO055_SAMPLERATE_DELAY_MS); |
238 | 241 |
} |
239 | 242 |
} |
240 | 243 |
|
241 |
Serial.println("\nFully calibrated!");
|
|
242 |
Serial.println("--------------------------------");
|
|
243 |
Serial.println("Calibration Results: ");
|
|
244 |
adafruit_bno055_offsets_t newCalib;
|
|
245 |
bno.getSensorOffsets(newCalib);
|
|
246 |
displaySensorOffsets(newCalib);
|
|
247 |
|
|
244 |
Serial.println("\nFully calibrated!");
|
|
245 |
Serial.println("--------------------------------");
|
|
246 |
Serial.println("Calibration Results: ");
|
|
247 |
adafruit_bno055_offsets_t newCalib;
|
|
248 |
bno.getSensorOffsets(newCalib);
|
|
249 |
displaySensorOffsets(newCalib);
|
|
250 |
|
|
248 | 251 |
Serial.println("\n\nStoring calibration data to EEPROM..."); |
249 | 252 |
|
250 |
eeAddress = 0; |
|
251 |
bno.getSensor(&sensor); |
|
252 |
bnoID = sensor.sensor_id; |
|
253 |
eeAddress = 0; |
|
254 |
bno.getSensor(&sensor); |
|
255 |
bnoID = sensor.sensor_id; |
|
256 |
|
|
257 |
EEPROM.put(eeAddress, bnoID); |
|
253 | 258 |
|
254 |
EEPROM.put(eeAddress, bnoID); |
|
259 |
eeAddress += sizeof(long); |
|
260 |
EEPROM.put(eeAddress, newCalib); |
|
261 |
Serial.println("Data stored to EEPROM."); |
|
255 | 262 |
|
256 |
eeAddress += sizeof(long); |
|
257 |
EEPROM.put(eeAddress, newCalib); |
|
258 |
Serial.println("Data stored to EEPROM."); |
|
259 |
|
|
260 |
Serial.println("\n--------------------------------\n"); |
|
261 |
delay(500); |
|
263 |
Serial.println("\n--------------------------------\n"); |
|
264 |
delay(500); |
|
262 | 265 |
} |
263 | 266 |
|
264 | 267 |
void loop() { |
265 |
/* Get a new sensor event */
|
|
266 |
sensors_event_t event;
|
|
267 |
bno.getEvent(&event);
|
|
268 |
/* Get a new sensor event */
|
|
269 |
sensors_event_t event;
|
|
270 |
bno.getEvent(&event);
|
|
268 | 271 |
|
269 |
/* Display the floating point data */
|
|
270 |
Serial.print("X: ");
|
|
271 |
Serial.print(event.orientation.x, 4);
|
|
272 |
Serial.print("\tY: ");
|
|
273 |
Serial.print(event.orientation.y, 4);
|
|
274 |
Serial.print("\tZ: ");
|
|
275 |
Serial.print(event.orientation.z, 4);
|
|
272 |
/* Display the floating point data */
|
|
273 |
Serial.print("X: ");
|
|
274 |
Serial.print(event.orientation.x, 4);
|
|
275 |
Serial.print("\tY: ");
|
|
276 |
Serial.print(event.orientation.y, 4);
|
|
277 |
Serial.print("\tZ: ");
|
|
278 |
Serial.print(event.orientation.z, 4);
|
|
276 | 279 |
|
277 |
/* Optional: Display calibration status */
|
|
278 |
displayCalStatus();
|
|
280 |
/* Optional: Display calibration status */
|
|
281 |
displayCalStatus();
|
|
279 | 282 |
|
280 |
/* Optional: Display sensor status (debug only) */
|
|
281 |
//displaySensorStatus();
|
|
283 |
/* Optional: Display sensor status (debug only) */
|
|
284 |
//displaySensorStatus();
|
|
282 | 285 |
|
283 |
/* New line for the next sample */
|
|
284 |
Serial.println("");
|
|
286 |
/* New line for the next sample */
|
|
287 |
Serial.println("");
|
|
285 | 288 |
|
286 |
/* Wait the specified delay before requesting new data */
|
|
287 |
delay(BNO055_SAMPLERATE_DELAY_MS);
|
|
289 |
/* Wait the specified delay before requesting new data */
|
|
290 |
delay(BNO055_SAMPLERATE_DELAY_MS);
|
|
288 | 291 |
} |
Also available in: Unified diff