Revision c4f272e1 Adafruit_BNO055.cpp
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 |
*/ |
Also available in: Unified diff