sts1_sensors.edu.BMM150

Module Contents

class PowerMode

Initialize self. See help(type(self)) for accurate signature.

class PresetMode

Initialize self. See help(type(self)) for accurate signature.

class PowerControl

Initialize self. See help(type(self)) for accurate signature.

class bmm150_mag_data
class bmm150_raw_mag_data
class bmm150_trim_registers
class bmm150_settings
class BMM150(preset_mode=1, address=None, bus=None)

Geomagnetic sensor.

Builds on top of the library bmm150. by Ulysse Moreau.

Parameters:
  • preset_mode (int) – Integer, either 1 (Low Power), 2 (Regular), 3 (High Accuracy) or 4 (Enhanced). Defaults to 1.

  • address (hexadecimal) – Physical address of the sensor on the board (see i2cdetect command). Allowed values: [0x10, 0x11, 0x12, 0x13]. If None, the environment variable STS1_SENSOR_ADDRESS_BMM150 will be used. If environment variable is not found, 0x10 will be used.

  • bus (SMBus) – A SMBus object. If None, this class will generate its own, defaults to None.

Example:

mag = BMM150()
x, y, z = mag.get_magnetic_data()
print(f"{x=:.2f} µT, {y=:.2f} µT, {z=:.2f} µT")
print(f"Heading: {mag.get_heading():.2f}°")
property address
set_bits_pos0(reg_data, bitname_mask, data)
get_bits(reg_data, bitname_mask, bitname_pos)
set_bits(reg_data, bitname_mask, bitname_pos, data)
set_op_mode(pwr_mode)

Sets power mode

Args:

pwr_mode (PowerMode): Desired power mode

Parameters:

pwr_mode (PowerMode)

Return type:

None

set_presetmode(preset_mode)

Sets preset mode

Args:

preset_mode (PresetMode): Desired preset mode

Parameters:

preset_mode (PresetMode)

suspend_to_sleep_mode()
soft_reset()

Soft resets the module.

read_trim_registers()

Reads the trim registers for calibration.

read_raw_mag_data()

Reads registers containing X, Y, Z and R data from the device.

Returns:

tuple[int, int, int, int]: A tuple containing raw (X, Y, Z, R) data.

Return type:

Tuple[int, int, int, int]

read_mag_data()

Reads and compensate the magnetic values for X, Y and Z.

Returns:

tuple[int, int, int]: A tuple containing raw (X, Y, Z) compensated data.

Return type:

Tuple[int, int, int]

get_raw_magnetic_data()

Get raw magnetic data in µT.

get_magnetic_data()

Get magnetic data in µT.

get_heading()

Get heading direction in degrees. Uses only x and y for calculation (z is ignored).