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:¶
- Raises:¶
RuntimeError – if the sensor is not found
Quickstart: Importing and using the device
Here is an example of using the
BMA220class. First you will need to import the libraries to use the sensorimport board import bma220Once this is done you can define your
board.I2Cobject and define your sensor objecti2c = 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_20b00bma220.ACC_RANGE_40b01bma220.ACC_RANGE_80b10bma220.ACC_RANGE_160b11
- 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_32HZ0x05bma220.ACCEL_64HZ0x04bma220.ACCEL_125HZ0x03bma220.ACCEL_250HZ0x02bma220.ACCEL_500HZ0x01bma220.ACCEL_1000HZ0x00
- 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_modeto be either unlatched (‘000’) or latched permanently (‘111’) or have different latching times.Mode
Value
bma220.UNLATCHED0b000bma220.LATCH_FOR_025S0b0010.25 secondsbma220.LATCH_FOR_050S0b0100.5 secondsbma220.LATCH_FOR_1S0b0111 secondbma220.LATCH_FOR_2S0b1002 secondsbma220.LATCH_FOR_4S0b1014 secondsbma220.LATCH_FOR_8S0b1108 secondsbma220.LATCHED0b111
- property sleep_duration : str¶
Sensor sleep_duration.
Mode
Value
bma220.SLEEP_2MS0b000bma220.SLEEP_10MS0b001bma220.SLEEP_25MS0b010bma220.SLEEP_50MS0b011bma220.SLEEP_100MS0b100bma220.SLEEP_500MS0b101bma220.SLEEP_1S0b110bma220.SLEEP_2S0b111
- 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_enabledand by enabling the data ready interrupt (or any other interrupt, see chapter 5 in the datasheet)Mode
Value
bma220.SLEEP_DISABLED0b0bma220.SLEEP_ENABLED0b1
- 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_DISABLED0b0bma220.X_ENABLED0b1
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_durationof consecutive slope data points is above the slope thresholdslope_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 thresholdslope_thresholdforslope_thresholdconsecutive times. As soon as all the enabled channels fall or stay below this threshold forslope_thresholdconsecutive 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_durationof consecutive slope data points is above the slope thresholdslope_threshold. define the number of consecutive slope data points aboveslope_thresholdwhich are required to set the interrupt:Mode
Value
bma220_slope.SLOPE_DURATION_10b00bma220_slope.SLOPE_DURATION_20b01bma220_slope.SLOPE_DURATION_30b10bma220_slope.SLOPE_DURATION_40b11
- property slope_filter : int¶
Defines whether filtered or unfiltered acceleration data should be used (evaluated)
Mode
Value
bma220_slope.FILTER_DISABLED0b0bma220_slope.FILTER_ENABLED0b1
- property slope_sign : str¶
Sensor slope_sign
Mode
Value
bma220_slope.SLOPE_SIGN_POSITIVE0b00bma220_slope.SLOPE_SIGN_NEGATIVE0b01
- property slope_threshold : int¶
the interrupt is only generated if a certain number
slope_durationof consecutive slope data points is above the slope thresholdslope_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_DISABLED0b0bma220_slope.SLOPE_X_ENABLED0b1
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_thresholdis 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 delaytt_durationbetween 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 withintt_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_ENABLED0b00Double Tap enabledbma220_tap_sensing.ST_ENABLED0b01Single Tap enabled
- property tt_duration : str¶
Sensor tt_duration
Mode
Value
bma220.TIME_50MS0B000bma220.TIME_105MS0B001bma220.TIME_150MS0B010bma220.TIME_219MS0B011bma220.TIME_250MS0B100bma220.TIME_375MS0B101bma220.TIME_500MS0B110bma220.TIME_700MS0B111
- property tt_filter : int¶
Defines whether filtered or unfiltered acceleration data should be used (evaluated)
Mode
Value
bma220_tap_sensing.FILTER_DISABLED0b0bma220_tap_sensing.FILTER_ENABLED0b1
- property tt_sign : str¶
Sensor tt_sign
Mode
Value
bma220_tap_sensing.TT_SIGN_POSITIVE0b00bma220_tap_sensing.TT_SIGN_NEGATIVE0b01
- 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_DISABLED0b0bma220_tap_sensing.TT_X_ENABLED0b1
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_enabledis 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.MODE00b00interrupt blocking is completely disabled.bma220_orientation.MODE10b01no 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.MODE20b01no 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.MODE30b01no 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_DISABLED0b0bma220_orientation.ORIENTATION_ENABLED0b1