BMG160 Class
- ID: bmg160
- Name: 3-axis Gyroscope Sensor
- Category: gyro
- Manufacturer: bosch
- Connection: i2c spi gpio
- Link: https://www.bosch-sensortec.com/bst/products/all_products/bmg160
The BMG160 is a 3-axis angular rate sensor that is made of a surface micro machined sensing element and an evaluation ASIC. Both parts are packed into one single LGA 3.0mm x 3.0mm x 0.95mm housing. The BMG160 is designed to meet requirements for consumer applications such as image stabilization (DSC and camera-phone), gaming and pointing devices. It is capable to measure angular rates in three perpendicular room dimensions, the x-, y- and z-axis, and to provide the corresponding output signals. The BMG160 is fitted with digital bi-directional SPI and I2C interfaces for optimum system integration.
Not all functionality of this chip has been implemented in this driver, however all the pieces are present to add any desired functionality. This driver supports both I2C (default) and SPI operation.
This device requires 3.3v operation.
Item Index
Methods
- BMG160
- update
- getChipID
- getGyroscope
- getGyroscope
- getTemperature
- init
- reset
- setRange
- setBandwidth
- setPowerMode
- enableFIFO
- fifoSetWatermark
- fifoConfig
- getInterruptEnable0
- setInterruptEnable0
- getInterruptMap0
- setInterruptMap0
- getInterruptMap1
- setInterruptMap1
- getInterruptSrc
- setInterruptSrc
- getInterruptOutputControl
- setInterruptOutputControl
- clearInterruptLatches
- getInterruptLatchBehavior
- setInterruptLatchBehavior
- getInterruptStatus0
- getInterruptStatus1
- getInterruptStatus2
- getInterruptStatus3
- enableRegisterShadowing
- enableOutputFiltering
- installISR
- uninstallISR
- readReg
- readRegs
- writeReg
Methods
BMG160
-
bus -
addr -
cs
BMG160 constructor.
This device can support both I2C and SPI. For SPI, set the addr to -1, and specify a positive integer representing the Chip Select (CS) pin for the cs argument. If you are using a hardware CS pin (like edison with arduino breakout), then you can connect the proper pin to the hardware CS pin on your MCU and supply -1 for cs. The default operating mode is I2C.
Parameters:
-
busNumberI2C or SPI bus to use.
-
addrNumberThe address for this device. -1 for SPI.
-
csNumberThe gpio pin to use for the SPI Chip Select. -1 for I2C or for SPI with a hardware controlled pin.
Returns:
update
()
Update the internal stored values from sensor data.
getChipID
()
Number
Return the chip ID.
Returns:
The chip ID (BMG160_CHIPID).
getGyroscope
-
x -
y -
z
Return gyroscope data in degrees per second. update() must have been called prior to calling this method.
Parameters:
-
xFloat *Pointer to a floating point value that will have the current x component placed into it.
-
yFloat *Pointer to a floating point value that will have the current y component placed into it.
-
zFloat *Pointer to a floating point value that will have the current z component placed into it.
getGyroscope
()
Std::vector float
Return gyroscope data in degrees per second in the form of a floating point vector. update() must have been called prior to calling this method.
Returns:
A floating point vector containing x, y, and z in that order.
getTemperature
-
fahrenheit
Return the current measured temperature. Note, this is not ambient temperature. update() must have been called prior to calling this method.
Parameters:
-
fahrenheitBooleantrue to return data in Fahrenheit, false for Celicus. Celsius is the default.
Returns:
The temperature in degrees Celsius or Fahrenheit.
init
-
pwr -
range -
bw
Initialize the device and start operation. This function is called from the constructor so will not typically need to be called by a user unless the device is reset.
Parameters:
-
pwrBMG160_POWER_MODE_TOne of the BMG160_POWER_MODE_T values. The default is BMG160_POWER_MODE_NORMAL.
-
rangeBMG160_RANGE_TOne of the BMG160_RANGE_T values. The default is BMG160_RANGE_250.
-
bwBMG160_BW_TOne of the filtering BMG160_BW_T values. The default is BMG160_BW_400_47.
reset
()
Reset the device as if during a power on reset. All configured values are lost when this happens. You should call init() afterwards, or at least perform the same initialization init() does before continuing.
setRange
-
range
Set the gyroscope detection scaling range. This device supports 125, 250, 500, 1000, and 2000 degree/s ranges.
Parameters:
-
rangeBMG160_RANGE_TOne of the BMG160_RANGE_T values.
setBandwidth
-
bw
Set the output filtering bandwidth of the device.
Parameters:
-
bwBMG160_BW_TOne of the BMG160_BW_T values.
setPowerMode
-
power
Set the power mode of the device. Care must be taken when setting a low power or suspend mode. See the datasheet for details. I ncertain power modes, register write must be drastically slowed down. which we cannot support.
Parameters:
-
powerBMG160_POWER_MODE_TOne of the POWER_MODE_T values.
enableFIFO
-
useFIFO
Enable update() to read from the FIFO rather than the gyroscope axis registers directly. init() enables this mode by default. An advantage to this mode that all axis data is sampled from the same timeslice. When reading directly from the gyroscope output registers, it's possible for one axis to be updated while another is being read, causing a temporal inconsistancy..
Using the FIFO removes this problem.
Parameters:
-
useFIFOBooleantrue to enable update() to read from the FIFO. When false, update will read from the gyroscope output registers directly.
fifoSetWatermark
-
wm
Set the FIFO watermark. When the watermark is reached an interrupt (if enabled) will be generated.
Parameters:
-
wmNumberThe FIFO watermark to use. The maximum value is 63.
fifoConfig
-
mode -
axes
Set the FIFO configuration. init() uses the BMG160_FIFO_MODE_BYPASS mode with axes set to BMG160_FIFO_DATA_SEL_XYZ by default.
Parameters:
-
modeBMG160_FIFO_MODE_TOne of the BMG160_FIFO_MODE_T values.
-
axesBMG160_FIFO_DATA_SEL_TOne of the BMG160_FIFO_DATA_SEL_T values.
getInterruptEnable0
()
Number
Return the Interrupt Enables 0 register. These registers allow you to enable various interrupt conditions. See the datasheet for details.
Returns:
A bitmask of INT_EN_0_BITS_T bits.
setInterruptEnable0
-
bits
Set the Interrupt Enables 0 register. See the datasheet for details.
Parameters:
-
bitsNumberA bitmask of BMG160_INT_EN_0_BITS_T bits.
getInterruptMap0
()
Number
Return the Interrupt Map 0 register. These registers allow you to map specific interrupts to the interrupt 1 or interrupt 2 pin. See the datasheet for details.
Returns:
A bitmask of INT_MAP_0_BITS_T bits.
setInterruptMap0
-
bits
Set the Interrupt Map 0 register. These registers allow you to map specific interrupts to the interrupt 1 or interrupt 2 pin. See the datasheet for details.
Parameters:
-
bitsNumberA bitmask of BMG160_INT_MAP_0_BITS_T bits.
getInterruptMap1
()
Number
Return the Interrupt Map 1 register. See the datasheet for details.
Returns:
A bitmask of BMG160_INT_MAP_1_BITS_T bits.
setInterruptMap1
-
bits
Set the Interrupt Map 1 register. See the datasheet for details.
Parameters:
-
bitsNumberA bitmask of BMG160_INT_MAP_1_BITS_T bits.
getInterruptSrc
()
Number
Return the Interrupt source register. This register allows determining where data comes from (filtered/unfiltered) for those interrupt sources where this is selectable. See the datasheet for details.
Returns:
A bitmask of INT_1A_BITS_T bits.
setInterruptSrc
-
bits
Set the Interrupt source register. This register allows determining where data comes from (filtered/unfiltered) for those interrupt sources where this is selectable. See the datasheet for details.
Parameters:
-
bitsNumberA bitmask of INT_1A_BITS_T bits.
getInterruptOutputControl
()
Number
Return the Interrupt output control register. This register allows determining the electrical characteristics of the 2 interrupt pins (open-drain/push-pull and level/edge triggering). See the datasheet for details.
Returns:
A bitmask of INT_EN_1_BITS_T bits.
setInterruptOutputControl
-
bits
Set the Interrupt output control register. This register allows determining the electrical characteristics of the 2 interrupt pins (open-drain/push-pull and level/edge triggering). See the datasheet for details.
Parameters:
-
bitsNumberA bitmask of INT_EN_1_BITS_T bits.
clearInterruptLatches
()
Clear all latched interrupts. See the datasheet for details.
getInterruptLatchBehavior
()
BMG160_RST_LATCH_T
Return the current interrupt latching behavior. See the datasheet for details.
Returns:
One of the RST_LATCH_T values.
setInterruptLatchBehavior
-
latch
Set the current interrupt latching behavior. See the datasheet for details.
Parameters:
-
latchBMG160_RST_LATCH_TOne of the RST_LATCH_T values.
getInterruptStatus0
()
Number
Return the interrupt status 0 register. These registers indicate which interrupts have been triggered. See the datasheet for details.
Returns:
a bitmask of INT_STATUS_0_BITS_T bits.
getInterruptStatus1
()
Number
Return the interrupt status 1 register. See the datasheet for details.
Returns:
a bitmask of INT_STATUS_1_BITS_T bits.
getInterruptStatus2
()
Number
Return the interrupt status 2 register. See the datasheet for details.
Returns:
a bitmask of INT_STATUS_2_BITS_T bits.
getInterruptStatus3
()
Number
Return the interrupt status 3 register. See the datasheet for details.
Returns:
a bitmask of INT_STATUS_3_BITS_T bits.
enableRegisterShadowing
-
shadow
Enable shadowing of the gyroscope output registers. When enabled, a read of an axis LSB register automatically locks the MSB register of that axis until it has been read. This is usually a good thing to have enabled. init() enables this by default. If disabled, then it becomes possible for part of an axis value to change while another part is being read, causing inconsistent data.
Parameters:
-
shadowBooleantrue to enable axis register shadowing, false otherwise.
enableOutputFiltering
-
filter
Enable filtering of the gyroscope axis data. init() enables this by default. If disabled, then gyroscope data that is read will be raw and unfiltered (rated R). See the datasheet for details.
Parameters:
-
filterBooleantrue to enable filtering, false to disable.
installISR
-
intr -
gpio -
level -
isr -
arg
install an interrupt handler.
Parameters:
-
intrBMG160_INTERRUPT_PINS_TOne of the BMG160_INTERRUPT_PINS_T values specifying which interrupt pin you are installing.
-
gpioNumberGPIO pin to use as interrupt pin.
-
levelMraa::EdgeThe interrupt trigger level (one of the mraa::Edge values). Make sure that you have configured the interrupt pin properly for whatever level you choose.
-
isrFunctionThe interrupt handler, accepting a void * argument.
-
argVoid *The argument to pass the the interrupt handler.
uninstallISR
-
intr
uninstall a previously installed interrupt handler
Parameters:
-
intrBMG160_INTERRUPT_PINS_Tone of the INTERRUPT_PINS_T values specifying which interrupt pin you are removing.
readReg
-
reg
Read a register.
Parameters:
-
regNumberThe register to read.
Returns:
The value of the register.
readRegs
-
reg -
buffer -
len
Read contiguous registers into a buffer.
Parameters:
-
regNumberundefined
-
bufferUint8_t *The buffer to store the results.
-
lenNumberThe number of registers to read.
Returns:
The number of bytes read.
writeReg
-
reg -
val
Write to a register
Parameters:
-
regNumberThe register to write to.
-
valNumberThe value to write.