adafruit_lis3mdl

CircuitPython helper library for the LIS3MDL 3-axis magnetometer

  • Author(s): Bryan Siepert

Implementation Notes

Hardware: * Adafruit Adafruit LSM6DS33 + LIS3MDL - 9 DoF IMU (Product ID: 4485)

Software and Dependencies:

class adafruit_lis3mdl.LIS3MDL(i2c_bus, address=<sphinx.ext.autodoc.importer._MockObject object>)

Driver for the LIS3MDL 3-axis magnetometer.

Parameters:
  • i2c_bus (I2C) – The I2C bus the LIS3MDL is connected to.
  • address – The I2C device address. Defaults to 0x1C

Quickstart: Importing and using the device

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

import board
import adafruit_lis3mdl

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

i2c = board.I2C()
sensor = adafruit_lis3mdl.LIS3MDL(i2c)

Now you have access to the magnetic attribute

mag_x, mag_y, mag_z = sensor.magnetic
data_rate

The rate at which the sensor takes measurements. Must be a Rate

magnetic

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

operation_mode

The operating mode for the sensor, controlling how measurements are taken. Must be an OperationMode. See the the OperationMode document for additional details

performance_mode

Sets the ‘performance mode’ of the sensor. Must be a PerformanceMode. Note that performance_mode affects the available data rate and will be automatically changed by setting data_rate to certain values.

range

The measurement range for the magnetic sensor. Must be a Range

reset()

Reset the sensor to the default state set by the library

class adafruit_lis3mdl.OperationMode

Options for operation_mode

Operation Mode Meaning
OperationMode.CONTINUOUS Measurements are made continuously at the given data_rate
OperationMode.SINGLE Setting to SINGLE takes a single measurement.
OperationMode.POWER_DOWN Halts measurements. magnetic will return the last measurement
class adafruit_lis3mdl.Rate

Options for data_rate

Rate Meaning
RATE_0_625_HZ 0.625 HZ
RATE_1_25_HZ 1.25 HZ
RATE_2_5_HZ 2.5 HZ
RATE_5_HZ 5 HZ
RATE_10_HZ 10 HZ
RATE_20_HZ 20 HZ
RATE_40_HZ 40 HZ
RATE_80_HZ 80 HZ
RATE_155_HZ 155 HZ ( Sets PerformanceMode to MODE_ULTRA)
RATE_300_HZ 300 HZ ( Sets PerformanceMode to MODE_HIGH)
RATE_560_HZ 560 HZ ( Sets PerformanceMode to MODE_MEDIUM)
RATE_1000_HZ 1000 HZ ( Sets PerformanceMode to MODE_LOW_POWER)