Joel von Rotz / BNO055
Embed: (wiki syntax)

« Back to documentation index

BNO055 Class Reference

BNO055 Class Reference

This is a library for the sensor BNO055, a 9 axis sensor by Bosch Sensortec, written by Joel von Rotz More...

#include <bno055.h>

Public Member Functions

 BNO055 (uint8_t slave_address, I2C_Master &i2c_master, DigitalOut &ResetPin, bool external_clk, Serial &DEBUG_SERIAL)
 Construct a new BNO055::BNO055 object.
 BNO055 (uint8_t slave_address, I2C_Master &i2c_master, DigitalOut &ResetPin, bool external_clk)
 Construct a new BNO055::BNO055 object.
void setUnitFormat (bno055_orientation_t new_orientation_format=WINDOWS, bno055_temperature_t new_temperature_format=CELSIUS, bno055_euler_t new_euler_format=DEGREES, bno055_gyro_t new_gyroscope_format=DEGREE_PER_SEC, bno055_acceleration_t new_acceleration_format=ACCELERATION)
 Defines the format of the measurment units.
void getUnitFormat (void)
 Not Finished.
void getIDs (void)
 Get IDs.
void setPowerMode (bno055_powermode_t new_power_mode=POWER_NORMAL)
 Sets the Power Mode.
uint8_t getPowerMode (void)
 Returns the currently used Power Mode.
void setOperationMode (bno055_opr_mode_t new_opr_mode=OPERATION_MODE_CONFIGMODE)
 Sets the desired Operation Mode.
uint8_t getOperationMode (void)
 Returns the current Operation Mode.
void setPage (bno055_page_t new_page=PAGE_0)
 Set I2C-Registermap Page.
uint8_t getPage (void)
 Returns the current Registermap-Page.
uint8_t getSystemStatus (void)
 Returns the System Status.
uint8_t getSystemError (void)
 Returns the System Error.
void useExternalOscillator (bool enabled)
 Configure External Oscillator Input.
void resetSW (void)
 Resets the System via Software.
void resetHW (void)
 Resets the System via Reset-Pin.
void assignAxis (bno055_axis_t x_axis=X_AXIS, bno055_axis_t y_axis=Y_AXIS, bno055_axis_t z_axis=Z_AXIS)
 Assign Axis to different Axes.
void setAxisSign (bno055_axis_sign_t x_sign=POSITIVE, bno055_axis_sign_t y_sign=POSITIVE, bno055_axis_sign_t z_sign=POSITIVE)
 Inverts the Axis.
void setOrientation (bno055_remap_options_t orientation_placement=REMAP_OPTION_P1)
 Remaps the three Axes to respect the new Orientation.
void getOrientation (void)
 Returns the current Orientation.
void getCalibrationStatus (void)
 Gets the System's Calibration Status.
void getInterruptFlag (void)
 Gets the Interrupt-flags.
void setEnableInterrupts (bno055_enable_t accel_no_motion, bno055_enable_t accel_any_motion, bno055_enable_t accel_high_g, bno055_enable_t gyro_high_rate, bno055_enable_t gyro_any_motion)
 Configure the Interrupts.
uint8_t getEnabledInterrupts (void)
 Returns the enabled Interrupt.
void setInterruptMask (bno055_enable_t accel_no_motion, bno055_enable_t accel_any_motion, bno055_enable_t accel_high_g, bno055_enable_t gyro_high_rate, bno055_enable_t gyro_any_motion)
 Sets the Interrupt Mask.
uint8_t getInterruptMask (void)
 Returns current Interrupt Mask.
void getAcceleration (void)
 Returns Acceleration Data.
void getMagnetometer (void)
 Returns Magnetometer Data.
void getGyroscope (void)
 Returns Gyroscope Data.
void getEulerDegrees (void)
 Returns Euler Degree Data.
void getQuaternion (void)
 Returns Quaternion Data.
void getLinearAcceleration (void)
 Returns Linear Acceleration Data.
void getGravityVector (void)
 Returns Gravity Vector Data.
void getTemperature (void)
 Returns Temperature Data.

Detailed Description

This is a library for the sensor BNO055, a 9 axis sensor by Bosch Sensortec, written by Joel von Rotz

BNO055-gyroscope-Absolute-Orientation-9-Axis-Sensor.jpg_640x640.jpg

Currently, this library is compatible with the mbed LPC1768 only and probably won't change in the future, unless somebody takes their time to port the library to other microcontroller (would very much appreciate it though).

This Library requires The TWI_Master Library to work



Example Programm Without Debug

 #include "mbed.h"
 #include "i2c_master.h"
 #include "bno055.h"
 
 Serial  pc(USBTX,USBRX,115200);
 
 I2C_Master i2c_master(p9, p10);
 DigitalOut bno055_reset(p11);
 BNO055     bno055(0x28,         //7-bit slave address
                   i2c_master,   //reference of the i2c-master object
                   bno055_reset, //reference of the reset-pin connected with the mbed
                   true);        //enable external 32kHz oscillator
 
 
 int main() {
   bno055.setOperationMode(OPERATION_MODE_NDOF);
   
   while(1) {
     bno055.getEulerDegrees();
     pc.printf("x: %4.3f y: %4.3f z: %4.3f\n\r", bno055.euler.x,bno055.euler.y,bno055.euler.z);
     wait_ms(100);
   }
 }


Example Programm With Debug

 #define DEBUGGING_ENABLED
 
 #include "mbed.h"
 #include "i2c_master.h"
 #include "bno055.h"
 
 Serial  pc(USBTX,USBRX,115200);
 
 I2C_Master i2c_master(p9, p10);
 DigitalOut bno055_reset(p11);
 BNO055     bno055(0x28,         //7-bit slave address
                   i2c_master,   //reference of the i2c-master object
                   bno055_reset, //reference of the reset-pin connected with the mbed
                   true,         //enable external 32kHz oscillator
                   pc);          //debugging Serial object
 
 int main() {
   bno055.setOperationMode(OPERATION_MODE_NDOF);
   
   while(1) {
     bno055.getEulerDegrees();
     pc.printf("x: %4.3f y: %4.3f z: %4.3f\n\r", bno055.euler.x,bno055.euler.y,bno055.euler.z);
     wait_ms(100);
   }
 }

During the execution of the programm, open your terminal. Everything should now be printed.

Definition at line 84 of file bno055.h.


Constructor & Destructor Documentation

BNO055 ( uint8_t  slave_address,
I2C_Master &  i2c_master,
DigitalOut &  ResetPin,
bool  external_clk,
Serial &  DEBUG_SERIAL 
)

Construct a new BNO055::BNO055 object.

This is the Debugging-version of the BNO055 class. The constructor requires an additional Serial-Object.

Parameters:
slave_addressThe slave-address (determined by the Address-Pin on the chip)
i2c_masterI2C-Master object
ResetPinReference of the Output-Pin, which is connected to the Reset-Pin of the Sensor
external_clkBoolean to determine if the Sensor uses an external 32kHz oscillator
DEBUG_SERIALReference of the Serial-object used to debug the different functions.

Definition at line 34 of file bno055.cpp.

BNO055 ( uint8_t  slave_address,
I2C_Master &  i2c_master,
DigitalOut &  ResetPin,
bool  external_clk 
)

Construct a new BNO055::BNO055 object.

Parameters:
slave_addressThe slave-address (determined by the Address-Pin on the chip)
i2c_masterI2C-Master object
ResetPinReference of the Output-Pin, which is connected to the Reset-Pin of the Sensor
external_clkBoolean to determine if the Sensor uses an external 32kHz oscillator

Definition at line 69 of file bno055.cpp.


Member Function Documentation

void assignAxis ( bno055_axis_t  x_axis = X_AXIS,
bno055_axis_t  y_axis = Y_AXIS,
bno055_axis_t  z_axis = Z_AXIS 
)

Assign Axis to different Axes.

But it's not possible to map the two axes on the same axis. It will not return anything, even if it's correct.

Possible values are: X_AXIS, Y_AXIS, Z_AXIS

Parameters:
x_axisNew Axis which will be applied to the X-Axis
y_axisNew Axis which will be applied to the Y-Axis
z_axisNew Axis which will be applied to the Z-Axis

Definition at line 483 of file bno055.cpp.

void getAcceleration ( void   )

Returns Acceleration Data.

Data is accessible through the accel-struct (object.accel.x, object.accel.y, object.accel.z), after calling this function

Definition at line 709 of file bno055.cpp.

void getCalibrationStatus ( void   )

Gets the System's Calibration Status.

The data is accessible through the calibration-struct (object.calibration.status, object.calibration.system, object.calibration.gyro, object.calibration.acceleration, object.calibration.magneto)

Definition at line 528 of file bno055.cpp.

uint8_t getEnabledInterrupts ( void   )

Returns the enabled Interrupt.

Returns:
uint8_t The value containing the enabled interrupts (see datasheet)

Definition at line 581 of file bno055.cpp.

void getEulerDegrees ( void   )

Returns Euler Degree Data.

Data is accessible through the euler-struct (object.euler.x, object.euler.y, object.euler.z), after calling this function

Definition at line 767 of file bno055.cpp.

void getGravityVector ( void   )

Returns Gravity Vector Data.

Data is accessible through the gravity_vector-struct (object.gravity_vector.x, object.gravity_vector.y, object.gravity_vector.z), after calling this function

Definition at line 824 of file bno055.cpp.

void getGyroscope ( void   )

Returns Gyroscope Data.

Data is accessible through the gyro-struct (object.gyro.x, object.gyro.y, object.gyro.z), after calling this function

Definition at line 746 of file bno055.cpp.

void getIDs ( void   )

Get IDs.

Read the datasheet, what exactly these IDs are. The data is accessible through the id-struct (object.id.xxx).

Definition at line 153 of file bno055.cpp.

void getInterruptFlag ( void   )

Gets the Interrupt-flags.

The data is accessible through the interrupt-struct (object.interrupt.xxx)

Definition at line 551 of file bno055.cpp.

uint8_t getInterruptMask ( void   )

Returns current Interrupt Mask.

Returns:
uint8_t Current Interrupt Mask (see datasheet)

Definition at line 655 of file bno055.cpp.

void getLinearAcceleration ( void   )

Returns Linear Acceleration Data.

Data is accessible through the linear_accel-struct (object.linear_accel.x, object.linear_accel.y, object.linear_accel.z), after calling this function

Definition at line 803 of file bno055.cpp.

void getMagnetometer ( void   )

Returns Magnetometer Data.

Data is accessible through the magneto-struct (object.magneto.x, object.magneto.y, object.magneto.z), after calling this function

Definition at line 731 of file bno055.cpp.

uint8_t getOperationMode ( void   )

Returns the current Operation Mode.

The data is also accessible through the mode-struct (object.mode.operation).

Returns:
uint8_t The current Operation Mode

Definition at line 289 of file bno055.cpp.

void getOrientation ( void   )

Returns the current Orientation.

The data is accessible through the axis-struct (object.axis.map & object.axis.sign).

Definition at line 459 of file bno055.cpp.

uint8_t getPage ( void   )

Returns the current Registermap-Page.

The data is also accessible through the page-struct (object.page).

Returns:
uint8_t The Current Page

Definition at line 325 of file bno055.cpp.

uint8_t getPowerMode ( void   )

Returns the currently used Power Mode.

The data is also accessible through the mode-struct (object.mode.power).

Returns:
uint8_t Currently used Power Mode

Definition at line 222 of file bno055.cpp.

void getQuaternion ( void   )

Returns Quaternion Data.

Data is accessible through the quaternion-struct (object.quaternion.x, object.quaternion.y, object.quaternion.z), after calling this function

Definition at line 788 of file bno055.cpp.

uint8_t getSystemError ( void   )

Returns the System Error.

The data is also accessible through the system-struct (object.system.error).

Returns:
uint8_t System Error

Definition at line 359 of file bno055.cpp.

uint8_t getSystemStatus ( void   )

Returns the System Status.

The data is also accessible through the system-struct (object.system.status).

Returns:
uint8_t System Status

Definition at line 343 of file bno055.cpp.

void getTemperature ( void   )

Returns Temperature Data.

Data is accessible through the temperature-struct (object.temperature), after calling this function

Definition at line 845 of file bno055.cpp.

void getUnitFormat ( void   )

Not Finished.

Definition at line 143 of file bno055.cpp.

void resetHW ( void   )

Resets the System via Reset-Pin.

Resets the System with the referenced Reset-Pin during object-construction

Definition at line 418 of file bno055.cpp.

void resetSW ( void   )

Resets the System via Software.

Definition at line 394 of file bno055.cpp.

void setAxisSign ( bno055_axis_sign_t  x_sign = POSITIVE,
bno055_axis_sign_t  y_sign = POSITIVE,
bno055_axis_sign_t  z_sign = POSITIVE 
)

Inverts the Axis.

Possible values are: POSITIVE & NEGATIVE

Parameters:
x_signNew Sign for the X-Axis
y_signNew Sign for the Y-Axis
z_signNew Sign for the Z-Axis

Definition at line 513 of file bno055.cpp.

void setEnableInterrupts ( bno055_enable_t  accel_no_motion,
bno055_enable_t  accel_any_motion,
bno055_enable_t  accel_high_g,
bno055_enable_t  gyro_high_rate,
bno055_enable_t  gyro_any_motion 
)

Configure the Interrupts.

Parameters:
accel_no_motionENABLE to enable interrupt, DISABLE to disable interrupt
accel_any_motionENABLE to enable interrupt, DISABLE to disable interrupt
accel_high_gENABLE to enable interrupt, DISABLE to disable interrupt
gyro_high_rateENABLE to enable interrupt, DISABLE to disable interrupt
gyro_any_motionENABLE to enable interrupt, DISABLE to disable interrupt

Definition at line 603 of file bno055.cpp.

void setInterruptMask ( bno055_enable_t  accel_no_motion,
bno055_enable_t  accel_any_motion,
bno055_enable_t  accel_high_g,
bno055_enable_t  gyro_high_rate,
bno055_enable_t  gyro_any_motion 
)

Sets the Interrupt Mask.

This function enables or disabled the changing of the Interrupt-pin.

Parameters:
accel_no_motionENABLE to enable interrupt-calling, DISABLE to disable it
accel_any_motionENABLE to enable interrupt-calling, DISABLE to disable it
accel_high_gENABLE to enable interrupt-calling, DISABLE to disable it
gyro_high_rateENABLE to enable interrupt-calling, DISABLE to disable it
gyro_any_motionENABLE to enable interrupt-calling, DISABLE to disable it

Definition at line 632 of file bno055.cpp.

void setOperationMode ( bno055_opr_mode_t  new_opr_mode = OPERATION_MODE_CONFIGMODE )

Sets the desired Operation Mode.

All of the information aren't definitive or could be straight up wrong. It is therefore highly recommended to read the datasheet of the BNO055.

Operation Modes
Type Description
OPERATION_MODE_CONFIGMODE Used when configuring the system
OPERATION_MODE_ACCONLY Enables Accelerometer only
OPERATION_MODE_MAGONLY Enables Magnetometer only
OPERATION_MODE_GYROONLY Enables Gyroscope only
OPERATION_MODE_ACCMAG Enables Accelerometer and Magnetometer only
OPERATION_MODE_ACCGYRO Enables Accelerometer and Gyroscope only
OPERATION_MODE_MAGGYRO Enables Magnetometer and Gyroscope only
OPERATION_MODE_AMG Enables all three sensors
OPERATION_MODE_IMU Enables Accelerometer & Gyroscope and relative position
OPERATION_MODE_COMPASS Enables Accelerometer & Magnetometer and absolute position
OPERATION_MODE_M4G "Magnet for Gyroscope" is similar to IMU, but instead using the gyroscope, it uses the magnetometer
OPERATION_MODE_NDOF_FMC_OFF "9 degrees of freedom" but without fast magnetometer calibration.
OPERATION_MODE_NDOF "9 degrees of freedom" - Magnetometer is calibrated very fast and increased data output
Parameters:
new_opr_mode

Definition at line 256 of file bno055.cpp.

void setOrientation ( bno055_remap_options_t  orientation_placement = REMAP_OPTION_P1 )

Remaps the three Axes to respect the new Orientation.

use REMAP_OPTION_PX with X defining one of the 8 orientation options (see datasheet)

Parameters:
orientation_placementOrientation of the IC

Definition at line 440 of file bno055.cpp.

void setPage ( bno055_page_t  new_page = PAGE_0 )

Set I2C-Registermap Page.

The BNO055 contains two Register Map pages: Page 0 and Page 1. This function is used to switch between those two.

Possible Options are: PAGE_0 & PAGE_1

Parameters:
new_pageDesired new page number

Definition at line 307 of file bno055.cpp.

void setPowerMode ( bno055_powermode_t  new_power_mode = POWER_NORMAL )

Sets the Power Mode.

All of the information aren't definitive or could be straight up wrong. It is therefore highly recommended to read the datasheet of the BNO055.

Power Modes
Type Description
POWER_NORMAL All sensors are activated
POWER_LOW_POWER_MODE If no action is detected for a configurable duration (default 5 seconds), the system is put into low power mode.
POWER_SUSPEND_MODE System is paused and sensors and mcu is put into sleep mode.
Parameters:
new_power_modeNew Power Mode

Definition at line 190 of file bno055.cpp.

void setUnitFormat ( bno055_orientation_t  new_orientation_format = WINDOWS,
bno055_temperature_t  new_temperature_format = CELSIUS,
bno055_euler_t  new_euler_format = DEGREES,
bno055_gyro_t  new_gyroscope_format = DEGREE_PER_SEC,
bno055_acceleration_t  new_acceleration_format = ACCELERATION 
)

Defines the format of the measurment units.

Following is a table, which displays all the possible formats for each measurement units. The column Code contain the values, which are used in the programm.

Measurement Unit Formats
Type Formats Code
Orientation Windows, Android - this changes the ranges of the axis WINDOWS, ANDROID
Temperature Celsius, Fahrenheit CELSIUS, FAHRENHEIT
Euler Degree, Radians DEGREE, RADIANS
Gyroscope degree per seconds, radian per seconds DEGREE_PER_SEC, RADIAN_PER_SEC
Acceleration acceleration (m/s2), milli g-force ACCELERATION, MILLI_G_FORCE
Parameters:
new_orientation_format
new_temperature_format
new_euler_format
new_gyroscope_format
new_acceleration_format

Definition at line 118 of file bno055.cpp.

void useExternalOscillator ( bool  enabled )

Configure External Oscillator Input.

The external oscillator increases data accuracy.

Parameters:
enabledTRUE enables external oscillator input, FALSE disabled input

Definition at line 375 of file bno055.cpp.