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.

// 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.

let signal = mbl_mw_mag_bmm150_get_b_field_data_signal(device.board)!
mbl_mw_datasignal_subscribe(signal, bridge(obj: self)) { (context, obj) in
    let mag: MblMwCartesianFloat = obj!.pointee.valueAs()
    print(Double(mag.x),Double(mag.y),Double(mag.z))
}
mbl_mw_mag_bmm150_enable_b_field_sampling(device.board)
mbl_mw_mag_bmm150_start(device.board)

// TIME PASSES

mbl_mw_mag_bmm150_stop(device.board)
mbl_mw_mag_bmm150_disable_b_field_sampling(device.board)
mbl_mw_datasignal_unsubscribe(signal)