BMA220 Library

bma220

BMA220 Bosch Circuitpython Driver library

  • Author(s): Jose D. Montoya

class bma220.bma220.BMA220(i2c_bus: busio.I2C, address: int = 0x0A)[source]

Driver for the BMA220 Sensor connected over I2C.

Parameters:
i2c_bus : I2C

The I2C bus the BMA220 is connected to.

address : int

The I2C device address. Defaults to 0x0A

Raises:

RuntimeError – if the sensor is not found

Quickstart: Importing and using the device

Here is an example of using the BMA220 class. First you will need to import the libraries to use the sensor

import board
import bma220

Once this is done you can define your board.I2C object and define your sensor object

i2c = board.I2C()  # uses board.SCL and board.SDA
bma220 = bma220.BMA220(i2c)

Now you have access to the attributes

accx, accy, accz = bma.acceleration
property acc_range : str

The BMA220 has four different range settings for the full scale acceleration range. In dependence of the use case always the lowest full scale range with the maximum resolution should be selected. Please refer to literature to find out, which full scale acceleration range, which sensitivity or which resolution is the ideal one.

Mode

Value

bma220.ACC_RANGE_2

0b00

bma220.ACC_RANGE_4

0b01

bma220.ACC_RANGE_8

0b10

bma220.ACC_RANGE_16

0b11

property acceleration : tuple[float, float, float]

Acceleration :return: acceleration

property filter_bandwidth : str
The BMA220 has a digital filter that can be configured. To always ensure

an ideal cut off frequency of the filter the BMA220 is adjusting the sample rate automatically.

Mode

Value

bma220.ACCEL_32HZ

0x05

bma220.ACCEL_64HZ

0x04

bma220.ACCEL_125HZ

0x03

bma220.ACCEL_250HZ

0x02

bma220.ACCEL_500HZ

0x01

bma220.ACCEL_1000HZ

0x00

property latched_mode : str

Sensor latched_mode

The interrupt controller can be used in two modes

  • Latched mode: Once one of the configured interrupt conditions applies, the INT pin is asserted and must be reset by the external master through the digital interface.

  • Non-Latched mode: The interrupt controller clears the INT signal once the interrupt condition no longer applies.

The interrupt output can be programmed by latched_mode to be either unlatched (‘000’) or latched permanently (‘111’) or have different latching times.

Mode

Value

bma220.UNLATCHED

0b000

bma220.LATCH_FOR_025S

0b001 0.25 seconds

bma220.LATCH_FOR_050S

0b010 0.5 seconds

bma220.LATCH_FOR_1S

0b011 1 second

bma220.LATCH_FOR_2S

0b100 2 seconds

bma220.LATCH_FOR_4S

0b101 4 seconds

bma220.LATCH_FOR_8S

0b110 8 seconds

bma220.LATCHED

0b111

property sleep_duration : str

Sensor sleep_duration.

Mode

Value

bma220.SLEEP_2MS

0b000

bma220.SLEEP_10MS

0b001

bma220.SLEEP_25MS

0b010

bma220.SLEEP_50MS

0b011

bma220.SLEEP_100MS

0b100

bma220.SLEEP_500MS

0b101

bma220.SLEEP_1S

0b110

bma220.SLEEP_2S

0b111

property sleep_enabled : str

The BMA220 supports a low-power mode. In this low-power mode, the chip wakes up periodically, enables the interrupt controller and goes back to sleep if no interrupt has occurred. The low-power mode can be enabled by setting sleep_enabled and by enabling the data ready interrupt (or any other interrupt, see chapter 5 in the datasheet)

Mode

Value

bma220.SLEEP_DISABLED

0b0

bma220.SLEEP_ENABLED

0b1

property x_enabled : str

Sensor x_enabled In order to optimize further power consumption of the BMA220, data evaluation of individual axes can be deactivated. Per default, all three axes are active.

Mode

Value

bma220.X_DISABLED

0b0

bma220.X_ENABLED

0b1

property y_enabled : str

Sensor y_enabled In order to optimize further power consumption of the BMA220, data evaluation of individual axes can be deactivated. Per default, all three axes are active.

Mode

Value

bma220.Y_DISABLED

0b0

bma220.Y_ENABLED

0b1

property z_enabled : str

Sensor z_enabled In order to optimize further power consumption of the BMA220, data evaluation of individual axes can be deactivated. Per default, all three axes are active.

Mode

Value

bma220.Z_DISABLED

0b0

bma220.Z_ENABLED

0b1

bma220_slope

BMA220 Slope Bosch Circuitpython Driver library

  • Author(s): Jose D. Montoya

class bma220.bma220_slope.BMA220_SLOPE(i2c_bus)[source]

The any-motion detection uses the slope between two successive acceleration signals to detect changes in motion. It generates an interrupt when a preset threshold slope_th is exceeded. The threshold can be configured between 0 and the maximum acceleration value corresponding to the selected measurement range. The time difference between the successive acceleration signals depends on the bandwidth of the configurable low pass filter and corresponds roughly to 1/(2*bandwidth) (Δt=1/(2*bw)). In order to suppress failure signals, the interrupt is only generated if a certain number slope_duration of consecutive slope data points is above the slope threshold slope_threshold. If the same number of data points falls below the threshold, the interrupt is reset. The criteria for any-motion detection are fulfilled and the slope interrupt is generated if any of the enabled channels exceeds the threshold slope_threshold for slope_threshold consecutive times. As soon as all the enabled channels fall or stay below this threshold for slope_threshold consecutive times the interrupt is reset unless interrupt signal is latched. The any-motion interrupt logic sends out the signals of the axis that has triggered the interrupt (slope_interrupt_info) and the signal of motion direction (slope_sign). When serial interface is active, any-motion detection logic is enabled if any of the any-motion enable register bits is set. To disable the any-motion interrupt, clear all the axis enable bits. In the dedicated wake-up mode (6.1), all three axes are enabled for any-motion detection whether the individual axis enable bits are set or not.

property slope_duration : int

the interrupt is only generated if a certain number slope_duration of consecutive slope data points is above the slope threshold slope_threshold. define the number of consecutive slope data points above slope_threshold which are required to set the interrupt:

Mode

Value

bma220_slope.SLOPE_DURATION_1

0b00

bma220_slope.SLOPE_DURATION_2

0b01

bma220_slope.SLOPE_DURATION_3

0b10

bma220_slope.SLOPE_DURATION_4

0b11

property slope_filter : int

Defines whether filtered or unfiltered acceleration data should be used (evaluated)

Mode

Value

bma220_slope.FILTER_DISABLED

0b0

bma220_slope.FILTER_ENABLED

0b1

property slope_interrupt : bool

Sensor slope_z_enabled

property slope_interrupt_info : tuple[bool, bool, bool]

Sensor slope_z_enabled

property slope_sign : str

Sensor slope_sign

Mode

Value

bma220_slope.SLOPE_SIGN_POSITIVE

0b00

bma220_slope.SLOPE_SIGN_NEGATIVE

0b01

property slope_threshold : int

the interrupt is only generated if a certain number slope_duration of consecutive slope data points is above the slope threshold slope_threshold. 1 LSB threshold is 1 LSB of acc_data

property slope_x_enabled : str

Sensor slope_x_enabled

Mode

Value

bma220_slope.SLOPE_X_DISABLED

0b0

bma220_slope.SLOPE_X_ENABLED

0b1

property slope_y_enabled : str

Sensor y_enabled

Mode

Value

bma220_slope.SLOPE_Y_DISABLED

0b0

bma220_slope.SLOPE_Y_ENABLED

0b1

property slope_z_enabled : str

Sensor slope_z_enabled

Mode

Value

bma220_slope.SLOPE_Z_DISABLED

0b0

bma220_slope.SLOPE_Z_ENABLED

0b1

bma220_tap_sensing

BMA220 Slope Bosch Circuitpython Driver library

  • Author(s): Jose D. Montoya

class bma220.bma220_tap_sensing.BMA220_TAP(i2c_bus)[source]

Tap sensing has the same functionality as a common laptop touch-pad. If 2 taps occur within a short time, a pre-defined action will be performed by the system. If time between 2 taps is too long or too short no action happens. When the serial interface is activated, tap sensing is enabled if any of the tap sensing enable To disable the tap sensing interrupt, clear all the axis enable bits. When the preset threshold tt_threshold is exceeded, a tap-shock is detected. The tap sensing interrupt is generated only when a second tap is detected within a specified period of time. The slope between two successive acceleration data has to exceed tt_th to detect a tap-shock. The time difference between the two successive acceleration values depends on the bandwidth of the low pass filter. It roughly corresponds to 1/(2*bandwidth). The time delay tt_duration between two taps is typically between 12,5ms and 500ms. The threshold is typically between 0.7g and 1.5g in 2g measurement range. Due to different coupling between sensor and device shell (housing) and different measurement ranges of the sensor these parameters are configurable. The criteria for tap sensing are fulfilled and the interrupt is generated if the second tap occurs after tap_quiet and within tt_duration. The tap sensing direction is determined by the 1st tap. During tt_quiet period (30ms) no taps should occur. If a tap occurs during tap_quiet period it will be connoted as new tap. The slope detection interrupt logic stores the direction of the (first) tap-shock in a status register. This register will be locked for tap_shock=50ms in order to prevent other slopes to overwrite this information. When a tap sensing interrupt is triggered, the signals of the axis that has triggered the interrupt (tt_interrupt_info) and the signal of motion direction (tt_sign) are stored in the corresponding registers. The axis on which the biggest slope occurs will trigger the first tap. The second tap will be triggered by any axis (not necessarily same as the first tap). The property :attr:double_tap_enabled` defines whether single tap or double tap shall be detected. In dedicated tap sensing mode, all three axes are enabled for double tap sensing detection.

property double_tap_enabled : str

Sensor slope_sign

Mode

Value

bma220_tap_sensing.TT_ENABLED

0b00 Double Tap enabled

bma220_tap_sensing.ST_ENABLED

0b01 Single Tap enabled

property tt_duration : str

Sensor tt_duration

Mode

Value

bma220.TIME_50MS

0B000

bma220.TIME_105MS

0B001

bma220.TIME_150MS

0B010

bma220.TIME_219MS

0B011

bma220.TIME_250MS

0B100

bma220.TIME_375MS

0B101

bma220.TIME_500MS

0B110

bma220.TIME_700MS

0B111

property tt_filter : int

Defines whether filtered or unfiltered acceleration data should be used (evaluated)

Mode

Value

bma220_tap_sensing.FILTER_DISABLED

0b0

bma220_tap_sensing.FILTER_ENABLED

0b1

property tt_interrupt : bool

Sensor tt_interrupt

property tt_interrupt_info : tuple[bool, bool, bool]

Sensor tt interrupt info

property tt_sign : str

Sensor tt_sign

Mode

Value

bma220_tap_sensing.TT_SIGN_POSITIVE

0b00

bma220_tap_sensing.TT_SIGN_NEGATIVE

0b01

property tt_threshold : int

define the threshold level of the tap sensing slope. 1 LSB is 2*(LSB of acc_data)

property tt_x_enabled : str

Sensor tt_x_enabled

Mode

Value

bma220_tap_sensing.TT_X_DISABLED

0b0

bma220_tap_sensing.TT_X_ENABLED

0b1

property tt_y_enabled : str

Sensor tt_y_enabled

Mode

Value

bma220_tap_sensing.TT_Y_DISABLED

0b0

bma220_tap_sensing.TT_Y_ENABLED

0b1

property tt_z_enabled : str

Sensor tt_z_enabled

Mode

Value

bma220_tap_sensing.TT_Z_DISABLED

0b0

bma220_tap_sensing.TT_Z_ENABLED

0b1

bma220_orientation

BMA220 Bosch Circuitpython Driver library

  • Author(s): Jose D. Montoya

class bma220.bma220_orientation.BMA220_ORIENTATION(i2c_bus)[source]

The orientation recognition feature informs on an orientation change of the sensor with respect to the gravitational field vector g.

The criteria for portrait/landscape switching is fulfilled and the interrupt is generated when the threshold \(|acc_y/acc_x|=1\) is crossed (i.e. 45°, 135°, 225°, 315°). As soon as the interrupt is set, no new interrupt is generated within the hysteresis level of \(0.66<|acc_y/acc_x|<1.66\) corresponding to a hysteresis interval of 13% around the threshold.

For all states where interrupt blocking through slope detection is used, the interrupt should be re-enabled after the slope has been below the threshold for 3 times in a row. For all states where interrupt blocking is enabled, in order to trigger the interrupt, the orientation should remain the same (stable) until the timer runs out (for ~100ms). The timer starts to count when orientation changes between two consecutive samples. If the orientation changes while timer is still counting, the timer is restarted. The criteria for switching from upward to downward looking fulfilled and the interrupt is generated when the threshold z=0g is crossed. As soon as the interrupt is set, no new interrupt is generated within the hysteresis level of \(-0.4g<z<0.4g\) (i.e. 25° tilt around vertical position). The given specification is valid for an upright mounted PCB. In order to enable also horizontal mounting, x and z axis can be exchanged via the register orient_ex. The x-, y-, z-axis will keep right-hand principle after the exchange. When serial interface is active, orientation detection is enabled if orientation_enabled is set. To disable the orientation interrupt, clear the enable bit. When the dedicated orientation mode is active, the orientation is given by certain output pins corresponding to the above-given definition of the orient register. For details on the output pins see Datasheet section 6.1. In case the orientation interrupt condition has been satisfied and interrupt is not latched, int signal is asserted for one data sampling period unless no-reset condition applies.

property orientation_blocking : str

Sensor orientation_blocking

Mode

Value

bma220_orientation.MODE0

0b00 interrupt blocking is completely disabled.

bma220_orientation.MODE1

0b01 no interrupt is generated, when \(|z|>0.9g\) OR \(|x|+|y|<0.4g\) OR when the slopes of the acceleration data exceeds 0.2g (sample-to-sample).

bma220_orientation.MODE2

0b01 no interrupt is generated, when \(|z|>0.9g\) OR \(|x|+|y|<0.4g\) OR when the slopes of the acceleration data exceeds 0.3g (sample-to-sample).

bma220_orientation.MODE3

0b01 no interrupt is generated, when \(|z|>0.9g\) OR \(|x|+|y|<0.4g\) OR when the slopes of the acceleration data exceeds 0.4g (sample-to-sample).

property orientation_enabled : str

Sensor orientation_enabled. By default, the sensor gets enabled when starting this function

Mode

Value

bma220_orientation.ORIENTATION_DISABLED

0b0

bma220_orientation.ORIENTATION_ENABLED

0b1

property orientation_exchange : str

Sensor orientation_exchange

Mode

Value

bma220_orientation.ORIENTATIONZ

0b0

bma220_orientation.ORIENTATIONX

0b1

property orientation_interrupt : bool

Sensor orientation_interrupt