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
BMA220
class. First you will need to import the libraries to use the sensorfrom machine import Pin, I2C from micropython_bma220 import bma220
Once this is done you can define your
machine.I2C
object 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_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 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_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 secondsbma220.LATCH_FOR_050S
0b010
0.5 secondsbma220.LATCH_FOR_1S
0b011
1 secondbma220.LATCH_FOR_2S
0b100
2 secondsbma220.LATCH_FOR_4S
0b101
4 secondsbma220.LATCH_FOR_8S
0b110
8 secondsbma220.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