Revision c4f272e1

View differences:

Adafruit_BNO055.cpp
61 61
  uint8_t id = read8(BNO055_CHIP_ID_ADDR);
62 62
  if(id != BNO055_ID)
63 63
  {
64
    return false;
64
    delay(1000); // hold on for boot
65
    if(id != BNO055_ID) {
66
      return false;  // still not? ok bail
67
    }
65 68
  }
66 69

  
67 70
  /* Switch to config mode (just in case since this is the default) */
68 71
  setMode(OPERATION_MODE_CONFIG);
72

  
73
  /* Reset */
74
  write8(BNO055_SYS_TRIGGER_ADDR, 0x20); //reset the sensor
75
  while (read8(BNO055_CHIP_ID_ADDR) != BNO055_ID) //wait for boot
76
    delay(10);
69 77
  
78
  delay(50);
79
 
70 80
  /* Set to normal power mode */
71 81
  write8(BNO055_PWR_MODE_ADDR, POWER_MODE_NORMAL);
72 82
  delay(10);
83

  
84
  write8(BNO055_PAGE_ID_ADDR, 0);
73 85
  
74 86
  /* Set the output units */
75 87
  uint8_t unitsel = (0 << 7) | /* Orientation = Android */
......
79 91
                    (0 << 0);  /* Accelerometer = m/s^2 */
80 92
  write8(BNO055_UNIT_SEL_ADDR, unitsel);
81 93

  
94
  write8(BNO055_SYS_TRIGGER_ADDR, 0x0);
95
  delay(10);
82 96
  /* Set the requested operating mode (see section 3.3) */
83
  write8(BNO055_OPR_MODE_ADDR, mode);
97
  setMode(mode);
84 98
  delay(20);
85 99

  
86 100
  return true;
......
94 108
void Adafruit_BNO055::setMode(adafruit_bno055_opmode_t mode)
95 109
{
96 110
  _mode = mode;
97
  
111
  //Serial.print("Mode: 0x"); Serial.println(mode, HEX);
98 112
  write8(BNO055_OPR_MODE_ADDR, _mode);
99 113
  delay(30);
100 114
}
101 115

  
102 116
/**************************************************************************/
103 117
/*!
118
    @brief  Use the external 32.768KHz crystal
119
*/
120
/**************************************************************************/
121
void Adafruit_BNO055::setExtCrystalUse(boolean usextal)
122
{
123
  adafruit_bno055_opmode_t modeback = _mode;
124

  
125
  /* Switch to config mode (just in case since this is the default) */
126
  setMode(OPERATION_MODE_CONFIG);
127
  delay(25);
128
  write8(BNO055_PAGE_ID_ADDR, 0);
129
  if (usextal) {
130
    write8(BNO055_SYS_TRIGGER_ADDR, 0x80);
131
  } else {
132
    write8(BNO055_SYS_TRIGGER_ADDR, 0x00);
133
  }
134
  delay(10);
135
  /* Set the requested operating mode (see section 3.3) */
136
  setMode(modeback);
137
  delay(20);
138
}
139

  
140

  
141
/**************************************************************************/
142
/*!
104 143
    @brief  Gets the latest system status info
105 144
*/
106 145
/**************************************************************************/
107 146
void Adafruit_BNO055::getSystemStatus(uint8_t *system_status, uint8_t *self_test_result, uint8_t *system_error)
108 147
{
148
  adafruit_bno055_opmode_t backupmode = _mode;
149

  
150
  setMode(OPERATION_MODE_CONFIG);
151
  delay(20);
152
  write8(BNO055_PAGE_ID_ADDR, 0);
153

  
109 154
  write8(BNO055_SYS_TRIGGER_ADDR, read8(BNO055_SYS_TRIGGER_ADDR) | 0x1);
110
  delay(10);
155
  delay(1000);
111 156
  /* Read the system status register */
112 157
  if (system_status != 0)
113 158
    *system_status    = read8(BNO055_SYS_STAT_ADDR);
......
115 160
    *self_test_result = read8(BNO055_SELFTEST_RESULT_ADDR);
116 161
  if (system_error != 0)
117 162
    *system_error     = read8(BNO055_SYS_ERR_ADDR);
163

  
164
  setMode(backupmode);
165
  delay(20);
118 166
}
119 167

  
120 168
/**************************************************************************/
......
316 364
}
317 365

  
318 366
/**************************************************************************/
319
/*
320
    Prints a float or double with the specified number of decimal places.
321

  
322
    'precision' should be 1 followed by a zero for every decimal place
323
    desired, so '100' will produce two decimal places:
324

  
325
    print_double(3.1415, 100); // Output = 3.14
326
*/
327
/**************************************************************************/
328
void Adafruit_BNO055::printDouble(double val, unsigned int precision)
329
{
330
  /* Print the integer portion */
331
  Serial.print (int(val));
332
  Serial.print(".");
333
  
334
  /* Print the fraction portion */
335
  unsigned int frac;
336
  if(val >= 0)
337
  {
338
    frac = (val - int(val)) * precision;
339
  }
340
  else
341
  {
342
    frac = (int(val)- val ) * precision;
343
  }
344
  Serial.println(frac,DEC) ;
345
}
346

  
347
/**************************************************************************/
348 367
/*!
349 368
    @brief  Provides the sensor_t data for this sensor
350 369
*/
Adafruit_BNO055.h
237 237
    void  setMode             ( adafruit_bno055_opmode_t mode );
238 238
    void  getRevInfo          ( adafruit_bno055_rev_info_t* );
239 239
    void  displayRevInfo      ( void );
240
    //    void  getSystemStatus     ( adafruit_bno055_system_status_t* );
240
    void  setExtCrystalUse    ( boolean usextal );
241 241
    void  getSystemStatus     ( uint8_t *system_status, 
242 242
				uint8_t *self_test_result, 
243 243
				uint8_t *system_error);
244 244
    void  displaySystemStatus ( void );
245
    void  printDouble         ( double val, unsigned int precision );
246 245
    
247 246
    imu::Vector<3>  getVector ( adafruit_vector_type_t vector_type );
248 247
    imu::Quaternion getQuat   ( void );
examples/rawdata/rawdata.ino
18 18
*/
19 19

  
20 20
/* Set the delay between fresh samples */
21
#define BNO055_SAMPLERATE_DELAY_MS (500)
21
#define BNO055_SAMPLERATE_DELAY_MS (100)
22 22
   
23 23
Adafruit_BNO055 bno = Adafruit_BNO055();
24 24

  
......
52 52
  Serial.print(temp);
53 53
  Serial.println(" C");
54 54
  Serial.println("");
55
  
56
  bno.setExtCrystalUse(true);
55 57
}
56 58

  
57 59
/**************************************************************************/
......
73 75
  
74 76
  /* Display the floating point data */
75 77
  Serial.print("X: ");
76
  bno.printDouble(euler.x(), 1000);
77
  Serial.print("Y: ");
78
  bno.printDouble(euler.y(), 1000);
79
  Serial.print("Z: ");
80
  bno.printDouble(euler.z(), 1000);
78
  Serial.print(euler.x());
79
  Serial.print(" Y: ");
80
  Serial.print(euler.y());
81
  Serial.print(" Z: ");
82
  Serial.print(euler.z());
81 83
  Serial.println("");
82 84

  
83 85
  /*
84 86
  // Quaternion data
85 87
  imu::Quaternion quat = bno.getQuat();
86 88
  Serial.print("qW: ");
87
  bno.printDouble(quat.w(), 1000);
88
  Serial.print("qX: ");
89
  bno.printDouble(quat.y(), 1000);
90
  Serial.print("qY: ");
91
  bno.printDouble(quat.x(), 1000);
92
  Serial.print("qZ: ");
93
  bno.printDouble(quat.z(), 1000);
89
  Serial.print(quat.w(), 4);
90
  Serial.print(" qX: ");
91
  Serial.print(quat.y(), 4);
92
  Serial.print(" qY: ");
93
  Serial.print(quat.x(), 4);
94
  Serial.print(" qZ: ");
95
  Serial.print(quat.z(), 4);
94 96
  Serial.println("");
95 97
  */
96 98
  
97 99
  delay(BNO055_SAMPLERATE_DELAY_MS);
98
}
100
}
examples/sensorapi/sensorapi.ino
19 19
   ===========
20 20
   Connect SCL to analog 5
21 21
   Connect SDA to analog 4
22
   Connect VDD to 3.3V DC
22
   Connect VDD to 3-5V DC
23 23
   Connect GROUND to common ground
24 24
    
25 25
   History
......
28 28
*/
29 29

  
30 30
/* Set the delay between fresh samples */
31
#define BNO055_SAMPLERATE_DELAY_MS (500)
31
#define BNO055_SAMPLERATE_DELAY_MS (100)
32 32
   
33 33
Adafruit_BNO055 bno = Adafruit_BNO055(55);
34 34

  
......
84 84
  /* Display chip revision details (optional) */
85 85
  // bno.displayRevInfo();
86 86
  // Serial.println("");
87
  
88
  bno.setExtCrystalUse(true);
87 89
}
88 90

  
89 91
/**************************************************************************/
......
100 102
  
101 103
  /* Display the floating point data */
102 104
  Serial.print("X: ");
103
  bno.printDouble(event.orientation.x, 1000);
104
  Serial.print("Y: ");
105
  bno.printDouble(event.orientation.y, 1000);
106
  Serial.print("Z: ");
107
  bno.printDouble(event.orientation.z, 1000);
105
  Serial.print(event.orientation.x, 4);
106
  Serial.print("\tY: ");
107
  Serial.print(event.orientation.y, 4);
108
  Serial.print("\tZ: ");
109
  Serial.print(event.orientation.z, 4);
108 110
  Serial.println("");
109 111
  
110 112
  delay(BNO055_SAMPLERATE_DELAY_MS);

Also available in: Unified diff