BNO055 Intelligent 9-axis absolute orientation sensor by Bosch Sensortec. It includes ACC, MAG and GYRO sensors and Cortex-M0+ processor.
Dependents: BNO055_test BNO055-ELEC3810 1BNO055 DEMO3 ... more
Please see follows.
/users/kenjiArai/notebook/bno055---orientation-sensor/#
Diff: BNO055.h
- Revision:
- 7:b48d96169302
- Parent:
- 6:07d01bf36ad0
--- a/BNO055.h Wed Aug 23 09:44:43 2017 +0000 +++ b/BNO055.h Wed Aug 05 05:28:13 2020 +0000 @@ -3,21 +3,25 @@ * BNO055 Intelligent 9-axis absolute orientation sensor * by Bosch Sensortec * - * Copyright (c) 2015,'17 Kenji Arai / JH1PJL - * http://www.page.sannet.ne.jp/kenjia/index.html - * http://mbed.org/users/kenjiArai/ + * Copyright (c) 2015,'17,'20 Kenji Arai / JH1PJL + * http://www7b.biglobe.ne.jp/~kenjia/ + * https://os.mbed.com/users/kenjiArai/ * Created: March 30th, 2015 - * Revised: August 23rd, 2017 + * Revised: August 5th, 2020 */ /* - *---------------- REFERENCE ---------------------------------------------------------------------- + *---------------- REFERENCE --------------------------------------------------- * Original Information - * https://www.bosch-sensortec.com/en/homepage/products_3/sensor_hubs/iot_solutions/bno055_1/bno055_4 - * Intelligent 9-axis absolute orientation sensor / Data Sheet BST_BNO055_DS000_12 Nov. 2014 rev.1.2 + * https://www.bosch-sensortec.com/en/homepage/ + * products_3/sensor_hubs/iot_solutions/bno055_1/bno055_4 + * Intelligent 9-axis absolute orientation sensor + * / Data Sheet BST_BNO055_DS000_12 Nov. 2014 rev.1.2 * Sample software https://github.com/BoschSensortec/BNO055_driver * Sensor board - * https://www.rutronik24.com/product/bosch+se/bno055+shuttle+board+mems/6431291.html - * http://microcontrollershop.com/product_info.php?products_id=7140&osCsid=10645k86db2crld4tfi0vol5g5 + * https://www.rutronik24.com/product/bosch+se/ + * bno055+shuttle+board+mems/6431291.html + * http://microcontrollershop.com/product_info.php + * ?products_id=7140&osCsid=10645k86db2crld4tfi0vol5g5 */ #ifndef BNO055_H @@ -56,7 +60,7 @@ #define I_AM_BNO055_MAG 0x32 // MAG ID #define I_AM_BNO055_GYR 0x0f // GYR ID -////////////// DATA TYPE DEFINITION /////////////////////// +////////////// DATA TYPE DEFINITION //////////////////////////////////////////// typedef struct { uint8_t chip_id; uint8_t acc_id; @@ -113,19 +117,22 @@ * BNO055_EULER_TypeDef euler_angles; * * int main() { - * pc.printf("Bosch Sensortec BNO055 test program on " __DATE__ "/" __TIME__ "\r\n"); * if (imu.chip_ready() == 0){ - * pc.printf("Bosch BNO055 is NOT avirable!!\r\n"); + * printf("Bosch BNO055 is NOT avirable!!\r\n"); * } * imu.read_id_inf(&bno055_id_inf); - * pc.printf("CHIP:0x%02x, ACC:0x%02x, MAG:0x%02x, GYR:0x%02x, , SW:0x%04x, , BL:0x%02x\r\n", - * bno055_id_inf.chip_id, bno055_id_inf.acc_id, bno055_id_inf.mag_id, - * bno055_id_inf.gyr_id, bno055_id_inf.sw_rev_id, bno055_id_inf.bootldr_rev_id); + * printf( + * "CHIP:0x%02x, ACC:0x%02x, MAG:0x%02x, GYR:0x%02x,", + * bno055_id_inf.chip_id, bno055_id_inf.acc_id, + * bno055_id_inf.mag_id, bno055_id_inf.gyr_id); + * printf(" , SW:0x%04x, , BL:0x%02x\r\n", + * bno055_id_inf.sw_rev_id, bno055_id_inf.bootldr_rev_id) * while(1) { * imu.get_Euler_Angles(&euler_angles); - * pc.printf("Heading:%+6.1f [deg], Roll:%+6.1f [deg], Pich:%+6.1f [deg]\r\n", - * euler_angles.h, euler_angles.r, euler_angles.p); - * wait(0.5); + * printf( + * "Heading:%+6.1f [deg], Roll:%+6.1f [deg], Pich:%+6.1f [deg]\r\n", + * euler_angles.h, euler_angles.r, euler_angles.p); + * ThisThread::sleep_for(500ms); * } * } * @endcode @@ -138,7 +145,10 @@ * @param data SDA and SCL pins * @param device address */ - BNO055(PinName p_sda, PinName p_scl, PinName p_reset, uint8_t addr, uint8_t mode); + BNO055( + PinName p_sda, PinName p_scl, + PinName p_reset, uint8_t addr, uint8_t mode + ); /** Configure data pin * @param data SDA and SCL pins @@ -281,13 +291,13 @@ }; -//--------------------------------------------------------- -//----- Register's definition ----------------------------- -//--------------------------------------------------------- +//------------------------------------------------------------------------------ +//----- Register's definition -------------------------------------------------- +//------------------------------------------------------------------------------ // Page id register definition #define BNO055_PAGE_ID 0x07 -//----- page0 --------------------------------------------- +//----- page0 ------------------------------------------------------------------ #define BNO055_CHIP_ID 0x00 #define BNO055_ACCEL_REV_ID 0x01 #define BNO055_MAG_REV_ID 0x02 @@ -431,7 +441,7 @@ #define MAG_RADIUS_LSB 0x69 #define MAG_RADIUS_MSB 0x6a -//----- page1 --------------------------------------------- +//----- page1 ------------------------------------------------------------------ // Configuration registers #define ACCEL_CONFIG 0x08 #define MAG_CONFIG 0x09 @@ -460,71 +470,76 @@ #define GYRO_ANY_MOTION_THRES 0x1e #define GYRO_ANY_MOTION_SET 0x1f -//--------------------------------------------------------- -//----- Calibration example ------------------------------- -//--------------------------------------------------------- +//------------------------------------------------------------------------------ +//----- Calibration example ---------------------------------------------------- +//------------------------------------------------------------------------------ #if 0 // Calibration // Please refer BNO055 Data sheet 3.10 Calibration & 3.6.4 Sensor calibration data -void bno055_calbration(void){ +void bno055_calbration(void) +{ uint8_t d; - pc.printf("------ Enter BNO055 Manual Calibration Mode ------\r\n"); + printf("------ Enter BNO055 Manual Calibration Mode ------\r\n"); //---------- Gyroscope Caliblation ------------------------------------------------------------ // (a) Place the device in a single stable position for a period of few seconds to allow the // gyroscope to calibrate - pc.printf("Step1) Please wait few seconds\r\n"); + printf("Step1) Please wait few seconds\r\n"); t.start(); - while (t.read() < 10){ + while (t.read() < 10) { d = imu.read_calib_status(); - pc.printf("Calb dat = 0x%x target = 0x30(at least)\r\n", d); - if ((d & 0x30) == 0x30){ + printf("Calb dat = 0x%x target = 0x30(at least)\r\n", d); + if ((d & 0x30) == 0x30) { break; } wait(1.0); } - pc.printf("-> Step1) is done\r\n\r\n"); + printf("-> Step1) is done\r\n\r\n"); //---------- Magnetometer Caliblation --------------------------------------------------------- // (a) Make some random movements (for example: writing the number ‘8’ on air) until the // CALIB_STAT register indicates fully calibrated. // (b) It takes more calibration movements to get the magnetometer calibrated than in the // NDOF mode. - pc.printf("Step2) random moving (try to change the BNO055 axis)\r\n"); + printf("Step2) random moving (try to change the BNO055 axis)\r\n"); t.start(); - while (t.read() < 30){ + while (t.read() < 30) { d = imu.read_calib_status(); - pc.printf("Calb dat = 0x%x target = 0x33(at least)\r\n", d); - if ((d & 0x03) == 0x03){ + printf("Calb dat = 0x%x target = 0x33(at least)\r\n", d); + if ((d & 0x03) == 0x03) { break; } - wait(1.0); + wait(1.0); } - pc.printf("-> Step2) is done\r\n\r\n"); + printf("-> Step2) is done\r\n\r\n"); //---------- Magnetometer Caliblation --------------------------------------------------------- // a) Place the device in 6 different stable positions for a period of few seconds // to allow the accelerometer to calibrate. // b) Make sure that there is slow movement between 2 stable positions // The 6 stable positions could be in any direction, but make sure that the device is // lying at least once perpendicular to the x, y and z axis. - pc.printf("Step3) Change rotation each X,Y,Z axis KEEP SLOWLY!!"); - pc.printf(" Each 90deg stay a 5 sec and set at least 6 position.\r\n"); - pc.printf(" e.g. (1)ACC:X0,Y0,Z-9,(2)ACC:X9,Y0,Z0,(3)ACC:X0,Y0,Z9,"); - pc.printf("(4)ACC:X-9,Y0,Z0,(5)ACC:X0,Y-9,Z0,(6)ACC:X0,Y9,Z0,\r\n"); - pc.printf(" If you will give up, hit any key.\r\n", d); + printf("Step3) Change rotation each X,Y,Z axis KEEP SLOWLY!!"); + printf(" Each 90deg stay a 5 sec and set at least 6 position.\r\n"); + printf(" e.g. (1)ACC:X0,Y0,Z-9,(2)ACC:X9,Y0,Z0,(3)ACC:X0,Y0,Z9,"); + printf("(4)ACC:X-9,Y0,Z0,(5)ACC:X0,Y-9,Z0,(6)ACC:X0,Y9,Z0,\r\n"); + printf(" If you will give up, hit any key.\r\n", d); t.stop(); - while (true){ + while (true) { d = imu.read_calib_status(); imu.get_gravity(&gravity); - pc.printf("Calb dat = 0x%x target = 0xff ACC:X %3.0f, Y %3.0f, Z %3.0f\r\n", - d, gravity.x, gravity.y, gravity.z); - if (d == 0xff){ break;} - if (pc.readable()){ break;} + printf("Calb dat = 0x%x target = 0xff ACC:X %3.0f, Y %3.0f, Z %3.0f\r\n", + d, gravity.x, gravity.y, gravity.z); + if (d == 0xff) { + break; + } + if (pc.readable()) { + break; + } wait(1.0); } - if (imu.read_calib_status() == 0xff){ - pc.printf("-> All of Calibration steps are done successfully!\r\n\r\n"); + if (imu.read_calib_status() == 0xff) { + printf("-> All of Calibration steps are done successfully!\r\n\r\n"); } else { - pc.printf("-> Calibration steps are suspended!\r\n\r\n"); + printf("-> Calibration steps are suspended!\r\n\r\n"); } t.stop(); }