BMM350 Unit =========== .. sku: U231 .. include:: ../refs/unit.bmm350.ref This library is the driver for BMM350 Unit, a three-axis BMM350 magnetometer. Support the following products: |BMM350 Unit| UiFlow2 Example --------------- Read magnetic field and heading ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Open the |cores3_unit_bmm350_example.m5f2| project in UiFlow2. This example displays the heading, X/Y/Z magnetic field values, and sensor temperature. Tap the calibration button to start collecting samples, rotate the Unit through all three axes, then tap the button again to finish. UiFlow2 Code Block: |example.png| Calibration requires at least 32 samples and at least ``10 uT`` of range on each axis. When the range is insufficient, the example keeps the previous calibration and reports that the calibration should be retried. MicroPython Example ------------------- Read magnetic field and heading ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This example uses CoreS3 Unit A I2C and continuously refreshes the graphical display with the current magnetic field, temperature, and heading. MicroPython Code Block: .. literalinclude:: ../../../examples/unit/bmm350/cores3_unit_bmm350_example.py :language: python :linenos: **API** ------- BMM350Unit ^^^^^^^^^^ .. class:: unit.bmm350.BMM350Unit(i2c, addr=0x14, output_data_rate_hz=100) Create a direct-I2C BMM350 Unit object. :param i2c: Initialized ``machine.I2C`` or ``PAHUBUnit`` object. :param int addr: I2C address. The default is ``0x14``. :param int output_data_rate_hz: Output data rate. Supported values are ``25``, ``50``, ``100``, ``200``, and ``400`` Hz. UIFLOW2: |init.png| .. method:: get_mag() Sample and return the mapped, calibrated magnetic field as ``(x, y, z)`` in ``uT``. :returns: Magnetic field tuple. :rtype: tuple UIFLOW2: |get_mag.png| .. method:: get_temperature() :no-index: Sample and return the sensor temperature in degrees Celsius. :returns: Sensor temperature. :rtype: float UIFLOW2: |get_temperature.png| .. method:: get_heading() :no-index: Sample and return the horizontal heading in the range ``0 <= heading < 360`` degrees. The Unit must be kept level for a meaningful heading. :returns: Horizontal heading in degrees. :rtype: float UIFLOW2: |get_heading.png| .. method:: set_output_data_rate(rate_hz) Set the output data rate to ``25``, ``50``, ``100``, ``200``, or ``400`` Hz. :param int rate_hz: Output data rate in Hz. :rtype: None UIFLOW2: |set_output_data_rate.png| .. method:: get_output_data_rate() Return the configured output data rate in Hz. :returns: Output data rate. :rtype: int UIFLOW2: |get_output_data_rate.png| .. method:: set_axis_mapping(x_axis, y_axis, z_axis) :no-index: Set the output axis order and direction. Each value must be one of ``1``, ``-1``, ``2``, ``-2``, ``3``, or ``-3``; each source axis must be used exactly once. :param int x_axis: Source axis and sign for output X. :param int y_axis: Source axis and sign for output Y. :param int z_axis: Source axis and sign for output Z. :rtype: None UIFLOW2: |set_axis_mapping.png| .. method:: get_axis_mapping() Return the current axis mapping tuple. :returns: Source axis and sign mapping. :rtype: tuple UIFLOW2: |get_axis_mapping.png| .. method:: set_calibration(offsets, scales) Apply three hard-iron offsets in ``uT`` and three positive soft-iron scale factors. Both arguments must contain three finite numeric values. :param tuple offsets: Three hard-iron offsets in ``uT``. :param tuple scales: Three positive soft-iron scale factors. :rtype: None .. method:: get_calibration() Return ``(offsets, scales)`` currently applied in memory. :returns: Current offsets and scale factors. :rtype: tuple .. method:: clear_calibration() Restore zero offsets and unit scale factors. :rtype: None UIFLOW2: |clear_calibration.png| .. method:: start_calibration() Start non-blocking min/max sample collection. Continue calling a sampling getter while rotating the Unit through all three axes. :raises RuntimeError: If calibration is already active. :rtype: None UIFLOW2: |start_calibration.png| .. method:: stop_calibration() Finish sample collection, apply the calculated calibration, and return ``(offsets, scales)``. At least 32 samples and at least ``10 uT`` of range on every axis are required; otherwise ``RuntimeError`` is raised. :returns: Calculated offsets and scale factors. :rtype: tuple UIFLOW2: |stop_calibration.png| .. method:: cancel_calibration() Cancel active sample collection while preserving the previous calibration. :rtype: None UIFLOW2: |cancel_calibration.png| .. method:: is_calibrating() Return ``True`` while calibration samples are being collected. :returns: Whether calibration is active. :rtype: bool UIFLOW2: |is_calibrating.png| .. method:: set_magnetic_declination(angle) Set magnetic declination in degrees. The value is added to subsequent horizontal headings. :param float angle: Magnetic declination in degrees. :rtype: None UIFLOW2: |set_magnetic_declination.png| .. method:: get_magnetic_declination() Return the configured magnetic declination in degrees. :returns: Magnetic declination in degrees. :rtype: float UIFLOW2: |get_magnetic_declination.png|