API Reference
adafruit_lis2mdl
CircuitPython driver for the LIS2MDL 3-axis magnetometer.
Author(s): Bryan Siepert
Implementation Notes
Hardware:
Adafruit Triple-axis Accelerometer+Magnetometer (Compass) Board - LSM303 (Product ID: 1120)
Adafruit FLORA Accelerometer/Compass Sensor - LSM303 - v1.0 (Product ID: 1247)
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads
Adafruit’s Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
Adafruit’s Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
- 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
LIS2MDLclass. First you will need to import the libraries to use the sensorimport board import adafruit_lis2mdl
Once this is done you can define your
board.I2Cobject and define your sensor objecti2c = board.I2C() # uses board.SCL and board.SDA sensor = adafruit_lis2mdl.LIS2MDL(i2c)
Now you have access to the
magneticattributemag_x, mag_y, mag_z = sensor.magnetic
- 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_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.
- property x_offset: float
An offset for the X-Axis to subtract from the measured value to correct for magnetic interference