adafruit_bno055 / Adafruit_BNO055.h @ c4f272e1
History | View | Annotate | Download (10.286 KB)
1 |
/***************************************************************************
|
---|---|
2 |
This is a library for the BNO055 orientation sensor
|
3 |
|
4 |
Designed specifically to work with the Adafruit BNO055 Breakout.
|
5 |
|
6 |
Pick one up today in the adafruit shop!
|
7 |
------> http://www.adafruit.com/products
|
8 |
|
9 |
These sensors use I2C to communicate, 2 pins are required to interface.
|
10 |
|
11 |
Adafruit invests time and resources providing this open source code,
|
12 |
please support Adafruit andopen-source hardware by purchasing products
|
13 |
from Adafruit!
|
14 |
|
15 |
Written by KTOWN for Adafruit Industries.
|
16 |
|
17 |
MIT license, all text above must be included in any redistribution
|
18 |
***************************************************************************/
|
19 |
|
20 |
#ifndef __ADAFRUIT_BNO055_H__
|
21 |
#define __ADAFRUIT_BNO055_H__
|
22 |
|
23 |
#if (ARDUINO >= 100) |
24 |
#include "Arduino.h" |
25 |
#else
|
26 |
#include "WProgram.h" |
27 |
#endif
|
28 |
#include "Wire.h" |
29 |
|
30 |
#include <Adafruit_Sensor.h> |
31 |
#include <utility/imumaths.h> |
32 |
|
33 |
#define BNO055_ADDRESS_A (0x28) |
34 |
#define BNO055_ADDRESS_B (0x29) |
35 |
#define BNO055_ID (0xA0) |
36 |
|
37 |
class Adafruit_BNO055 /* : public Adafruit_Sensor */
|
38 |
{ |
39 |
public:
|
40 |
typedef enum |
41 |
{ |
42 |
/* Page id register definition */
|
43 |
BNO055_PAGE_ID_ADDR = 0X07,
|
44 |
|
45 |
/* PAGE0 REGISTER DEFINITION START*/
|
46 |
BNO055_CHIP_ID_ADDR = 0x00,
|
47 |
BNO055_ACCEL_REV_ID_ADDR = 0x01,
|
48 |
BNO055_MAG_REV_ID_ADDR = 0x02,
|
49 |
BNO055_GYRO_REV_ID_ADDR = 0x03,
|
50 |
BNO055_SW_REV_ID_LSB_ADDR = 0x04,
|
51 |
BNO055_SW_REV_ID_MSB_ADDR = 0x05,
|
52 |
BNO055_BL_REV_ID_ADDR = 0X06,
|
53 |
|
54 |
/* Accel data register */
|
55 |
BNO055_ACCEL_DATA_X_LSB_ADDR = 0X08,
|
56 |
BNO055_ACCEL_DATA_X_MSB_ADDR = 0X09,
|
57 |
BNO055_ACCEL_DATA_Y_LSB_ADDR = 0X0A,
|
58 |
BNO055_ACCEL_DATA_Y_MSB_ADDR = 0X0B,
|
59 |
BNO055_ACCEL_DATA_Z_LSB_ADDR = 0X0C,
|
60 |
BNO055_ACCEL_DATA_Z_MSB_ADDR = 0X0D,
|
61 |
|
62 |
/* Mag data register */
|
63 |
BNO055_MAG_DATA_X_LSB_ADDR = 0X0E,
|
64 |
BNO055_MAG_DATA_X_MSB_ADDR = 0X0F,
|
65 |
BNO055_MAG_DATA_Y_LSB_ADDR = 0X10,
|
66 |
BNO055_MAG_DATA_Y_MSB_ADDR = 0X11,
|
67 |
BNO055_MAG_DATA_Z_LSB_ADDR = 0X12,
|
68 |
BNO055_MAG_DATA_Z_MSB_ADDR = 0X13,
|
69 |
|
70 |
/* Gyro data registers */
|
71 |
BNO055_GYRO_DATA_X_LSB_ADDR = 0X14,
|
72 |
BNO055_GYRO_DATA_X_MSB_ADDR = 0X15,
|
73 |
BNO055_GYRO_DATA_Y_LSB_ADDR = 0X16,
|
74 |
BNO055_GYRO_DATA_Y_MSB_ADDR = 0X17,
|
75 |
BNO055_GYRO_DATA_Z_LSB_ADDR = 0X18,
|
76 |
BNO055_GYRO_DATA_Z_MSB_ADDR = 0X19,
|
77 |
|
78 |
/* Euler data registers */
|
79 |
BNO055_EULER_H_LSB_ADDR = 0X1A,
|
80 |
BNO055_EULER_H_MSB_ADDR = 0X1B,
|
81 |
BNO055_EULER_R_LSB_ADDR = 0X1C,
|
82 |
BNO055_EULER_R_MSB_ADDR = 0X1D,
|
83 |
BNO055_EULER_P_LSB_ADDR = 0X1E,
|
84 |
BNO055_EULER_P_MSB_ADDR = 0X1F,
|
85 |
|
86 |
/* Quaternion data registers */
|
87 |
BNO055_QUATERNION_DATA_W_LSB_ADDR = 0X20,
|
88 |
BNO055_QUATERNION_DATA_W_MSB_ADDR = 0X21,
|
89 |
BNO055_QUATERNION_DATA_X_LSB_ADDR = 0X22,
|
90 |
BNO055_QUATERNION_DATA_X_MSB_ADDR = 0X23,
|
91 |
BNO055_QUATERNION_DATA_Y_LSB_ADDR = 0X24,
|
92 |
BNO055_QUATERNION_DATA_Y_MSB_ADDR = 0X25,
|
93 |
BNO055_QUATERNION_DATA_Z_LSB_ADDR = 0X26,
|
94 |
BNO055_QUATERNION_DATA_Z_MSB_ADDR = 0X27,
|
95 |
|
96 |
/* Linear acceleration data registers */
|
97 |
BNO055_LINEAR_ACCEL_DATA_X_LSB_ADDR = 0X28,
|
98 |
BNO055_LINEAR_ACCEL_DATA_X_MSB_ADDR = 0X29,
|
99 |
BNO055_LINEAR_ACCEL_DATA_Y_LSB_ADDR = 0X2A,
|
100 |
BNO055_LINEAR_ACCEL_DATA_Y_MSB_ADDR = 0X2B,
|
101 |
BNO055_LINEAR_ACCEL_DATA_Z_LSB_ADDR = 0X2C,
|
102 |
BNO055_LINEAR_ACCEL_DATA_Z_MSB_ADDR = 0X2D,
|
103 |
|
104 |
/* Gravity data registers */
|
105 |
BNO055_GRAVITY_DATA_X_LSB_ADDR = 0X2E,
|
106 |
BNO055_GRAVITY_DATA_X_MSB_ADDR = 0X2F,
|
107 |
BNO055_GRAVITY_DATA_Y_LSB_ADDR = 0X30,
|
108 |
BNO055_GRAVITY_DATA_Y_MSB_ADDR = 0X31,
|
109 |
BNO055_GRAVITY_DATA_Z_LSB_ADDR = 0X32,
|
110 |
BNO055_GRAVITY_DATA_Z_MSB_ADDR = 0X33,
|
111 |
|
112 |
/* Temperature data register */
|
113 |
BNO055_TEMP_ADDR = 0X34,
|
114 |
|
115 |
/* Status registers */
|
116 |
BNO055_CALIB_STAT_ADDR = 0X35,
|
117 |
BNO055_SELFTEST_RESULT_ADDR = 0X36,
|
118 |
BNO055_INTR_STAT_ADDR = 0X37,
|
119 |
|
120 |
BNO055_SYS_CLK_STAT_ADDR = 0X38,
|
121 |
BNO055_SYS_STAT_ADDR = 0X39,
|
122 |
BNO055_SYS_ERR_ADDR = 0X3A,
|
123 |
|
124 |
/* Unit selection register */
|
125 |
BNO055_UNIT_SEL_ADDR = 0X3B,
|
126 |
BNO055_DATA_SELECT_ADDR = 0X3C,
|
127 |
|
128 |
/* Mode registers */
|
129 |
BNO055_OPR_MODE_ADDR = 0X3D,
|
130 |
BNO055_PWR_MODE_ADDR = 0X3E,
|
131 |
|
132 |
BNO055_SYS_TRIGGER_ADDR = 0X3F,
|
133 |
BNO055_TEMP_SOURCE_ADDR = 0X40,
|
134 |
|
135 |
/* Axis remap registers */
|
136 |
BNO055_AXIS_MAP_CONFIG_ADDR = 0X41,
|
137 |
BNO055_AXIS_MAP_SIGN_ADDR = 0X42,
|
138 |
|
139 |
/* SIC registers */
|
140 |
BNO055_SIC_MATRIX_0_LSB_ADDR = 0X43,
|
141 |
BNO055_SIC_MATRIX_0_MSB_ADDR = 0X44,
|
142 |
BNO055_SIC_MATRIX_1_LSB_ADDR = 0X45,
|
143 |
BNO055_SIC_MATRIX_1_MSB_ADDR = 0X46,
|
144 |
BNO055_SIC_MATRIX_2_LSB_ADDR = 0X47,
|
145 |
BNO055_SIC_MATRIX_2_MSB_ADDR = 0X48,
|
146 |
BNO055_SIC_MATRIX_3_LSB_ADDR = 0X49,
|
147 |
BNO055_SIC_MATRIX_3_MSB_ADDR = 0X4A,
|
148 |
BNO055_SIC_MATRIX_4_LSB_ADDR = 0X4B,
|
149 |
BNO055_SIC_MATRIX_4_MSB_ADDR = 0X4C,
|
150 |
BNO055_SIC_MATRIX_5_LSB_ADDR = 0X4D,
|
151 |
BNO055_SIC_MATRIX_5_MSB_ADDR = 0X4E,
|
152 |
BNO055_SIC_MATRIX_6_LSB_ADDR = 0X4F,
|
153 |
BNO055_SIC_MATRIX_6_MSB_ADDR = 0X50,
|
154 |
BNO055_SIC_MATRIX_7_LSB_ADDR = 0X51,
|
155 |
BNO055_SIC_MATRIX_7_MSB_ADDR = 0X52,
|
156 |
BNO055_SIC_MATRIX_8_LSB_ADDR = 0X53,
|
157 |
BNO055_SIC_MATRIX_8_MSB_ADDR = 0X54,
|
158 |
|
159 |
/* Accelerometer Offset registers */
|
160 |
ACCEL_OFFSET_X_LSB_ADDR = 0X55,
|
161 |
ACCEL_OFFSET_X_MSB_ADDR = 0X56,
|
162 |
ACCEL_OFFSET_Y_LSB_ADDR = 0X57,
|
163 |
ACCEL_OFFSET_Y_MSB_ADDR = 0X58,
|
164 |
ACCEL_OFFSET_Z_LSB_ADDR = 0X59,
|
165 |
ACCEL_OFFSET_Z_MSB_ADDR = 0X5A,
|
166 |
|
167 |
/* Magnetometer Offset registers */
|
168 |
MAG_OFFSET_X_LSB_ADDR = 0X5B,
|
169 |
MAG_OFFSET_X_MSB_ADDR = 0X5C,
|
170 |
MAG_OFFSET_Y_LSB_ADDR = 0X5D,
|
171 |
MAG_OFFSET_Y_MSB_ADDR = 0X5E,
|
172 |
MAG_OFFSET_Z_LSB_ADDR = 0X5F,
|
173 |
MAG_OFFSET_Z_MSB_ADDR = 0X60,
|
174 |
|
175 |
/* Gyroscope Offset register s*/
|
176 |
GYRO_OFFSET_X_LSB_ADDR = 0X61,
|
177 |
GYRO_OFFSET_X_MSB_ADDR = 0X62,
|
178 |
GYRO_OFFSET_Y_LSB_ADDR = 0X63,
|
179 |
GYRO_OFFSET_Y_MSB_ADDR = 0X64,
|
180 |
GYRO_OFFSET_Z_LSB_ADDR = 0X65,
|
181 |
GYRO_OFFSET_Z_MSB_ADDR = 0X66,
|
182 |
|
183 |
/* Radius registers */
|
184 |
ACCEL_RADIUS_LSB_ADDR = 0X67,
|
185 |
ACCEL_RADIUS_MSB_ADDR = 0X68,
|
186 |
MAG_RADIUS_LSB_ADDR = 0X69,
|
187 |
MAG_RADIUS_MSB_ADDR = 0X6A
|
188 |
} adafruit_bno055_reg_t; |
189 |
|
190 |
typedef enum |
191 |
{ |
192 |
POWER_MODE_NORMAL = 0X00,
|
193 |
POWER_MODE_LOWPOWER = 0X01,
|
194 |
POWER_MODE_SUSPEND = 0X02
|
195 |
} adafruit_bno055_powermode_t; |
196 |
|
197 |
typedef enum |
198 |
{ |
199 |
/* Operation mode settings*/
|
200 |
OPERATION_MODE_CONFIG = 0X00,
|
201 |
OPERATION_MODE_ACCONLY = 0X01,
|
202 |
OPERATION_MODE_MAGONLY = 0X02,
|
203 |
OPERATION_MODE_GYRONLY = 0X03,
|
204 |
OPERATION_MODE_ACCMAG = 0X04,
|
205 |
OPERATION_MODE_ACCGYRO = 0X05,
|
206 |
OPERATION_MODE_MAGGYRO = 0X06,
|
207 |
OPERATION_MODE_AMG = 0X07,
|
208 |
OPERATION_MODE_IMUPLUS = 0X08,
|
209 |
OPERATION_MODE_COMPASS = 0X09,
|
210 |
OPERATION_MODE_M4G = 0X0A,
|
211 |
OPERATION_MODE_NDOF_FMC_OFF = 0X0B,
|
212 |
OPERATION_MODE_NDOF = 0X0C
|
213 |
} adafruit_bno055_opmode_t; |
214 |
|
215 |
typedef struct |
216 |
{ |
217 |
uint8_t accel_rev; |
218 |
uint8_t mag_rev; |
219 |
uint8_t gyro_rev; |
220 |
uint16_t sw_rev; |
221 |
uint8_t bl_rev; |
222 |
} adafruit_bno055_rev_info_t; |
223 |
|
224 |
typedef enum |
225 |
{ |
226 |
VECTOR_ACCELEROMETER = BNO055_ACCEL_DATA_X_LSB_ADDR, |
227 |
VECTOR_MAGNETOMETER = BNO055_MAG_DATA_X_LSB_ADDR, |
228 |
VECTOR_GYROSCOPE = BNO055_GYRO_DATA_X_LSB_ADDR, |
229 |
VECTOR_EULER = BNO055_EULER_H_LSB_ADDR, |
230 |
VECTOR_LINEARACCEL = BNO055_LINEAR_ACCEL_DATA_X_LSB_ADDR, |
231 |
VECTOR_GRAVITY = BNO055_GRAVITY_DATA_X_LSB_ADDR |
232 |
} adafruit_vector_type_t; |
233 |
|
234 |
Adafruit_BNO055 ( int32_t sensorID = -1, uint8_t address = BNO055_ADDRESS_A );
|
235 |
|
236 |
bool begin ( adafruit_bno055_opmode_t mode = OPERATION_MODE_NDOF );
|
237 |
void setMode ( adafruit_bno055_opmode_t mode );
|
238 |
void getRevInfo ( adafruit_bno055_rev_info_t* );
|
239 |
void displayRevInfo ( void ); |
240 |
void setExtCrystalUse ( boolean usextal );
|
241 |
void getSystemStatus ( uint8_t *system_status,
|
242 |
uint8_t *self_test_result, |
243 |
uint8_t *system_error); |
244 |
void displaySystemStatus ( void ); |
245 |
|
246 |
imu::Vector<3> getVector ( adafruit_vector_type_t vector_type );
|
247 |
imu::Quaternion getQuat ( void );
|
248 |
int8_t getTemp ( void );
|
249 |
|
250 |
/* Adafruit_Sensor implementation */
|
251 |
bool getEvent ( sensors_event_t* );
|
252 |
void getSensor ( sensor_t* );
|
253 |
|
254 |
private:
|
255 |
byte read8 ( adafruit_bno055_reg_t ); |
256 |
bool readLen ( adafruit_bno055_reg_t, byte* buffer, uint8_t len );
|
257 |
bool write8 ( adafruit_bno055_reg_t, byte value );
|
258 |
|
259 |
uint8_t _address; |
260 |
int32_t _sensorID; |
261 |
adafruit_bno055_opmode_t _mode; |
262 |
}; |
263 |
|
264 |
#endif
|