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

100 Hz

Rate_10_HZ

10 Hz

Rate_20_HZ

20 Hz

Rate_50_HZ

50 Hz

class adafruit_lis2mdl.LIS2MDL(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
data_rate

The magnetometer update rate.

faults

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)

interrupt_enabled

Enable or disable the magnetometer interrupt

interrupt_threshold

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

low_power

Enables and disables low power mode

magnetic

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

reset()[source]

Reset the sensor to the default state set by the library

x_offset

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

y_offset

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

z_offset

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