pyupm_bma220 module

class pyupm_bma220.BMA220(bus=0, addr=10)[source]

Bases: object

API for the BMA220 3-axis Accelerometer.

ID: bma220

Name: Digital Triaxial Acceleration Sensor

Category: accelerometer

Manufacturer: bosch dfrobot

Connection: i2c gpio

Link:http://www.dfrobot.com/index.php?route=product/product&product_id=1085 The BMA220 is a low cost, very small 3-axis accelerometer with 6 bits of resolution. It can also detect orientation and tap events.

The BMA220 has a linear acceleration full scale of 2g/4g/8g/16g.

While not all of the functionality of this device is supported initially, methods and register definitions are provided that should allow an end user to implement whatever features are required.

This driver was developed on a DFRobot BMA (Tiny).

C++ includes: bma220.hpp

CONFIG2_LAT_0_25 = 1
CONFIG2_LAT_0_5 = 2
CONFIG2_LAT_1 = 3
CONFIG2_LAT_2 = 4
CONFIG2_LAT_4 = 5
CONFIG2_LAT_8 = 6
CONFIG2_LAT_PERM = 7
CONFIG2_LAT_UNLATCH = 0
CONFIG_ORI_DN_LAND_LEFT = 6
CONFIG_ORI_DN_LAND_RIGHT = 7
CONFIG_ORI_DN_PORT_UPRIGHT = 4
CONFIG_ORI_DN_PORT_UPSIDE_DOWN = 5
CONFIG_ORI_UP_LAND_LEFT = 2
CONFIG_ORI_UP_LAND_RIGHT = 3
CONFIG_ORI_UP_PORT_UPRIGHT = 0
CONFIG_ORI_UP_PORT_UPSIDE_DOWN = 1
ENABLE_CONFIG2_HIGH_X = 4
ENABLE_CONFIG2_HIGH_Y = 2
ENABLE_CONFIG2_HIGH_Z = 1
ENABLE_CONFIG2_LAT_INT0 = 16
ENABLE_CONFIG2_LAT_INT1 = 32
ENABLE_CONFIG2_LAT_INT2 = 64
ENABLE_CONFIG2_LOW = 8
ENABLE_CONFIG2_RESET_INT = 128
ENABLE_CONFIG3_SLEEP_DUR0 = 8
ENABLE_CONFIG3_SLEEP_DUR1 = 16
ENABLE_CONFIG3_SLEEP_DUR2 = 32
ENABLE_CONFIG3_SLEEP_EN = 64
ENABLE_CONFIG3_X_CHAN = 4
ENABLE_CONFIG3_Y_CHAN = 2
ENABLE_CONFIG3_Z_CHAN = 1
ENABLE_CONFIG_DATA = 128
ENABLE_CONFIG_ORIENT = 64
ENABLE_CONFIG_SLOPE_X = 32
ENABLE_CONFIG_SLOPE_Y = 16
ENABLE_CONFIG_SLOPE_Z = 8
ENABLE_CONFIG_TT_X = 4
ENABLE_CONFIG_TT_Y = 2
ENABLE_CONFIG_TT_Z = 1
FILTER_CONFIG_125HZ = 3
FILTER_CONFIG_1KHZ = 0
FILTER_CONFIG_250HZ = 2
FILTER_CONFIG_32HZ = 5
FILTER_CONFIG_500HZ = 1
FILTER_CONFIG_64HZ = 4
FILTER_CONFIG_FILTER0 = 1
FILTER_CONFIG_FILTER1 = 2
FILTER_CONFIG_FILTER2 = 4
FILTER_CONFIG_FILTER3 = 8
FILTER_CONFIG_SERIAL_HIGH_BW = 128
FSL_RANGE_16G = 3
FSL_RANGE_2G = 0
FSL_RANGE_4G = 1
FSL_RANGE_8G = 2
H_HYST_DUR_HIGH_DUR0 = 1
H_HYST_DUR_HIGH_DUR1 = 2
H_HYST_DUR_HIGH_DUR2 = 4
H_HYST_DUR_HIGH_DUR3 = 8
H_HYST_DUR_HIGH_DUR4 = 16
H_HYST_DUR_HIGH_DUR5 = 32
H_HYST_DUR_HIGH_HY1 = 64
H_HYST_DUR_HIGH_HY2 = 128
I2C_WATCHDOG_SPI3 = 1
I2C_WATCHDOG_TO_EN = 4
I2C_WATCHDOG_TO_SEL = 2
INT_STATUS1_FIRST_X = 8
INT_STATUS1_FIRST_Y = 4
INT_STATUS1_FIRST_Z = 2
INT_STATUS1_ORIENT0 = 16
INT_STATUS1_ORIENT1 = 32
INT_STATUS1_ORIENT2 = 64
INT_STATUS1_ORIENT_INT = 128
INT_STATUS1_SIGN = 1
INT_STATUS2_DATA = 2
INT_STATUS2_HIGH = 4
INT_STATUS2_LOW = 8
INT_STATUS2_SLOPE = 1
INT_STATUS2_TAP = 16
L_HYST_DUR_LOW_DUR0 = 1
L_HYST_DUR_LOW_DUR1 = 2
L_HYST_DUR_LOW_DUR2 = 4
L_HYST_DUR_LOW_DUR3 = 8
L_HYST_DUR_LOW_DUR4 = 16
L_HYST_DUR_LOW_DUR5 = 32
L_HYST_DUR_LOW_HY1 = 64
L_HYST_DUR_LOW_HY2 = 128
REG_ACC_X = 4
REG_ACC_Y = 6
REG_ACC_Z = 8
REG_CHIPID = 0
REG_ENABLE_CONFIG = 26
REG_ENABLE_CONFIG2 = 28
REG_ENABLE_CONFIG3 = 30
REG_FILTER_CONFIG = 32
REG_H_HYST_DUR = 10
REG_I2C_WATCHDOG = 46
REG_INT_STATUS1 = 22
REG_INT_STATUS2 = 24
REG_L_HYST_DUR = 14
REG_REVISIONID = 2
REG_SBIST_FSL_CONFIG = 34
REG_SBIST_FSL_RANGE0 = 1
REG_SBIST_FSL_RANGE1 = 2
REG_SBIST_FSL_SBIST0 = 4
REG_SBIST_FSL_SBIST1 = 8
REG_SBIST_FSL_SBIST_SIGN = 16
REG_SLOPE_CONFIG = 18
REG_SOFTRESET = 50
REG_SUSPEND = 48
REG_TAP_CONFIG = 16
REG_TAP_CONFIG2 = 20
REG_THRESHOLD = 12
SBIST_OFF = 0
SBIST_X = 1
SBIST_Y = 2
SBIST_Z = 3
SLEEP_DUR_100MS = 4
SLEEP_DUR_10MS = 1
SLEEP_DUR_1S = 6
SLEEP_DUR_25MS = 2
SLEEP_DUR_2MS = 0
SLEEP_DUR_2S = 7
SLEEP_DUR_500MS = 5
SLEEP_DUR_50MS = 3
SLOPE_CONFIG_DUR0 = 1
SLOPE_CONFIG_DUR1 = 2
SLOPE_CONFIG_FILTER = 64
SLOPE_CONFIG_ORIENT_EX = 128
SLOPE_CONFIG_THRESH0 = 4
SLOPE_CONFIG_THRESH1 = 8
SLOPE_CONFIG_THRESH2 = 16
SLOPE_CONFIG_THRESH3 = 32
TAP_CONFIG2_ORIENT_BLOCK0 = 4
TAP_CONFIG2_ORIENT_BLOCK1 = 8
TAP_CONFIG2_SAMP0 = 1
TAP_CONFIG2_SAMP1 = 2
TAP_CONFIG2_TIP_EN = 16
TAP_CONFIG_DUR0 = 1
TAP_CONFIG_DUR1 = 2
TAP_CONFIG_DUR2 = 4
TAP_CONFIG_FILTER = 128
TAP_CONFIG_THRESH0 = 8
TAP_CONFIG_THRESH1 = 16
TAP_CONFIG_THRESH2 = 32
TAP_CONFIG_THRESH3 = 64
TAP_ORIENT_BLOCK_0 = 0
TAP_ORIENT_BLOCK_2 = 1
TAP_ORIENT_BLOCK_3 = 2
TAP_ORIENT_BLOCK_4 = 3
TAP_SAMP_16 = 3
TAP_SAMP_2 = 0
TAP_SAMP_4 = 1
TAP_SAMP_8 = 2
THRESHOLD_HIGH0 = 1
THRESHOLD_HIGH1 = 2
THRESHOLD_HIGH2 = 4
THRESHOLD_HIGH3 = 8
THRESHOLD_LOW0 = 16
THRESHOLD_LOW1 = 32
THRESHOLD_LOW2 = 64
THRESHOLD_LOW3 = 128
enableAxes(xEn, yEn, zEn)[source]

bool enableAxes(bool xEn, bool yEn, bool zEn)

enable or disable axis channels

xEn: true to enable the axis, false otherwise

yEn: true to enable the axis, false otherwise

zEn: true to enable the axis, false otherwise

true if successful

enableSlopeFilter(filt)[source]

bool enableSlopeFilter(bool filt)

enable or disable slope filtering

filt: true to enable filtering, false otherwise

true if successful

enableTapFilter(filt)[source]

bool enableTapFilter(bool filt)

unable to disable tap filtering

filt: true to enable, false otherwise

true if successful

getAccelerometer(*args)[source]

std::vector< float > getAccelerometer()

get the accelerometer values in gravities

std::vector containing X, Y, Z acceleration values

getChipID()[source]

uint8_t getChipID()

return the chip ID

the chip ID (usually 0xdd)

getChipRevision()[source]

uint8_t getChipRevision()

return the chip revision

the chip revision (usually 0x00)

getInterruptEnables1()[source]

uint8_t getInterruptEnables1()

return the enabled interrupts for events in interrupt config register 1

bitmask of ENABLE_CONFIG_BITS_T values

getInterruptEnables2()[source]

uint8_t getInterruptEnables2()

return the enabled interrupts for events in interrupt config register 2

bitmask of ENABLE_CONFIG2_BITS_T values

getInterruptStatus1()[source]

uint8_t getInterruptStatus1()

return a bitmask of the interrupt status 1 register

bitmask of INT_STATUS1_BITS_T bits (minus the orient value)

getInterruptStatus2()[source]

uint8_t getInterruptStatus2()

return a bitmask of the interrupt status 2 register

bitmask of INT_STATUS2_BITS_T bits

getOrient()[source]

BMA220::CONFIG_ORIENT_T getOrient()

return the orient value from the interrupt status 1 register

one of the CONFIG_ORIENT_T values

get_gpioIntr()[source]

mraa::Gpio * get_gpioIntr()

installISR(gpio, level, isr, arg)[source]

void installISR(int gpio, mraa::Edge level, void(*isr)(void *), void *arg)

install an interrupt handler.

gpio: gpio pin to use as interrupt pin

level: 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: the interrupt handler, accepting a void * argument

arg: the argument to pass the the interrupt handler

readReg(reg)[source]

uint8_t readReg(uint8_t reg)

read a register

reg: the register to read

the value of the register

resetInterrupts()[source]

bool resetInterrupts()

reset the interrupt controller. This should be called after any changes are made to interrupt configuration, or to reset interrupts if latched interrupts have been enabled and an interrupt has occurred..

true if successful

setAccelerometerScale(scale)[source]

bool setAccelerometerScale(FSL_RANGE_T scale)

set the scaling mode of the accelerometer (2g/4g/8g/16g)

scale: one of the FSL_RANGE_T values

true if successful, false otherwise

setFilterConfig(filter)[source]

bool setFilterConfig(FILTER_CONFIG_T filter)

set the filtering configuration

filter: one of the FILTER_CONFIG_T values

true if successful

setHighGDuration(dur)[source]

bool setHighGDuration(uint8_t dur)

specify the sample duration for high G detection

dur: the number of samples (depends on bandwidth)

true if successful

setHighGHysteresis(hyst)[source]

bool setHighGHysteresis(uint8_t hyst)

specify the hysteresis for high G detection

hyst: 2 bit hysteresis value

true if successful

setHighGThreshold(thresh)[source]

bool setHighGThreshold(uint8_t thresh)

specify the threshold for high G detection

thresh: see the datasheet

true if successful

setInterruptEnables1(bits)[source]

bool setInterruptEnables1(uint8_t bits)

enable interrupts for events in interrupt config register 1

bits: bitmask of ENABLE_CONFIG_BITS_T values

true if successful

setInterruptEnables2(bits)[source]

bool setInterruptEnables2(uint8_t bits)

enable interrupts for events in interrupt config register 2

bits: bitmask of ENABLE_CONFIG2_BITS_T values

true if successful

setInterruptLatch(lat)[source]

bool setInterruptLatch(CONFIG2_LAT_T lat)

configure interrupt latching behavior

lat: one of the CONFIG2_LAT_T values

true if successful

setLowGDuration(dur)[source]

bool setLowGDuration(uint8_t dur)

specify the sample duration for low G detection

dur: the number of samples (depends on bandwidth)

true if successful

setLowGHysteresis(hyst)[source]

bool setLowGHysteresis(uint8_t hyst)

specify the hysteresis for low G detection

hyst: 2 bit hysteresis value

true if successful

setLowGThreshold(thresh)[source]

bool setLowGThreshold(uint8_t thresh)

specify the threshold for low G detection

thresh: see the datasheet

true if successful

setSerialHighBW(high)[source]

bool setSerialHighBW(bool high)

enable or disable high bandwidth serial access (1Khz). This essentially disables filtering and makes the raw unfiltered data available in the axis registers.

high: true to enable high bw access, false otherwise

true if successful

setSleepDuration(dur)[source]

bool setSleepDuration(SLEEP_DUR_T dur)

when in low power (sleep) mode, specify how often the device wakes up to acquire samples.

dur: one of the SLEEP_DUR_T values

true if successful

setSlopeDuration(dur)[source]

bool setSlopeDuration(uint8_t dur)

specify the sample duration for slope detection

dur: the number of samples (depends on bandwidth)

true if successful

setSlopeThreshold(thresh)[source]

bool setSlopeThreshold(uint8_t thresh)

specify the threshold for slope detection

thresh: see the datasheet

true if successful

setTapDuration(dur)[source]

bool setTapDuration(uint8_t dur)

specify the sample duration for tap detection

dur: the number of samples (depends on bandwidth)

true if successful

setTapThreshold(thresh)[source]

bool setTapThreshold(uint8_t thresh)

specify the threshold for tap detection

thresh: see the datasheet

true if successful

sleep(enable)[source]

bool sleep(bool enable)

place the device into, or take the device out of low power mode. See the datasheet for information on how low power mode is implemented on this device.

enable: true to set low power mode, false otherwise

true if successful

softReset()[source]

uint8_t softReset()

place the device into, or take the device out of soft reset mode

0x00 if the device was in active mode, 0xff if the device was in soft reset mode

suspend()[source]

uint8_t suspend()

place the device into, or take the device out of suspend mode

0x00 if the device was in active mode, 0xff if the device was in suspend mode

uninstallISR()[source]

void uninstallISR()

uninstall a previously installed interrupt handler

update()[source]

void update()

update the accelerometer values

writeReg(reg, val)[source]

bool writeReg(uint8_t reg, uint8_t val)

write to a register

reg: the register to write to

val: the value to write

true if successful, false otherwise