adafruit_lsm303dlh_mag

CircuitPython driver for the LSM303DLH’s magnetometer.

  • Author(s): Dave Astels, Bryan Siepert

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_lsm303dlh_mag.LSM303DLH_Mag(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
mag_gain

The magnetometer’s gain.

mag_rate

The magnetometer update rate.

magnetic

The processed magnetometer sensor values. A 3-tuple of X, Y, Z axis values in microteslas that are signed floats.