UPM

The UPM API is a high level sensor library for IoT devices using MRAA. See examples here. Back to index page.
SparkFun sensor images provided under CC BY-NC-SA-3.0.

BMA250E Class

Module: bma250e

The BMA250E is a triaxial, low-g acceleration sensor with digital output for consumer applications. It allows measurements of acceleration in three perpendicular axes. An evaluation circuitry (ASIC) converts the output of a micromechanical acceleration-sensing structure (MEMS) that works according to the differential capacitance principle.
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 driver attempts to support verious flavors of this chip, such as the version on the BMX050, BMI050 (chipid 0xfa) and the version on the bmc050 (chipid 0x03). Not all functionality is appropriate, or even present on all chips. Consult the relevant datasheets.
This device requires 3.3v operation.

Methods

BMA250E

(
  • bus
  • addr
  • cs
)
Number

BMA250E 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:

  • bus Number

    I2C or SPI bus to use.

  • addr Number

    The address for this device. -1 for SPI.

  • cs Number

    The gpio pin to use for the SPI Chip Select. -1 for I2C or for SPI with a hardware controlled pin.

Returns:

Number:

update

()

Update the internal stored values from sensor data.

getChipID

() Number

Return the chip ID.

Returns:

Number:

The chip ID.

getAccelerometer

(
  • x
  • y
  • z
)

Return accelerometer data in gravities. update() must have been called prior to calling this method.

Parameters:

  • x Float *

    Pointer to a floating point value that will have the current x component placed into it.

  • y Float *

    Pointer to a floating point value that will have the current y component placed into it.

  • z Float *

    Pointer to a floating point value that will have the current z component placed into it.

getAccelerometer

() Std::vector float

Return accelerometer data in gravities in the form of a floating point vector. update() must have been called prior to calling this method.

Returns:

Std::vector float :

A floating point vector containing x, y, and z in that order.

getTemperature

(
  • fahrenheit
)
Number

Return the current measured temperature. Note, this is not ambient temperature. update() must have been called prior to calling this method.

Parameters:

  • fahrenheit Boolean

    true to return data in Fahrenheit, false for Celicus. Celsius is the default.

Returns:

Number:

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:

  • pwr BMA250E_POWER_MODE_T

    One of the BMA250E_POWER_MODE_T values. The default is BMA250E_POWER_MODE_NORMAL.

  • range BMA250E_RANGE_T

    One of the BMA250E_RANGE_T values. The default is BMA250E_RANGE_2G.

  • bw BMA250E_BW_T

    One of the filtering BMA250E_BW_T values. The default is BMA250E_BW_250.

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 acceleration scaling range. This device supports 2, 4, 8, and 16g ranges.

Parameters:

  • range BMA250E_RANGE_T

    One of the BMA250E_RANGE_T values.

setBandwidth

(
  • bw
)

Set the output filtering bandwidth of the device.

Parameters:

  • bw BMA250E_BW_T

    One of the BMA250E_BW_T values.

setPowerMode

(
  • power
)

Set the power mode of the device. Care must be taken when setting a low power or suspend mode. By default init() calls setLowPowerMode2() to ensure that if any of these modes are entered we can still talk to the device. The default low power mode is LPM1, which requires slowing down register writes, which we cannot support. setLowPowerMode2() enables LPM2 which keeps the digital interface operational in low power or suspend modes. See the datasheet for details.
So if you reset your device and don't call init() or setLowPowerMode2() , you could lose control of the device by calling this function with anything other than POWER_MODE_NORMAL. You've been warned :)

Parameters:

  • power BMA250E_POWER_MODE_T

    One of the BMA250E_POWER_MODE_T values.

enableFIFO

(
  • useFIFO
)

Enable update() to read from the FIFO rather than the acceleration axis registers directly. init() enables this mode by default if the chip variant supports a FIFO. An advantage to this mode that all axis data is sampled from the same timeslice. When reading directly from the acceleration output registers, it's possible for one axis to be updated while another is being read, causing a temporal anomaly that even Captain Picard can't resolve. If there is no FIFO present, this call is ignored.
Using the FIFO removes this problem.

Parameters:

  • useFIFO Boolean

    True to enable update() to read from the FIFO. When false, update will read from the acceleration output registers directly.

fifoSetWatermark

(
  • wm
)

Set the FIFO watermark. When the watermark is reached an interrupt (if enabled) will be generated. If there is no FIFO present, this call is ignored.

Parameters:

  • wm Number

    The FIFO watermark to use. The maximum value is 63.

fifoConfig

(
  • mode
  • axes
)

Set the FIFO configuration. init() uses the FIFO_MODE_BYPASS mode with axes set to FIFO_DATA_SEL_XYZ by default. If there is no FIFO present, this call is ignored.

Parameters:

  • mode BMA250E_FIFO_MODE_T

    One of the BMA250E_FIFO_MODE_T values.

  • axes BMA250E_FIFO_DATA_SEL_T

    One of the BMA250E_FIFO_DATA_SEL_T values.

setSelfTest

(
  • sign
  • amp
  • axis
)

Enable, disable, and configure the built in self test on a per axis basis. See the datasheet for details.

Parameters:

  • sign Boolean

    True for a positive deflection, false for negative

  • amp Boolean

    True for a high deflection, false for a low deflection

  • axis BMA250E_SELFTTEST_AXIS_T

    One of the BMA250E_SELFTTEST_AXIS_T values. Note, only one axis at a time can be tested. Accelerometer output for other axes should be ignored.

getInterruptEnable0

() Number

Return the Interrupt Enables 0 register. These registers allow you to enable various interrupt conditions. See the datasheet for details.

Returns:

Number:

A bitmask of BMA250E_INT_EN_0_BITS_T bits.

setInterruptEnable0

(
  • bits
)

Set the Interrupt Enables 0 register. See the datasheet for details.

Parameters:

  • bits Number

    A bitmask of BMA250E_INT_EN_0_BITS_T bits.

getInterruptEnable1

() Number

Return the Interrupt Enables 1 register. See the datasheet for details.

Returns:

Number:

A bitmask of BMA250E_INT_EN_1_BITS_T bits.

setInterruptEnable1

(
  • bits
)

Set the Interrupt Enables 1 register. See the datasheet for details.

Parameters:

  • bits Number

    A bitmask of BMA250E_INT_EN_1_BITS_T bits.

getInterruptEnable2

() Number

Return the Interrupt Enables 2 register. See the datasheet for details.

Returns:

Number:

A bitmask of BMA250E_INT_EN_2_BITS_T bits.

setInterruptEnable2

(
  • bits
)

Set the Interrupt Enables 2 register. See the datasheet for details.

Parameters:

  • bits Number

    A bitmask of BMA250E_INT_EN_2_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:

Number:

A bitmask of BMA250E_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:

  • bits Number

    A bitmask of BMA250E_INT_MAP_0_BITS_T bits.

getInterruptMap1

() Number

Return the Interrupt Map 1 register. See the datasheet for details.

Returns:

Number:

A bitmask of BMA250E_INT_MAP_1_BITS_T bits.

setInterruptMap1

(
  • bits
)

Set the Interrupt Map 1 register. See the datasheet for details.

Parameters:

  • bits Number

    A bitmask of BMA250E_INT_MAP_1_BITS_T bits.

getInterruptMap2

() Number

Return the Interrupt Map 2 register. See the datasheet for details.

Returns:

Number:

A bitmask of BMA250E_INT_MAP_2_BITS_T bits.

setInterruptMap2

(
  • bits
)

Set the Interrupt Map 2 register. See the datasheet for details.

Parameters:

  • bits Number

    A bitmask of BMA250E_INT_MAP_2_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:

Number:

A bitmask of BMA250E_INT_SRC_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:

  • bits Number

    A bitmask of BMA250E_INT_SRC_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:

Number:

A bitmask of BMA250E_INT_OUT_CTRL_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:

  • bits Number

    A bitmask of BMA250E_INT_OUT_CTRL_BITS_T bits.

clearInterruptLatches

()

Clear all latched interrupts. See the datasheet for details.

getInterruptLatchBehavior

() BMA250E_RST_LATCH_T

Return the current interrupt latching behavior. See the datasheet for details.

Returns:

BMA250E_RST_LATCH_T:

One of the BMA250E_RST_LATCH_T values.

setInterruptLatchBehavior

(
  • latch
)

Set the current interrupt latching behavior. See the datasheet for details.

Parameters:

  • latch BMA250E_RST_LATCH_T

    One of the BMA250E_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:

Number:

A bitmask of BMA250E_INT_STATUS_0_BITS_T bits.

getInterruptStatus1

() Number

Return the interrupt status 1 register. See the datasheet for details.

Returns:

Number:

A bitmask of BMA250E_INT_STATUS_1_BITS_T bits.

getInterruptStatus2

() Number

Return the interrupt status 2 register. See the datasheet for details.

Returns:

Number:

A bitmask of BMA250E_INT_STATUS_2_BITS_T bits.

getInterruptStatus3Bits

() Number

Return the interrupt status 3 register bitfields. See the datasheet for details. The Orientation value is not returned by this function, see getInterruptStatus3Orientation() for that information.

Returns:

Number:

A bitmask of BMA250E_INT_STATUS_3_BITS_T bits ONLY.

getInterruptStatus3Orientation

() BMA250E_ORIENT_T

Return the interrupt status 3 register Orientation value. See the datasheet for details.

Returns:

BMA250E_ORIENT_T:

One of the BMA250E_ORIENT_T values.

enableRegisterShadowing

(
  • shadow
)

Enable shadowing of the accelerometer 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:

  • shadow Boolean

    True to enable axis register shadowing, false otherwise.

enableOutputFiltering

(
  • filter
)

Enable filtering of the accelerometer axis data. init() enables this by default. If disabled, then accelerometer data that is read will be raw and unfiltered (rated R). See the datasheet for details.

Parameters:

  • filter Boolean

    True to enable filtering, false to disable.

setLowPowerMode2

()

Make sure low power mode config (LPM2) is set in case we later go into the low power or suspend power modes. LPM1 mode (the default) requires drastically slowed register writes which we cannot handle.

installISR

(
  • intr
  • gpio
  • level
  • isr
  • arg
)

install an interrupt handler.

Parameters:

  • intr BMA250E_INTERRUPT_PINS_T

    One of the BMA250E_INTERRUPT_PINS_T values specifying which interrupt pin you are installing.

  • gpio Number

    GPIO pin to use as interrupt pin.

  • level Mraa::Edge

    The interrupt trigger level (one of mraa::Edge values). Make sure that you have configured the interrupt pin properly for whatever level you choose.

  • isr Function

    The interrupt handler, accepting a void * argument.

  • arg Void *

    The argument to pass the the interrupt handler.

uninstallISR

(
  • intr
)

uninstall a previously installed interrupt handler

Parameters:

  • intr BMA250E_INTERRUPT_PINS_T

    One of the BMA250E_INTERRUPT_PINS_T values specifying which interrupt pin you are removing.

readReg

(
  • reg
)
Number

Read a register.

Parameters:

  • reg Number

    The register to read.

Returns:

Number:

The value of the register.

readRegs

(
  • reg
  • buffer
  • len
)
Number

Read contiguous registers into a buffer.

Parameters:

  • reg Number

    undefined

  • buffer Uint8_t *

    The buffer to store the results.

  • len Number

    The number of registers to read.

Returns:

Number:

The number of bytes read.

writeReg

(
  • reg
  • val
)

Write to a register.

Parameters:

  • reg Number

    The register to write to.

  • val Number

    The value to write.