MicroPython BMA220 Library¶
bma220¶
MicroPython Driver for the Bosch BMA220 Accelerometer
Author(s): Jose D. Montoya
-
class micropython_bma220.bma220.BMA220(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 sensorfrom machine import Pin, I2C from micropython_bma220 import bma220Once this is done you can define your
machine.I2Cobject and define your sensor objecti2c = I2C(1, sda=Pin(2), scl=Pin(3)) bma220 = bma220.BMA220(i2c)Now you have access to the attributes
accx, accy, accz = bma220.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 acceleration : tuple[float, float, float]¶
Acceleration :return: acceleration x, y, z in m/s²
- 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