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
LIS3MDLclass. First you will need to import the libraries to use the sensorfrom machine import Pin, I2C from micropython_lis3mdl import lis3mdlOnce this is done you can define your
machine.I2Cobject 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_HZ0b000000lis3mdl.RATE_1_25_HZ0b000010lis3mdl.RATE_2_5_HZ0b000100lis3mdl.RATE_5_HZ0b000110lis3mdl.RATE_10_HZ0b001000lis3mdl.RATE_20_HZ0b001010lis3mdl.RATE_40_HZ0b001100lis3mdl.RATE_80_HZ0b001110lis3mdl.RATE_155_HZ0b000001lis3mdl.RATE_300_HZ0b010001lis3mdl.RATE_560_HZ0b100001lis3mdl.RATE_1000_HZ0b110001
- property low_power_mode : str¶
Sensor low_power_mode. Default value: DISABLED If ENABLED,
data_rateis set to 0.625 Hz and the system performs, for each channel, the minimum number of averages.Mode
Value
lis3mdl.LP_DISABLED0b0lis3mdl.LP_ENABLED0b1