MicroPython LIS3MDL Library¶
lis3mdl
¶
MicroPython Driver for the ST LIS3MDL magnetometer
Author: Jose D. Montoya
-
class micropython_lis3mdl.lis3mdl.LIS3MDL(i2c, address: int =
0x1C
)[source]¶ Driver for the LIS3MDL 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
LIS3MDL
class. First you will need to import the libraries to use the sensorfrom machine import Pin, I2C from micropython_lis3mdl import lis3mdl
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 = lis3mdl.LIS3MDL(i2c)
Now you have access to the attributes
magx, magy, magz = lis.magnetic
- property data_rate : str¶
Sensor data_rate. Data rate higher than 80 Hz needs the FAST_ODR bit activated as well as the X and Y axes operative mode selection set. Be sure to read the datasheet to select the right value according to your needs.
Mode
Value
lis3mdl.RATE_0_625_HZ
0b000000
lis3mdl.RATE_1_25_HZ
0b000010
lis3mdl.RATE_2_5_HZ
0b000100
lis3mdl.RATE_5_HZ
0b000110
lis3mdl.RATE_10_HZ
0b001000
lis3mdl.RATE_20_HZ
0b001010
lis3mdl.RATE_40_HZ
0b001100
lis3mdl.RATE_80_HZ
0b001110
lis3mdl.RATE_155_HZ
0b000001
lis3mdl.RATE_300_HZ
0b010001
lis3mdl.RATE_560_HZ
0b100001
lis3mdl.RATE_1000_HZ
0b110001
- property low_power_mode : str¶
Sensor low_power_mode. Default value: DISABLED If ENABLED,
data_rate
is set to 0.625 Hz and the system performs, for each channel, the minimum number of averages.Mode
Value
lis3mdl.LP_DISABLED
0b0
lis3mdl.LP_ENABLED
0b1