rm3100

Driver for the RM3100 magnetometer by PNI Sensor Corporation

  • Author(s): Phil Underwood

Implementation Notes

Hardware:

Software and Dependencies:

class rm3100.RM3100_I2C(bus: I2C, i2c_address: int = 32, cycle_count: int = 200, drdy_pin: Pin | None = None)

Driver for RM3100 magnetometer using I2C interface

Parameters:
  • bus (I2C) – The I2C bus the RM3100 is connected to

  • address (int) – The I2C device address. Defaults to 0x20

  • cycle_count (int) – Number of oscillations used to measure magnetic field. Higher numbers give more accurate results, but takes longer to measure. Each cycle takes approximately 36 microseconds. Default is 200.

  • drdy_pin (DigitalInOut) – Pin connected to DRDY of RM3100. DRDY signals when the RM3100 has completed a measurement. If None, the STATUS register will be polled to see when measurement is complete. Default is None

convert_to_microteslas(value: Tuple[int, int, int]) Tuple[float, float, float]

Convert raw reading to reading in µT. This is dependent on the cycle count selected. :param (int, int, int) value: raw reading :return: Reading in µT :rtype: (float,float,float)

get_last_reading() Tuple[int, int, int]

Get the most recent reading

Returns:

Raw magnetic field strength of X,Y,Z axes

Return type:

(int, int, int)

get_next_reading(poll_interval=0.01) Tuple[int, int, int]

Get the next reading, can hang forever if not in continuous mode and start_single_reading has not been called. Can cause increased signal noise if the DRDY pin is not used.

Parameters:

poll_interval (float) – How frequently to check if next reading is ready, default is 0.01s

Returns:

Raw magnetic field strength of X,Y,Z axes

Return type:

(int, int, int)

property magnetic: Tuple[float, float, float]

Magnetic field strength in x,y,z axes, in µT, uses most recent reading

property measurement_complete: bool

Whether the most recent reading has finished.

property measurement_time: float

Time needed to complete a measurement, in seconds

start_continuous_reading(frequency: float = 300)

Start continuously reading at the given frequency. It is recommended that you use the DRDY line to detect measurement occurrences. Polling for new readings frequently can cause electronic noise that adversely affects accuracy.

Parameters:

frequency – Valid frequencies are 600Hz, 300Hz, 150Hz, 75Hz, 37Hz, 18Hz, 9Hz, 4.5Hz, 2.3Hz, 1.2Hz, 0.6Hz, 0.3Hz, 0.015Hz. 0.0075Hz. The nearest valid frequency is selected. Note that the cycle count may override this value, if taking a reading would be longer than the sample interval.

start_single_reading()

Start a single measurement cycle

stop()

Stop continuous mode

class rm3100.RM3100_SPI(bus: SPI, chip_select: DigitalInOut, cycle_count: int = 200, drdy_pin: DigitalInOut | None = None)

Driver for RM3100 magnetometer using I2C interface

Parameters:
  • bus (SPI) – The SPI bus the RM3100 is connected to

  • chip_select (DigitalInOut) – Chip Select

  • cycle_count (int) – Number of oscillations used to measure magnetic field. Higher numbers give more accurate results, but takes longer to measure. Each cycle takes approximately 36 microseconds for 3 axes. Default is 200.

  • drdy_pin (DigitalInOut) – Pin connected to DRDY of RM3100. DRDY signals when the RM3100 has completed a measurement. If None, the STATUS register will be polled to see when measurement is complete. Default is None

convert_to_microteslas(value: Tuple[int, int, int]) Tuple[float, float, float]

Convert raw reading to reading in µT. This is dependent on the cycle count selected. :param (int, int, int) value: raw reading :return: Reading in µT :rtype: (float,float,float)

get_last_reading() Tuple[int, int, int]

Get the most recent reading

Returns:

Raw magnetic field strength of X,Y,Z axes

Return type:

(int, int, int)

get_next_reading(poll_interval=0.01) Tuple[int, int, int]

Get the next reading, can hang forever if not in continuous mode and start_single_reading has not been called. Can cause increased signal noise if the DRDY pin is not used.

Parameters:

poll_interval (float) – How frequently to check if next reading is ready, default is 0.01s

Returns:

Raw magnetic field strength of X,Y,Z axes

Return type:

(int, int, int)

property magnetic: Tuple[float, float, float]

Magnetic field strength in x,y,z axes, in µT, uses most recent reading

property measurement_complete: bool

Whether the most recent reading has finished.

property measurement_time: float

Time needed to complete a measurement, in seconds

start_continuous_reading(frequency: float = 300)

Start continuously reading at the given frequency. It is recommended that you use the DRDY line to detect measurement occurrences. Polling for new readings frequently can cause electronic noise that adversely affects accuracy.

Parameters:

frequency – Valid frequencies are 600Hz, 300Hz, 150Hz, 75Hz, 37Hz, 18Hz, 9Hz, 4.5Hz, 2.3Hz, 1.2Hz, 0.6Hz, 0.3Hz, 0.015Hz. 0.0075Hz. The nearest valid frequency is selected. Note that the cycle count may override this value, if taking a reading would be longer than the sample interval.

start_single_reading()

Start a single measurement cycle

stop()

Stop continuous mode