adafruit_lsm303dlh_mag

CircuitPython driver for the LSM303DLH’s magnetometer.

Note that this is specifically intended for the LSM303DLHC, as opposed to the LSM303DLH proper, which has the magnetic Y and Z orientations swapped.

  • Author(s): Dave Astels, Bryan Siepert

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_lsm303dlh_mag.LSM303DLH_Mag(i2c: I2C)[source]

Driver for the Driver for the LSM303DLH’s ‘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 LSM303DLH_Mag class. First you will need to import the libraries to use the sensor

import board
import adafruit_lsm303dlh_mag

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

i2c = board.I2C()  # uses board.SCL and board.SDA
sensor = adafruit_lsm303dlh_mag.LSM303DLH_Mag(i2c)

Now you have access to the magnetic attribute

mag_x, mag_y, mag_z = sensor.magnetic
property mag_gain: int

The magnetometer’s gain.

property mag_rate: int

The magnetometer update rate.

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.