Statistics
| Branch: | Revision:

adafruit_bno055 / Adafruit_BNO055.cpp @ 5e9f001d

History | View | Annotate | Download (26.488 KB)

1 5d8d461e Jan Hoffmann
/*!
2
 * @file Adafruit_BNO055.cpp
3
 *
4
 *  @mainpage Adafruit BNO055 Orientation Sensor
5 75f03d2e Szymon Kaliski
 *
6 5d8d461e Jan Hoffmann
 *  @section intro_sec Introduction
7
 *
8 75f03d2e Szymon Kaliski
 *  This is a library for the BNO055 orientation sensor
9 5d8d461e Jan Hoffmann
 *
10 75f03d2e Szymon Kaliski
 *  Designed specifically to work with the Adafruit BNO055 Breakout.
11 5d8d461e Jan Hoffmann
 *
12 75f03d2e Szymon Kaliski
 *  Pick one up today in the adafruit shop!
13
 *  ------> https://www.adafruit.com/product/2472
14 5d8d461e Jan Hoffmann
 *
15 75f03d2e Szymon Kaliski
 *  These sensors use I2C to communicate, 2 pins are required to interface.
16 5d8d461e Jan Hoffmann
 *
17 75f03d2e Szymon Kaliski
 *  Adafruit invests time and resources providing this open source code,
18
 *  please support Adafruit andopen-source hardware by purchasing products
19
 *  from Adafruit!
20 5d8d461e Jan Hoffmann
 *
21
 *  @section author Author
22
 *
23
 *  K.Townsend (Adafruit Industries)
24
 *
25 75f03d2e Szymon Kaliski
 *  @section license License
26
 *
27
 *  MIT license, all text above must be included in any redistribution
28 5d8d461e Jan Hoffmann
 */
29 4bc1c0c1 Kevin Townsend
30 55e2f6d1 Jan Hoffmann
#include "Arduino.h"
31 4bc1c0c1 Kevin Townsend
32
#include <limits.h>
33 55e2f6d1 Jan Hoffmann
#include <math.h>
34 4bc1c0c1 Kevin Townsend
35
#include "Adafruit_BNO055.h"
36
37
/*!
38 5d8d461e Jan Hoffmann
 *  @brief  Instantiates a new Adafruit_BNO055 class
39 9a8e8b26 Jan Hoffmann
 *  @param  sensorID
40
 *          sensor ID
41
 *  @param  address
42
 *          i2c address
43 2b95af9e ulysse314
 *  @param  theWire
44 dbc34b4d Jan Hoffmann
 *          Wire object
45 5d8d461e Jan Hoffmann
 */
46 9a8e8b26 Jan Hoffmann
Adafruit_BNO055::Adafruit_BNO055(int32_t sensorID, uint8_t address,
47
                                 TwoWire *theWire) {
48 463eabf7 Wetmelon
  _sensorID = sensorID;
49
  _address = address;
50 83911fa6 Jan Hoffmann
  _wire = theWire;
51 4bc1c0c1 Kevin Townsend
}
52
53
/*!
54 f7556b0d Jan Hoffmann
 *  @brief  Sets up the HW
55
 *  @param  mode
56
 *          mode values
57
 *           [OPERATION_MODE_CONFIG,
58
 *            OPERATION_MODE_ACCONLY,
59
 *            OPERATION_MODE_MAGONLY,
60
 *            OPERATION_MODE_GYRONLY,
61
 *            OPERATION_MODE_ACCMAG,
62
 *            OPERATION_MODE_ACCGYRO,
63
 *            OPERATION_MODE_MAGGYRO,
64
 *            OPERATION_MODE_AMG,
65
 *            OPERATION_MODE_IMUPLUS,
66
 *            OPERATION_MODE_COMPASS,
67
 *            OPERATION_MODE_M4G,
68
 *            OPERATION_MODE_NDOF_FMC_OFF,
69
 *            OPERATION_MODE_NDOF]
70
 *  @return true if process is successful
71
 */
72 9a8e8b26 Jan Hoffmann
bool Adafruit_BNO055::begin(adafruit_bno055_opmode_t mode) {
73
#if defined(ARDUINO_SAMD_ZERO) && (_address == BNO055_ADDRESS_A)
74 f7556b0d Jan Hoffmann
#error                                                                         \
75
    "On an arduino Zero, BNO055's ADR pin must be high. Fix that, then delete this line."
76
  _address = BNO055_ADDRESS_B;
77
#endif
78
79 463eabf7 Wetmelon
  /* Enable I2C */
80 f7556b0d Jan Hoffmann
  _wire->begin();
81 463eabf7 Wetmelon
82 78cc710f ladyada
  // BNO055 clock stretches for 500us or more!
83
#ifdef ESP8266
84 9a8e8b26 Jan Hoffmann
  _wire->setClockStretchLimit(1000); // Allow for 1000us of clock stretching
85 78cc710f ladyada
#endif
86
87 463eabf7 Wetmelon
  /* Make sure we have the right device */
88
  uint8_t id = read8(BNO055_CHIP_ID_ADDR);
89 55e2f6d1 Jan Hoffmann
  if (id != BNO055_ID) {
90 463eabf7 Wetmelon
    delay(1000); // hold on for boot
91
    id = read8(BNO055_CHIP_ID_ADDR);
92 55e2f6d1 Jan Hoffmann
    if (id != BNO055_ID) {
93 9a8e8b26 Jan Hoffmann
      return false; // still not? ok bail
94 463eabf7 Wetmelon
    }
95
  }
96
97
  /* Switch to config mode (just in case since this is the default) */
98
  setMode(OPERATION_MODE_CONFIG);
99
100
  /* Reset */
101
  write8(BNO055_SYS_TRIGGER_ADDR, 0x20);
102 5f6b7a75 Jan Hoffmann
  /* Delay incrased to 30ms due to power issues https://tinyurl.com/y375z699 */
103
  delay(30);
104 55e2f6d1 Jan Hoffmann
  while (read8(BNO055_CHIP_ID_ADDR) != BNO055_ID) {
105 463eabf7 Wetmelon
    delay(10);
106
  }
107
  delay(50);
108
109
  /* Set to normal power mode */
110
  write8(BNO055_PWR_MODE_ADDR, POWER_MODE_NORMAL);
111
  delay(10);
112
113
  write8(BNO055_PAGE_ID_ADDR, 0);
114
115
  /* Set the output units */
116
  /*
117
  uint8_t unitsel = (0 << 7) | // Orientation = Android
118
                    (0 << 4) | // Temperature = Celsius
119
                    (0 << 2) | // Euler = Degrees
120
                    (1 << 1) | // Gyro = Rads
121
                    (0 << 0);  // Accelerometer = m/s^2
122
  write8(BNO055_UNIT_SEL_ADDR, unitsel);
123
  */
124
125 8d5b341f Jan
  // Select BNO055 gyro temperature source - REDUCES DRIFT SIGNIFICANTLY!
126
  write8(BNO055_TEMP_SOURCE_ADDR, 0x01);
127
128 378858ec Shunya Sato
  /* Configure axis mapping (see section 3.4) */
129
  /*
130
  write8(BNO055_AXIS_MAP_CONFIG_ADDR, REMAP_CONFIG_P2); // P0-P7, Default is P1
131
  delay(10);
132
  write8(BNO055_AXIS_MAP_SIGN_ADDR, REMAP_SIGN_P2); // P0-P7, Default is P1
133
  delay(10);
134
  */
135 a97e0fe1 kA®0šhî
136 463eabf7 Wetmelon
  write8(BNO055_SYS_TRIGGER_ADDR, 0x0);
137
  delay(10);
138
  /* Set the requested operating mode (see section 3.3) */
139
  setMode(mode);
140
  delay(20);
141
142
  return true;
143 4bc1c0c1 Kevin Townsend
}
144
145
/*!
146 5d8d461e Jan Hoffmann
 *  @brief  Puts the chip in the specified operating mode
147
 *  @param  mode
148 f7556b0d Jan Hoffmann
 *          mode values
149
 *           [OPERATION_MODE_CONFIG,
150
 *            OPERATION_MODE_ACCONLY,
151
 *            OPERATION_MODE_MAGONLY,
152
 *            OPERATION_MODE_GYRONLY,
153
 *            OPERATION_MODE_ACCMAG,
154
 *            OPERATION_MODE_ACCGYRO,
155
 *            OPERATION_MODE_MAGGYRO,
156
 *            OPERATION_MODE_AMG,
157
 *            OPERATION_MODE_IMUPLUS,
158
 *            OPERATION_MODE_COMPASS,
159
 *            OPERATION_MODE_M4G,
160
 *            OPERATION_MODE_NDOF_FMC_OFF,
161
 *            OPERATION_MODE_NDOF]
162 5d8d461e Jan Hoffmann
 */
163 55e2f6d1 Jan Hoffmann
void Adafruit_BNO055::setMode(adafruit_bno055_opmode_t mode) {
164 463eabf7 Wetmelon
  _mode = mode;
165
  write8(BNO055_OPR_MODE_ADDR, _mode);
166
  delay(30);
167 4bc1c0c1 Kevin Townsend
}
168
169
/*!
170 5d8d461e Jan Hoffmann
 *  @brief  Changes the chip's axis remap
171
 *  @param  remapcode
172 f7556b0d Jan Hoffmann
 *          remap code possible values
173
 *          [REMAP_CONFIG_P0
174
 *           REMAP_CONFIG_P1 (default)
175
 *           REMAP_CONFIG_P2
176
 *           REMAP_CONFIG_P3
177
 *           REMAP_CONFIG_P4
178
 *           REMAP_CONFIG_P5
179
 *           REMAP_CONFIG_P6
180
 *           REMAP_CONFIG_P7]
181 5d8d461e Jan Hoffmann
 */
182 55e2f6d1 Jan Hoffmann
void Adafruit_BNO055::setAxisRemap(
183
    adafruit_bno055_axis_remap_config_t remapcode) {
184 a97e0fe1 kA®0šhî
  adafruit_bno055_opmode_t modeback = _mode;
185
186
  setMode(OPERATION_MODE_CONFIG);
187
  delay(25);
188
  write8(BNO055_AXIS_MAP_CONFIG_ADDR, remapcode);
189
  delay(10);
190
  /* Set the requested operating mode (see section 3.3) */
191
  setMode(modeback);
192
  delay(20);
193
}
194
195
/*!
196 5d8d461e Jan Hoffmann
 *  @brief  Changes the chip's axis signs
197
 *  @param  remapsign
198 f7556b0d Jan Hoffmann
 *          remap sign possible values
199
 *          [REMAP_SIGN_P0
200
 *           REMAP_SIGN_P1 (default)
201
 *           REMAP_SIGN_P2
202
 *           REMAP_SIGN_P3
203
 *           REMAP_SIGN_P4
204
 *           REMAP_SIGN_P5
205
 *           REMAP_SIGN_P6
206
 *           REMAP_SIGN_P7]
207 5d8d461e Jan Hoffmann
 */
208 55e2f6d1 Jan Hoffmann
void Adafruit_BNO055::setAxisSign(adafruit_bno055_axis_remap_sign_t remapsign) {
209 a97e0fe1 kA®0šhî
  adafruit_bno055_opmode_t modeback = _mode;
210
211
  setMode(OPERATION_MODE_CONFIG);
212
  delay(25);
213
  write8(BNO055_AXIS_MAP_SIGN_ADDR, remapsign);
214
  delay(10);
215
  /* Set the requested operating mode (see section 3.3) */
216
  setMode(modeback);
217
  delay(20);
218
}
219
220
/*!
221 5d8d461e Jan Hoffmann
 *  @brief  Use the external 32.768KHz crystal
222 f7556b0d Jan Hoffmann
 *  @param  usextal
223
 *          use external crystal boolean
224 5d8d461e Jan Hoffmann
 */
225 55e2f6d1 Jan Hoffmann
void Adafruit_BNO055::setExtCrystalUse(boolean usextal) {
226 463eabf7 Wetmelon
  adafruit_bno055_opmode_t modeback = _mode;
227
228
  /* Switch to config mode (just in case since this is the default) */
229
  setMode(OPERATION_MODE_CONFIG);
230
  delay(25);
231
  write8(BNO055_PAGE_ID_ADDR, 0);
232
  if (usextal) {
233
    write8(BNO055_SYS_TRIGGER_ADDR, 0x80);
234
  } else {
235
    write8(BNO055_SYS_TRIGGER_ADDR, 0x00);
236
  }
237
  delay(10);
238
  /* Set the requested operating mode (see section 3.3) */
239
  setMode(modeback);
240
  delay(20);
241 c4f272e1 ladyada
}
242
243
/*!
244 5d8d461e Jan Hoffmann
 *   @brief  Gets the latest system status info
245
 *   @param  system_status
246 f7556b0d Jan Hoffmann
 *           system status info
247 5d8d461e Jan Hoffmann
 *   @param  self_test_result
248 f7556b0d Jan Hoffmann
 *           self test result
249 5d8d461e Jan Hoffmann
 *   @param  system_error
250 f7556b0d Jan Hoffmann
 *           system error info
251 5d8d461e Jan Hoffmann
 */
252 55e2f6d1 Jan Hoffmann
void Adafruit_BNO055::getSystemStatus(uint8_t *system_status,
253
                                      uint8_t *self_test_result,
254
                                      uint8_t *system_error) {
255 463eabf7 Wetmelon
  write8(BNO055_PAGE_ID_ADDR, 0);
256
257
  /* System Status (see section 4.3.58)
258
     0 = Idle
259
     1 = System Error
260
     2 = Initializing Peripherals
261
     3 = System Iniitalization
262
     4 = Executing Self-Test
263
     5 = Sensor fusio algorithm running
264 75f03d2e Szymon Kaliski
     6 = System running without fusion algorithms
265 5d8d461e Jan Hoffmann
   */
266 463eabf7 Wetmelon
267
  if (system_status != 0)
268 55e2f6d1 Jan Hoffmann
    *system_status = read8(BNO055_SYS_STAT_ADDR);
269 463eabf7 Wetmelon
270 5d8d461e Jan Hoffmann
  /* Self Test Results
271 463eabf7 Wetmelon
     1 = test passed, 0 = test failed
272

273
     Bit 0 = Accelerometer self test
274
     Bit 1 = Magnetometer self test
275
     Bit 2 = Gyroscope self test
276
     Bit 3 = MCU self test
277

278 75f03d2e Szymon Kaliski
     0x0F = all good!
279 5d8d461e Jan Hoffmann
   */
280 463eabf7 Wetmelon
281
  if (self_test_result != 0)
282
    *self_test_result = read8(BNO055_SELFTEST_RESULT_ADDR);
283
284
  /* System Error (see section 4.3.59)
285
     0 = No error
286
     1 = Peripheral initialization error
287
     2 = System initialization error
288
     3 = Self test result failed
289
     4 = Register map value out of range
290
     5 = Register map address out of range
291
     6 = Register map write error
292
     7 = BNO low power mode not available for selected operat ion mode
293
     8 = Accelerometer power mode not available
294
     9 = Fusion algorithm configuration error
295 75f03d2e Szymon Kaliski
     A = Sensor configuration error
296 5d8d461e Jan Hoffmann
   */
297 463eabf7 Wetmelon
298
  if (system_error != 0)
299 55e2f6d1 Jan Hoffmann
    *system_error = read8(BNO055_SYS_ERR_ADDR);
300 463eabf7 Wetmelon
301
  delay(200);
302 4bc1c0c1 Kevin Townsend
}
303
304
/*!
305 5d8d461e Jan Hoffmann
 *  @brief  Gets the chip revision numbers
306 f7556b0d Jan Hoffmann
 *  @param  info
307
 *          revision info
308 5d8d461e Jan Hoffmann
 */
309 55e2f6d1 Jan Hoffmann
void Adafruit_BNO055::getRevInfo(adafruit_bno055_rev_info_t *info) {
310 463eabf7 Wetmelon
  uint8_t a, b;
311 4bc1c0c1 Kevin Townsend
312 463eabf7 Wetmelon
  memset(info, 0, sizeof(adafruit_bno055_rev_info_t));
313 4bc1c0c1 Kevin Townsend
314 463eabf7 Wetmelon
  /* Check the accelerometer revision */
315
  info->accel_rev = read8(BNO055_ACCEL_REV_ID_ADDR);
316 67f3cff5 Kevin Townsend
317 463eabf7 Wetmelon
  /* Check the magnetometer revision */
318 55e2f6d1 Jan Hoffmann
  info->mag_rev = read8(BNO055_MAG_REV_ID_ADDR);
319 67f3cff5 Kevin Townsend
320 463eabf7 Wetmelon
  /* Check the gyroscope revision */
321 55e2f6d1 Jan Hoffmann
  info->gyro_rev = read8(BNO055_GYRO_REV_ID_ADDR);
322 67f3cff5 Kevin Townsend
323 463eabf7 Wetmelon
  /* Check the SW revision */
324 55e2f6d1 Jan Hoffmann
  info->bl_rev = read8(BNO055_BL_REV_ID_ADDR);
325 40f91f6f Tony DiCola
326 463eabf7 Wetmelon
  a = read8(BNO055_SW_REV_ID_LSB_ADDR);
327
  b = read8(BNO055_SW_REV_ID_MSB_ADDR);
328
  info->sw_rev = (((uint16_t)b) << 8) | ((uint16_t)a);
329 4bc1c0c1 Kevin Townsend
}
330
331
/*!
332 5d8d461e Jan Hoffmann
 *  @brief  Gets current calibration state.  Each value should be a uint8_t
333
 *          pointer and it will be set to 0 if not calibrated and 3 if
334
 *          fully calibrated.
335 f7556b0d Jan Hoffmann
 *          See section 34.3.54
336 5d8d461e Jan Hoffmann
 *  @param  sys
337 f7556b0d Jan Hoffmann
 *          Current system calibration status, depends on status of all sensors,
338
 * read-only
339 5d8d461e Jan Hoffmann
 *  @param  gyro
340 f7556b0d Jan Hoffmann
 *          Current calibration status of Gyroscope, read-only
341 5d8d461e Jan Hoffmann
 *  @param  accel
342 f7556b0d Jan Hoffmann
 *          Current calibration status of Accelerometer, read-only
343 5d8d461e Jan Hoffmann
 *  @param  mag
344 f7556b0d Jan Hoffmann
 *          Current calibration status of Magnetometer, read-only
345 5d8d461e Jan Hoffmann
 */
346 55e2f6d1 Jan Hoffmann
void Adafruit_BNO055::getCalibration(uint8_t *sys, uint8_t *gyro,
347
                                     uint8_t *accel, uint8_t *mag) {
348 463eabf7 Wetmelon
  uint8_t calData = read8(BNO055_CALIB_STAT_ADDR);
349
  if (sys != NULL) {
350
    *sys = (calData >> 6) & 0x03;
351
  }
352
  if (gyro != NULL) {
353
    *gyro = (calData >> 4) & 0x03;
354
  }
355
  if (accel != NULL) {
356
    *accel = (calData >> 2) & 0x03;
357
  }
358
  if (mag != NULL) {
359
    *mag = calData & 0x03;
360
  }
361 40f91f6f Tony DiCola
}
362
363
/*!
364 5d8d461e Jan Hoffmann
 *  @brief  Gets the temperature in degrees celsius
365
 *  @return temperature in degrees celsius
366
 */
367 55e2f6d1 Jan Hoffmann
int8_t Adafruit_BNO055::getTemp() {
368 463eabf7 Wetmelon
  int8_t temp = (int8_t)(read8(BNO055_TEMP_ADDR));
369
  return temp;
370 0e2e2723 Kevin Townsend
}
371
372
/*!
373 5d8d461e Jan Hoffmann
 *  @brief   Gets a vector reading from the specified source
374
 *  @param   vector_type
375 f7556b0d Jan Hoffmann
 *           possible vector type values
376
 *           [VECTOR_ACCELEROMETER
377
 *            VECTOR_MAGNETOMETER
378
 *            VECTOR_GYROSCOPE
379
 *            VECTOR_EULER
380
 *            VECTOR_LINEARACCEL
381
 *            VECTOR_GRAVITY]
382 5d8d461e Jan Hoffmann
 *  @return  vector from specified source
383
 */
384 55e2f6d1 Jan Hoffmann
imu::Vector<3> Adafruit_BNO055::getVector(adafruit_vector_type_t vector_type) {
385 463eabf7 Wetmelon
  imu::Vector<3> xyz;
386
  uint8_t buffer[6];
387 55e2f6d1 Jan Hoffmann
  memset(buffer, 0, 6);
388 463eabf7 Wetmelon
389
  int16_t x, y, z;
390
  x = y = z = 0;
391
392
  /* Read vector data (6 bytes) */
393
  readLen((adafruit_bno055_reg_t)vector_type, buffer, 6);
394
395
  x = ((int16_t)buffer[0]) | (((int16_t)buffer[1]) << 8);
396
  y = ((int16_t)buffer[2]) | (((int16_t)buffer[3]) << 8);
397
  z = ((int16_t)buffer[4]) | (((int16_t)buffer[5]) << 8);
398
399 75f03d2e Szymon Kaliski
  /*!
400 5d8d461e Jan Hoffmann
   * Convert the value to an appropriate range (section 3.6.4)
401 75f03d2e Szymon Kaliski
   * and assign the value to the Vector type
402 5d8d461e Jan Hoffmann
   */
403 55e2f6d1 Jan Hoffmann
  switch (vector_type) {
404
  case VECTOR_MAGNETOMETER:
405
    /* 1uT = 16 LSB */
406
    xyz[0] = ((double)x) / 16.0;
407
    xyz[1] = ((double)y) / 16.0;
408
    xyz[2] = ((double)z) / 16.0;
409
    break;
410
  case VECTOR_GYROSCOPE:
411
    /* 1dps = 16 LSB */
412
    xyz[0] = ((double)x) / 16.0;
413
    xyz[1] = ((double)y) / 16.0;
414
    xyz[2] = ((double)z) / 16.0;
415
    break;
416
  case VECTOR_EULER:
417
    /* 1 degree = 16 LSB */
418
    xyz[0] = ((double)x) / 16.0;
419
    xyz[1] = ((double)y) / 16.0;
420
    xyz[2] = ((double)z) / 16.0;
421
    break;
422
  case VECTOR_ACCELEROMETER:
423 e223568a Jan Hoffmann
    /* 1m/s^2 = 100 LSB */
424
    xyz[0] = ((double)x) / 100.0;
425
    xyz[1] = ((double)y) / 100.0;
426
    xyz[2] = ((double)z) / 100.0;
427
    break;
428 55e2f6d1 Jan Hoffmann
  case VECTOR_LINEARACCEL:
429 e223568a Jan Hoffmann
    /* 1m/s^2 = 100 LSB */
430
    xyz[0] = ((double)x) / 100.0;
431
    xyz[1] = ((double)y) / 100.0;
432
    xyz[2] = ((double)z) / 100.0;
433
    break;
434 55e2f6d1 Jan Hoffmann
  case VECTOR_GRAVITY:
435
    /* 1m/s^2 = 100 LSB */
436
    xyz[0] = ((double)x) / 100.0;
437
    xyz[1] = ((double)y) / 100.0;
438
    xyz[2] = ((double)z) / 100.0;
439
    break;
440 463eabf7 Wetmelon
  }
441
442
  return xyz;
443 4bc1c0c1 Kevin Townsend
}
444
445
/*!
446 5d8d461e Jan Hoffmann
 *  @brief  Gets a quaternion reading from the specified source
447
 *  @return quaternion reading
448
 */
449 55e2f6d1 Jan Hoffmann
imu::Quaternion Adafruit_BNO055::getQuat() {
450 463eabf7 Wetmelon
  uint8_t buffer[8];
451 55e2f6d1 Jan Hoffmann
  memset(buffer, 0, 8);
452 463eabf7 Wetmelon
453
  int16_t x, y, z, w;
454
  x = y = z = w = 0;
455
456
  /* Read quat data (8 bytes) */
457
  readLen(BNO055_QUATERNION_DATA_W_LSB_ADDR, buffer, 8);
458
  w = (((uint16_t)buffer[1]) << 8) | ((uint16_t)buffer[0]);
459
  x = (((uint16_t)buffer[3]) << 8) | ((uint16_t)buffer[2]);
460
  y = (((uint16_t)buffer[5]) << 8) | ((uint16_t)buffer[4]);
461
  z = (((uint16_t)buffer[7]) << 8) | ((uint16_t)buffer[6]);
462
463 5d8d461e Jan Hoffmann
  /*!
464
   * Assign to Quaternion
465
   * See
466
   * http://ae-bst.resource.bosch.com/media/products/dokumente/bno055/BST_BNO055_DS000_12~1.pdf
467 75f03d2e Szymon Kaliski
   * 3.6.5.5 Orientation (Quaternion)
468 5d8d461e Jan Hoffmann
   */
469 55e2f6d1 Jan Hoffmann
  const double scale = (1.0 / (1 << 14));
470 463eabf7 Wetmelon
  imu::Quaternion quat(scale * w, scale * x, scale * y, scale * z);
471
  return quat;
472 48741e1f Kevin Townsend
}
473
474
/*!
475 5d8d461e Jan Hoffmann
 *  @brief  Provides the sensor_t data for this sensor
476
 *  @param  sensor
477 2b95af9e ulysse314
 *          Sensor description
478 75f03d2e Szymon Kaliski
 */
479 55e2f6d1 Jan Hoffmann
void Adafruit_BNO055::getSensor(sensor_t *sensor) {
480 463eabf7 Wetmelon
  /* Clear the sensor_t object */
481
  memset(sensor, 0, sizeof(sensor_t));
482
483
  /* Insert the sensor name in the fixed length char array */
484 55e2f6d1 Jan Hoffmann
  strncpy(sensor->name, "BNO055", sizeof(sensor->name) - 1);
485
  sensor->name[sizeof(sensor->name) - 1] = 0;
486
  sensor->version = 1;
487
  sensor->sensor_id = _sensorID;
488
  sensor->type = SENSOR_TYPE_ORIENTATION;
489
  sensor->min_delay = 0;
490
  sensor->max_value = 0.0F;
491
  sensor->min_value = 0.0F;
492
  sensor->resolution = 0.01F;
493 4bc1c0c1 Kevin Townsend
}
494
495
/*!
496 5d8d461e Jan Hoffmann
 *  @brief  Reads the sensor and returns the data as a sensors_event_t
497
 *  @param  event
498 2b95af9e ulysse314
 *          Event description
499 5d8d461e Jan Hoffmann
 *  @return always returns true
500
 */
501 55e2f6d1 Jan Hoffmann
bool Adafruit_BNO055::getEvent(sensors_event_t *event) {
502 463eabf7 Wetmelon
  /* Clear the event */
503
  memset(event, 0, sizeof(sensors_event_t));
504 4bc1c0c1 Kevin Townsend
505 55e2f6d1 Jan Hoffmann
  event->version = sizeof(sensors_event_t);
506 463eabf7 Wetmelon
  event->sensor_id = _sensorID;
507 55e2f6d1 Jan Hoffmann
  event->type = SENSOR_TYPE_ORIENTATION;
508 463eabf7 Wetmelon
  event->timestamp = millis();
509 fcd68623 Kevin Townsend
510 463eabf7 Wetmelon
  /* Get a Euler angle sample for orientation */
511
  imu::Vector<3> euler = getVector(Adafruit_BNO055::VECTOR_EULER);
512
  event->orientation.x = euler.x();
513
  event->orientation.y = euler.y();
514
  event->orientation.z = euler.z();
515 312a5b9e Wetmelon
516 463eabf7 Wetmelon
  return true;
517 312a5b9e Wetmelon
}
518 fcd68623 Kevin Townsend
519 312a5b9e Wetmelon
/*!
520 f0ebdf46 Jan Hoffmann
 *  @brief  Reads the sensor and returns the data as a sensors_event_t
521
 *  @param  event
522 2b95af9e ulysse314
 *          Event description
523 f0ebdf46 Jan Hoffmann
 *  @param  vec_type
524
 *          specify the type of reading
525
 *  @return always returns true
526
 */
527
bool Adafruit_BNO055::getEvent(sensors_event_t *event, adafruit_vector_type_t vec_type)
528 312a5b9e Wetmelon
{
529 f0ebdf46 Jan Hoffmann
  /* Clear the event */
530
  memset(event, 0, sizeof(sensors_event_t));
531 312a5b9e Wetmelon
532 f0ebdf46 Jan Hoffmann
  event->version = sizeof(sensors_event_t);
533
  event->sensor_id = _sensorID;
534
  event->timestamp = millis();
535 312a5b9e Wetmelon
536 f0ebdf46 Jan Hoffmann
  //read the data according to vec_type
537
  imu::Vector<3> vec;
538
  if (vec_type == Adafruit_BNO055::VECTOR_LINEARACCEL)
539
  {
540 7bc8249a Paul Otto
    event->type = SENSOR_TYPE_LINEAR_ACCELERATION;
541 f0ebdf46 Jan Hoffmann
    vec = getVector(Adafruit_BNO055::VECTOR_LINEARACCEL);
542 312a5b9e Wetmelon
543 f0ebdf46 Jan Hoffmann
    event->acceleration.x = vec.x();
544
    event->acceleration.y = vec.y();
545
    event->acceleration.z = vec.z();
546
  }
547
  else if (vec_type == Adafruit_BNO055::VECTOR_ACCELEROMETER)
548
  {
549
    event->type = SENSOR_TYPE_ACCELEROMETER;
550
    vec = getVector(Adafruit_BNO055::VECTOR_ACCELEROMETER);
551
552
    event->acceleration.x = vec.x();
553
    event->acceleration.y = vec.y();
554
    event->acceleration.z = vec.z();
555
  }
556
  else if (vec_type == Adafruit_BNO055::VECTOR_GRAVITY)
557
  {
558
    event->type = SENSOR_TYPE_ACCELEROMETER;
559
    vec = getVector(Adafruit_BNO055::VECTOR_GRAVITY);
560
561
    event->acceleration.x = vec.x();
562
    event->acceleration.y = vec.y();
563
    event->acceleration.z = vec.z();
564
  }
565
  else if (vec_type == Adafruit_BNO055::VECTOR_EULER)
566
  {
567
    event->type = SENSOR_TYPE_ORIENTATION;
568
    vec = getVector(Adafruit_BNO055::VECTOR_EULER);
569
570
    event->orientation.x = vec.x();
571
    event->orientation.y = vec.y();
572
    event->orientation.z = vec.z();
573
  }
574
  else if (vec_type == Adafruit_BNO055::VECTOR_GYROSCOPE)
575
  {
576
    event->type = SENSOR_TYPE_ROTATION_VECTOR;
577
    vec = getVector(Adafruit_BNO055::VECTOR_GYROSCOPE);
578
579
    event->gyro.x = vec.x();
580
    event->gyro.y = vec.y();
581
    event->gyro.z = vec.z();
582
  }
583
  else if (vec_type == Adafruit_BNO055::VECTOR_MAGNETOMETER)
584
  {
585
    event->type = SENSOR_TYPE_MAGNETIC_FIELD;
586
    vec = getVector(Adafruit_BNO055::VECTOR_MAGNETOMETER);
587
588
    event->magnetic.x = vec.x();
589
    event->magnetic.y = vec.y();
590
    event->magnetic.z = vec.z();
591
  }
592
  
593
594
  return true;
595 312a5b9e Wetmelon
}
596
597
598
/*!
599 5d8d461e Jan Hoffmann
 *  @brief  Reads the sensor's offset registers into a byte array
600
 *  @param  calibData
601 2b95af9e ulysse314
 *          Calibration offset (buffer size should be 22)
602 5d8d461e Jan Hoffmann
 *  @return true if read is successful
603
 */
604 55e2f6d1 Jan Hoffmann
bool Adafruit_BNO055::getSensorOffsets(uint8_t *calibData) {
605
  if (isFullyCalibrated()) {
606 463eabf7 Wetmelon
    adafruit_bno055_opmode_t lastMode = _mode;
607
    setMode(OPERATION_MODE_CONFIG);
608
609 55e2f6d1 Jan Hoffmann
    readLen(ACCEL_OFFSET_X_LSB_ADDR, calibData, NUM_BNO055_OFFSET_REGISTERS);
610 463eabf7 Wetmelon
611
    setMode(lastMode);
612 55e2f6d1 Jan Hoffmann
    return true;
613
  }
614
  return false;
615 4bc1c0c1 Kevin Townsend
}
616
617 312a5b9e Wetmelon
/*!
618 5d8d461e Jan Hoffmann
 *  @brief  Reads the sensor's offset registers into an offset struct
619
 *  @param  offsets_type
620 dbc34b4d Jan Hoffmann
 *          type of offsets
621 5d8d461e Jan Hoffmann
 *  @return true if read is successful
622
 */
623 55e2f6d1 Jan Hoffmann
bool Adafruit_BNO055::getSensorOffsets(
624
    adafruit_bno055_offsets_t &offsets_type) {
625
  if (isFullyCalibrated()) {
626 463eabf7 Wetmelon
    adafruit_bno055_opmode_t lastMode = _mode;
627
    setMode(OPERATION_MODE_CONFIG);
628
    delay(25);
629
630 55e2f6d1 Jan Hoffmann
    /* Accel offset range depends on the G-range:
631
       +/-2g  = +/- 2000 mg
632
       +/-4g  = +/- 4000 mg
633
       +/-8g  = +/- 8000 mg
634
       +/-1§g = +/- 16000 mg */
635
    offsets_type.accel_offset_x = (read8(ACCEL_OFFSET_X_MSB_ADDR) << 8) |
636
                                  (read8(ACCEL_OFFSET_X_LSB_ADDR));
637
    offsets_type.accel_offset_y = (read8(ACCEL_OFFSET_Y_MSB_ADDR) << 8) |
638
                                  (read8(ACCEL_OFFSET_Y_LSB_ADDR));
639
    offsets_type.accel_offset_z = (read8(ACCEL_OFFSET_Z_MSB_ADDR) << 8) |
640
                                  (read8(ACCEL_OFFSET_Z_LSB_ADDR));
641
642
    /* Magnetometer offset range = +/- 6400 LSB where 1uT = 16 LSB */
643
    offsets_type.mag_offset_x =
644
        (read8(MAG_OFFSET_X_MSB_ADDR) << 8) | (read8(MAG_OFFSET_X_LSB_ADDR));
645
    offsets_type.mag_offset_y =
646
        (read8(MAG_OFFSET_Y_MSB_ADDR) << 8) | (read8(MAG_OFFSET_Y_LSB_ADDR));
647
    offsets_type.mag_offset_z =
648
        (read8(MAG_OFFSET_Z_MSB_ADDR) << 8) | (read8(MAG_OFFSET_Z_LSB_ADDR));
649
650
    /* Gyro offset range depends on the DPS range:
651
      2000 dps = +/- 32000 LSB
652
      1000 dps = +/- 16000 LSB
653
       500 dps = +/- 8000 LSB
654
       250 dps = +/- 4000 LSB
655
       125 dps = +/- 2000 LSB
656
       ... where 1 DPS = 16 LSB */
657
    offsets_type.gyro_offset_x =
658
        (read8(GYRO_OFFSET_X_MSB_ADDR) << 8) | (read8(GYRO_OFFSET_X_LSB_ADDR));
659
    offsets_type.gyro_offset_y =
660
        (read8(GYRO_OFFSET_Y_MSB_ADDR) << 8) | (read8(GYRO_OFFSET_Y_LSB_ADDR));
661
    offsets_type.gyro_offset_z =
662
        (read8(GYRO_OFFSET_Z_MSB_ADDR) << 8) | (read8(GYRO_OFFSET_Z_LSB_ADDR));
663
664
    /* Accelerometer radius = +/- 1000 LSB */
665
    offsets_type.accel_radius =
666
        (read8(ACCEL_RADIUS_MSB_ADDR) << 8) | (read8(ACCEL_RADIUS_LSB_ADDR));
667
668
    /* Magnetometer radius = +/- 960 LSB */
669
    offsets_type.mag_radius =
670
        (read8(MAG_RADIUS_MSB_ADDR) << 8) | (read8(MAG_RADIUS_LSB_ADDR));
671 463eabf7 Wetmelon
672
    setMode(lastMode);
673 55e2f6d1 Jan Hoffmann
    return true;
674
  }
675
  return false;
676 312a5b9e Wetmelon
}
677
678 741a95a7 Kevin Townsend
/*!
679 75f03d2e Szymon Kaliski
 *  @brief  Writes an array of calibration values to the sensor's offset
680 2b95af9e ulysse314
 *  @param  calibData
681 f7556b0d Jan Hoffmann
 *          calibration data
682 5d8d461e Jan Hoffmann
 */
683 55e2f6d1 Jan Hoffmann
void Adafruit_BNO055::setSensorOffsets(const uint8_t *calibData) {
684
  adafruit_bno055_opmode_t lastMode = _mode;
685
  setMode(OPERATION_MODE_CONFIG);
686
  delay(25);
687 463eabf7 Wetmelon
688 55e2f6d1 Jan Hoffmann
  /* Note: Configuration will take place only when user writes to the last
689
     byte of each config data pair (ex. ACCEL_OFFSET_Z_MSB_ADDR, etc.).
690
     Therefore the last byte must be written whenever the user wants to
691
     changes the configuration. */
692
693
  /* A writeLen() would make this much cleaner */
694
  write8(ACCEL_OFFSET_X_LSB_ADDR, calibData[0]);
695
  write8(ACCEL_OFFSET_X_MSB_ADDR, calibData[1]);
696
  write8(ACCEL_OFFSET_Y_LSB_ADDR, calibData[2]);
697
  write8(ACCEL_OFFSET_Y_MSB_ADDR, calibData[3]);
698
  write8(ACCEL_OFFSET_Z_LSB_ADDR, calibData[4]);
699
  write8(ACCEL_OFFSET_Z_MSB_ADDR, calibData[5]);
700
701
  write8(MAG_OFFSET_X_LSB_ADDR, calibData[6]);
702
  write8(MAG_OFFSET_X_MSB_ADDR, calibData[7]);
703
  write8(MAG_OFFSET_Y_LSB_ADDR, calibData[8]);
704
  write8(MAG_OFFSET_Y_MSB_ADDR, calibData[9]);
705
  write8(MAG_OFFSET_Z_LSB_ADDR, calibData[10]);
706
  write8(MAG_OFFSET_Z_MSB_ADDR, calibData[11]);
707
708
  write8(GYRO_OFFSET_X_LSB_ADDR, calibData[12]);
709
  write8(GYRO_OFFSET_X_MSB_ADDR, calibData[13]);
710
  write8(GYRO_OFFSET_Y_LSB_ADDR, calibData[14]);
711
  write8(GYRO_OFFSET_Y_MSB_ADDR, calibData[15]);
712
  write8(GYRO_OFFSET_Z_LSB_ADDR, calibData[16]);
713
  write8(GYRO_OFFSET_Z_MSB_ADDR, calibData[17]);
714
715
  write8(ACCEL_RADIUS_LSB_ADDR, calibData[18]);
716
  write8(ACCEL_RADIUS_MSB_ADDR, calibData[19]);
717
718
  write8(MAG_RADIUS_LSB_ADDR, calibData[20]);
719
  write8(MAG_RADIUS_MSB_ADDR, calibData[21]);
720
721
  setMode(lastMode);
722 312a5b9e Wetmelon
}
723
724
/*!
725 5d8d461e Jan Hoffmann
 *  @brief  Writes to the sensor's offset registers from an offset struct
726
 *  @param  offsets_type
727 f7556b0d Jan Hoffmann
 *          accel_offset_x = acceleration offset x
728
 *          accel_offset_y = acceleration offset y
729
 *          accel_offset_z = acceleration offset z
730
 *
731
 *          mag_offset_x   = magnetometer offset x
732
 *          mag_offset_y   = magnetometer offset y
733
 *          mag_offset_z   = magnetometer offset z
734
 *
735
 *          gyro_offset_x  = gyroscrope offset x
736
 *          gyro_offset_y  = gyroscrope offset y
737
 *          gyro_offset_z  = gyroscrope offset z
738 75f03d2e Szymon Kaliski
 */
739 55e2f6d1 Jan Hoffmann
void Adafruit_BNO055::setSensorOffsets(
740
    const adafruit_bno055_offsets_t &offsets_type) {
741
  adafruit_bno055_opmode_t lastMode = _mode;
742
  setMode(OPERATION_MODE_CONFIG);
743
  delay(25);
744 312a5b9e Wetmelon
745 55e2f6d1 Jan Hoffmann
  /* Note: Configuration will take place only when user writes to the last
746
     byte of each config data pair (ex. ACCEL_OFFSET_Z_MSB_ADDR, etc.).
747
     Therefore the last byte must be written whenever the user wants to
748
     changes the configuration. */
749
750
  write8(ACCEL_OFFSET_X_LSB_ADDR, (offsets_type.accel_offset_x) & 0x0FF);
751
  write8(ACCEL_OFFSET_X_MSB_ADDR, (offsets_type.accel_offset_x >> 8) & 0x0FF);
752
  write8(ACCEL_OFFSET_Y_LSB_ADDR, (offsets_type.accel_offset_y) & 0x0FF);
753
  write8(ACCEL_OFFSET_Y_MSB_ADDR, (offsets_type.accel_offset_y >> 8) & 0x0FF);
754
  write8(ACCEL_OFFSET_Z_LSB_ADDR, (offsets_type.accel_offset_z) & 0x0FF);
755
  write8(ACCEL_OFFSET_Z_MSB_ADDR, (offsets_type.accel_offset_z >> 8) & 0x0FF);
756
757
  write8(MAG_OFFSET_X_LSB_ADDR, (offsets_type.mag_offset_x) & 0x0FF);
758
  write8(MAG_OFFSET_X_MSB_ADDR, (offsets_type.mag_offset_x >> 8) & 0x0FF);
759
  write8(MAG_OFFSET_Y_LSB_ADDR, (offsets_type.mag_offset_y) & 0x0FF);
760
  write8(MAG_OFFSET_Y_MSB_ADDR, (offsets_type.mag_offset_y >> 8) & 0x0FF);
761
  write8(MAG_OFFSET_Z_LSB_ADDR, (offsets_type.mag_offset_z) & 0x0FF);
762
  write8(MAG_OFFSET_Z_MSB_ADDR, (offsets_type.mag_offset_z >> 8) & 0x0FF);
763
764
  write8(GYRO_OFFSET_X_LSB_ADDR, (offsets_type.gyro_offset_x) & 0x0FF);
765
  write8(GYRO_OFFSET_X_MSB_ADDR, (offsets_type.gyro_offset_x >> 8) & 0x0FF);
766
  write8(GYRO_OFFSET_Y_LSB_ADDR, (offsets_type.gyro_offset_y) & 0x0FF);
767
  write8(GYRO_OFFSET_Y_MSB_ADDR, (offsets_type.gyro_offset_y >> 8) & 0x0FF);
768
  write8(GYRO_OFFSET_Z_LSB_ADDR, (offsets_type.gyro_offset_z) & 0x0FF);
769
  write8(GYRO_OFFSET_Z_MSB_ADDR, (offsets_type.gyro_offset_z >> 8) & 0x0FF);
770
771
  write8(ACCEL_RADIUS_LSB_ADDR, (offsets_type.accel_radius) & 0x0FF);
772
  write8(ACCEL_RADIUS_MSB_ADDR, (offsets_type.accel_radius >> 8) & 0x0FF);
773
774
  write8(MAG_RADIUS_LSB_ADDR, (offsets_type.mag_radius) & 0x0FF);
775
  write8(MAG_RADIUS_MSB_ADDR, (offsets_type.mag_radius >> 8) & 0x0FF);
776
777
  setMode(lastMode);
778 312a5b9e Wetmelon
}
779 4bc1c0c1 Kevin Townsend
780
/*!
781 5d8d461e Jan Hoffmann
 *  @brief  Checks of all cal status values are set to 3 (fully calibrated)
782
 *  @return status of calibration
783
 */
784 55e2f6d1 Jan Hoffmann
bool Adafruit_BNO055::isFullyCalibrated() {
785
  uint8_t system, gyro, accel, mag;
786
  getCalibration(&system, &gyro, &accel, &mag);
787 510d0f10 Jan Hoffmann
788
  switch (_mode) {
789
  case OPERATION_MODE_ACCONLY:
790
    return (accel == 3);
791
  case OPERATION_MODE_MAGONLY:
792
    return (mag == 3);
793
  case OPERATION_MODE_GYRONLY:
794
  case OPERATION_MODE_M4G: /* No magnetometer calibration required. */
795
    return (gyro == 3);
796
  case OPERATION_MODE_ACCMAG:
797
  case OPERATION_MODE_COMPASS:
798
    return (accel == 3 && mag == 3);
799
  case OPERATION_MODE_ACCGYRO:
800
  case OPERATION_MODE_IMUPLUS:
801
    return (accel == 3 && gyro == 3);
802
  case OPERATION_MODE_MAGGYRO:
803
    return (mag == 3 && gyro == 3);
804
  default:
805
    return (system == 3 && gyro == 3 && accel == 3 && mag == 3);
806
  }
807 312a5b9e Wetmelon
}
808
809 4bc1c0c1 Kevin Townsend
/*!
810 a7b2a1c9 Jan Hoffmann
 *  @brief  Enter Suspend mode (i.e., sleep)
811
 */
812
void Adafruit_BNO055::enterSuspendMode() {
813
  adafruit_bno055_opmode_t modeback = _mode;
814
815
  /* Switch to config mode (just in case since this is the default) */
816
  setMode(OPERATION_MODE_CONFIG);
817
  delay(25);
818
  write8(BNO055_PWR_MODE_ADDR, 0x02);
819
  /* Set the requested operating mode (see section 3.3) */
820
  setMode(modeback);
821
  delay(20);
822
}
823
824
/*!
825
 *  @brief  Enter Normal mode (i.e., wake)
826
 */
827
void Adafruit_BNO055::enterNormalMode() {
828
  adafruit_bno055_opmode_t modeback = _mode;
829
830
  /* Switch to config mode (just in case since this is the default) */
831
  setMode(OPERATION_MODE_CONFIG);
832
  delay(25);
833
  write8(BNO055_PWR_MODE_ADDR, 0x00);
834
  /* Set the requested operating mode (see section 3.3) */
835
  setMode(modeback);
836
  delay(20);
837
}
838
839
/*!
840 5d8d461e Jan Hoffmann
 *  @brief  Writes an 8 bit value over I2C
841
 */
842 55e2f6d1 Jan Hoffmann
bool Adafruit_BNO055::write8(adafruit_bno055_reg_t reg, byte value) {
843 f7556b0d Jan Hoffmann
  _wire->beginTransmission(_address);
844 55e2f6d1 Jan Hoffmann
#if ARDUINO >= 100
845 f7556b0d Jan Hoffmann
  _wire->write((uint8_t)reg);
846
  _wire->write((uint8_t)value);
847 55e2f6d1 Jan Hoffmann
#else
848 f7556b0d Jan Hoffmann
  _wire->send(reg);
849
  _wire->send(value);
850 55e2f6d1 Jan Hoffmann
#endif
851 f7556b0d Jan Hoffmann
  _wire->endTransmission();
852 463eabf7 Wetmelon
853
  /* ToDo: Check for error! */
854
  return true;
855 4bc1c0c1 Kevin Townsend
}
856
857
/*!
858 5d8d461e Jan Hoffmann
 *  @brief  Reads an 8 bit value over I2C
859
 */
860 55e2f6d1 Jan Hoffmann
byte Adafruit_BNO055::read8(adafruit_bno055_reg_t reg) {
861 463eabf7 Wetmelon
  byte value = 0;
862
863 f7556b0d Jan Hoffmann
  _wire->beginTransmission(_address);
864 55e2f6d1 Jan Hoffmann
#if ARDUINO >= 100
865 f7556b0d Jan Hoffmann
  _wire->write((uint8_t)reg);
866 55e2f6d1 Jan Hoffmann
#else
867 f7556b0d Jan Hoffmann
  _wire->send(reg);
868 55e2f6d1 Jan Hoffmann
#endif
869 f7556b0d Jan Hoffmann
  _wire->endTransmission();
870
  _wire->requestFrom(_address, (byte)1);
871 55e2f6d1 Jan Hoffmann
#if ARDUINO >= 100
872 f7556b0d Jan Hoffmann
  value = _wire->read();
873 55e2f6d1 Jan Hoffmann
#else
874 f7556b0d Jan Hoffmann
  value = _wire->receive();
875 55e2f6d1 Jan Hoffmann
#endif
876 463eabf7 Wetmelon
877
  return value;
878 4bc1c0c1 Kevin Townsend
}
879
880
/*!
881 5d8d461e Jan Hoffmann
 *  @brief  Reads the specified number of bytes over I2C
882
 */
883 55e2f6d1 Jan Hoffmann
bool Adafruit_BNO055::readLen(adafruit_bno055_reg_t reg, byte *buffer,
884
                              uint8_t len) {
885 f7556b0d Jan Hoffmann
  _wire->beginTransmission(_address);
886 55e2f6d1 Jan Hoffmann
#if ARDUINO >= 100
887 f7556b0d Jan Hoffmann
  _wire->write((uint8_t)reg);
888 55e2f6d1 Jan Hoffmann
#else
889 f7556b0d Jan Hoffmann
  _wire->send(reg);
890 55e2f6d1 Jan Hoffmann
#endif
891 f7556b0d Jan Hoffmann
  _wire->endTransmission();
892
  _wire->requestFrom(_address, (byte)len);
893 463eabf7 Wetmelon
894 55e2f6d1 Jan Hoffmann
  for (uint8_t i = 0; i < len; i++) {
895
#if ARDUINO >= 100
896 f7556b0d Jan Hoffmann
    buffer[i] = _wire->read();
897 55e2f6d1 Jan Hoffmann
#else
898 f7556b0d Jan Hoffmann
    buffer[i] = _wire->receive();
899 55e2f6d1 Jan Hoffmann
#endif
900 463eabf7 Wetmelon
  }
901
902 5e9f001d Jan
  /* ToDo: Check for errors! */
903
  return true;
904
}
905
906 60d68bed Jan
/*
907
 * @brief Explicit reset for the chip
908
 */
909 5e9f001d Jan
void Adafruit_BNO055::reset() {
910 60d68bed Jan
  _wire->beginTransmission(_address);
911
  setMode(OPERATION_MODE_CONFIG);
912
913
  /* Reset */
914
  write8(BNO055_SYS_TRIGGER_ADDR, 0x20);
915
  while (read8(BNO055_CHIP_ID_ADDR) != BNO055_ID) {
916
    delay(10);
917
  }
918
  delay(50);
919
}