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