MicroPython LIS2MDL Driver¶
lis2mdl
¶
MicroPython Driver for the ST LIS2MDL Magnetometer sensor
Author(s): Jose D. Montoya
- class micropython_lis2mdl.lis2mdl.AlertStatus(x_high, x_low, y_high, y_low, z_high, z_low)¶
Create new instance of AlertStatus(x_high, x_low, y_high, y_low, z_high, z_low)
- x_high¶
Alias for field number 0
- x_low¶
Alias for field number 1
- y_high¶
Alias for field number 2
- y_low¶
Alias for field number 3
- z_high¶
Alias for field number 4
- z_low¶
Alias for field number 5
-
class micropython_lis2mdl.lis2mdl.LIS2MDL(i2c, address: int =
0x1E
)[source]¶ Driver for the LIS2MDL Sensor connected over I2C.
- Parameters:¶
- Raises:¶
RuntimeError – if the sensor is not found
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 sensorfrom machine import Pin, I2C from micropython_lis2mdl import lis2mdl
Once this is done you can define your
machine.I2C
object and define your sensor objecti2c = I2C(1, sda=Pin(2), scl=Pin(3)) lis = lis2mdl.LIS2MDL(i2c)
Now you have access to the attributes
magx, magy, magz = lis.magnetic
- property alert_status¶
Alert Status for interrupts
- property data_rate : str¶
Sensor data_rate
Mode
Value
lis2mdl.RATE_10_HZ
0b00
lis2mdl.RATE_20_HZ
0b01
lis2mdl.RATE_50_HZ
0b10
lis2mdl.RATE_100_HZ
0b11
- property interrupt_mode : str¶
Sensor interrupt_mode
Mode
Value
lis2mdl.INT_DISABLED
0b0
lis2mdl.INT_ENABLED
0b1
- 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
- property interrupt_triggered¶
Return True when an interrupt is triggered
- property low_pass_filter_mode : str¶
Sensor low_pass_filter_mode. Default DISABLED: Values:
DISABLED : ODR/2
ENABLED : ODR/4
Mode
Value
lis2mdl.LPF_DISABLED
0b0
lis2mdl.LPF_ENABLED
0b1
- property low_power_mode : str¶
Sensor low_power_mode. Default value: DISABLED
Mode
Value
lis3mdl.LP_DISABLED
0b0
lis3mdl.LP_ENABLED
0b1