Skip to content
Snippets Groups Projects

feat(bma): Add initial support for BMA400

Open Michael Meinel requested to merge led02/firmware:led02/bma into master
11 files
+ 1138
0
Compare changes
  • Side-by-side
  • Inline
Files
11
+ 198
0
``bma400`` - Accelerometer
==========================
This module gives access to the BMA400 sensor. It tries to acquire a lock so it can
only be accessed from one task at a time.
.. py:class:: bma400.BMA400([power_mode=bma400.PowerMode.LowPower,] [enable_ints=[],] **kwargs)
Interface for the BMA400 sensor.
This class wrapps the low-level interface to be more usable. Basically, it allows
to configure the sensor, select enabled interrupts and read data values.
:param bma400.PowerMode power_mode: Select the power mode to initialize the BMA400 with.
:param List[bma400.IntType] enable_ints: Select the interrupts to be enabled.
:param kwargs: Additional keyword parameters are passed to :py:meth:`bma400.BMA400.configure`
to configure the sensor at initialization.
You should use the attribute names of :py:class:`bma400.ConfigType` as keys.
.. py:method:: configure(conf, **kwargs)
Set a configuration on the BMA400.
:param bma400.ConfigType conf: The configuration that should be set.
:param kwargs: The parameters that should be set on the configuration. The names are
the same as defined in the BMA400 SDK.
Example:
.. code-block:: python
bma = bma400.BMA400()
bma.configure(bma400.ConfigType.Accel,
odr=bma400.ODR.at_200Hz,
range=bma400.Range.max_4G,
data_src=bma400.AccelSrc.Filt1,
filt1_bw=bma400.Filt1Bw.bw_0)
.. py:method:: set_power_mode(power_mode)
Set the current power mode of the sensor.
:param bma400.PowerMode power_mode: The power mode that should be used.
.. py:method:: enable_int(*ints)
Enable selected interrupts.
:param bma400.IntType ints: The interrupts to be enabled.
.. py:method:: disable_int(*ints)
Disable selected interrupts.
:param bma400.IntType ints: The interrupts to be disabled.
.. py:method:: get_accel()
Get acceleration vector.
:return: Tuple containing ``x``, ``y``, and ``z`` acceleration.
.. py:method:: get_interrupts([select=None])
Get active interrupts.
:param Set[bma400.Int] select: Only check for the given interrupts.
:return: A set with all currently active :py:class:`bma400.Int` (filtered by ``select``).
Configuration values and interrupts
-----------------------------------
.. py:class:: bma400.PowerMode
Constants that define the power mode to be set.
Possbile values: ``Sleep``, ``LowPower``, ``Normal``
.. py:class:: bma400.ConfigType
Constants to select a configuration to be set.
.. py:attribute:: Accel
Select acceleration configuration.
.. py:attribute:: Tap
Select tap detection configuration.
.. py:attribute:: Orirent
Select orientation change detection configuration.
.. py:class:: bma400.ODR
Supported values: ``at_12_5Hz``, ``at_25Hz``, ``at_50Hz``, ``at_100Hz``,
``at_200Hz``, ``at_400Hz``, ``at_800Hz``
.. py:class:: bma400.Range
Supported values: ``max_2G``, ``max_4G``, ``max_8G``, ``max_16G``
.. py:class:: bma400.IntChannel
Supported values: ``UnmapIntPins``, ``Channel1``, ``Channel2``, ``MapBothIntPins``
.. py:class:: bma400.TapAxis
Supported values: ``X``, ``Y``, ``Z``
.. py:class:: bma400.Quiet
Supported values for single tap: ``ST_60_Samples``, ``ST_80_Samples``,
``ST_100_Samples``, ``ST_120_Samples``
Supported values for double tap: ``DT_4_Samples``, ``DT_8_Samples``,
``DT_12_Samples``, ``DT_16_Samples``
.. py:class:: bma400.AccelSrc
Supported values: ``Filt1``, ``Filt2``, ``FiltLP``
.. py:class:: bma400.Filt1Bw
Supported values: ``bw_0``, ``bw_1``
.. py:class:: bma400.IntType
Select interrupt types to be generated.
.. py:attribute:: Orient
Enable interrupt when orientation has changed.
.. py:attribute:: SingleTap
Enable interrupt on single tap.
.. py:attribute:: DoubleTap
Enable interrupt on double tap.
.. py:attribute:: Steps
Enable step counter interrupts.
.. py:class:: bma400.Int
This class provides the mask for emitted interrupts. These values are also
returned by :py:meth:`bma400.BMA400.get_interrupts`.
Supported values: ``Empty``, ``WakeUp``, ``Orient``, ``Steps``, ``SingleTap``,
``DoubleTap``
.. py:attribute:: All
A set with all available interrutps. Useful for filtering with
:py:meth:`bma400.BMA400.get_interrupts`.
Examples
--------
Wait for a double-tap:
.. code-block:: python
import utime
import bma400
bma = bma400.BMA400(power_mode=bma400.PowerMode.Normal,
enable_ints=[bma400.IntType.DoubleTap],
Accel={"odr": bma400.ODR.at_200Hz,
"range": bma400.Range.max_4G,
"data_src": bma400.AccelSrc.Filt1,
"filt1_bw": bma400.Filt1Bw.bw_1},
Tap={"int_chan": bma400.IntChannel.UnmapIntPins,
"axes_sel": bma400.TapAxis.Z,
"sensitivity": 0})
while bma400.Int.DoubleTap not in bma.get_interrupts():
utime.sleep_ms(10)
Loading