Magnetometer

A magnetometer is a device for detecting and measuring magnetic fields (in Teslas). The device can be used in conjunction with a 3-axis accelerometer to produce orientation independent accurate compass heading information.

MetaWear CPro, MMC, and MMR boards have a BMM150 geomagnetic sensor for sensing magnetic fields.

Functions communicating with the magnetometer are defined in the magnetometer_bmm150.h.

Power Modes

The BMM150 magnetometer has 4 recommended power modes:

Setting

ODR

Average Current

Noise

LOW_POWER

10Hz

170µA

1.0µT (xy axis), 1.4µT (z axis)

REGULAR

10Hz

0.5mA

0.6µT

ENHANCED_REGULAR

10Hz

0.8mA

0.5µT

HIGH_ACCURACY

20Hz

4.9mA

0.3µT

Constants identifying these power modes are defined by the MblMwMagBmm150Preset enum. For most use cases, MWL_MW_MAG_BMM_150_PP_LOW_POWER is the recommended power mode.

#include "metawear/sensor/magnetometer_bmm150.h"

void setup_magnetometer(MblMwMetaWearBoard* board) {
    // Use low power mode
    mbl_mw_mag_bmm150_set_power_preset(board, MWL_MW_MAG_BMM_150_PP_LOW_POWER);
}

B Field Sampling

B field sampling measures the magnetic field strength for the XYZ directions. To enable B field sampling, call mbl_mw_mag_bmm150_enable_b_field_sampling before starting the magnetometer.

Field strength is represented by the MblMwCartesianFloat struct and is in units of micro Teslas (µT). The x, y, and z fields contain the B field strength in that direction.

#include "metawear/core/datasignal.h"
#include "metawear/core/types.h"

#include "metawear/sensor/magnetometer_bmm150.h"

void bfield_stream(MblMwMetaWearBoard* board) {
    static auto data_handler = [](const MblMwData* data) -> void {
        // Cast value to MblMwCartesianFloat*
        auto bfield = (MblMwCartesianFloat*) data->value;
        printf("(%.3f, %.3f, %.3f)uT\n", bfield ->x, bfield->y, bfield->z);
    };

    auto bfield_signal = mbl_mw_mag_bmm150_get_b_field_data_signal(board);
    mbl_mw_datasignal_subscribe(bfield_signal, data_handler);

    mbl_mw_mag_bmm150_enable_b_field_sampling(board);
    mbl_mw_mag_bmm150_start(board);
}