adafruit_lis2mdl

CircuitPython driver for the LIS2MDL 3-axis magnetometer.

  • Author(s): Bryan Siepert

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_lis2mdl.DataRate[source]

Data rate choices to set using data_rate

Rate_100_HZ = 3

100 Hz

Rate_10_HZ = 0

10 Hz

Rate_20_HZ = 1

20 Hz

Rate_50_HZ = 2

50 Hz

class adafruit_lis2mdl.LIS2MDL(i2c: I2C)[source]

Driver for the LIS2MDL 3-axis magnetometer.

Parameters:

i2c (I2C) – The I2C bus the device is connected to

Quickstart: Importing and using the device

Here is an example of using the LIS2MDL class. First you will need to import the libraries to use the sensor

import board
import adafruit_lis2mdl

Once this is done you can define your board.I2C object and define your sensor object

i2c = board.I2C()  # uses board.SCL and board.SDA
sensor = adafruit_lis2mdl.LIS2MDL(i2c)

Now you have access to the magnetic attribute

mag_x, mag_y, mag_z = sensor.magnetic
property data_rate: Literal[0, 1, 2, 3]

The magnetometer update rate.

property faults: Tuple[bool, bool, bool, bool, bool, bool, bool]

A tuple representing interrupts on each axis in a positive and negative direction (x_hi, y_hi, z_hi, x_low, y_low, z_low, int_triggered)

property interrupt_enabled: bool

Enable or disable the magnetometer interrupt

property interrupt_threshold: float

The threshold (in microteslas) for magnetometer interrupt generation. Given value is compared against all axes in both the positive and negative direction

low_power = 96

Enables and disables low power mode

property magnetic: Tuple[float, float, float]

The processed magnetometer sensor values. A 3-tuple of X, Y, Z axis values in microteslas that are signed floats.

reset() None[source]

Reset the sensor to the default state set by the library

property x_offset: float

An offset for the X-Axis to subtract from the measured value to correct for magnetic interference

property y_offset: float

An offset for the Y-Axis to subtract from the measured value to correct for magnetic interference

property z_offset: float

An offset for the Z-Axis to subtract from the measured value to correct for magnetic interference