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
Adafruit Triple-axis Accelerometer+Magnetometer (Compass) Board - LSM303 (Product ID: 1120)
Adafruit FLORA Accelerometer/Compass Sensor - LSM303 - v1.0 (Product ID: 1247)
Software and Dependencies:
Adafruit CircuitPython firmware: https://circuitpython.org/downloads
Adafruit’s Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
- class adafruit_lsm303dlh_mag.LSM303DLH_Mag(i2c: I2C)¶
Driver for the Driver for the LSM303DLH’s ‘magnetometer.
i2c (I2C) – The I2C bus the device is connected to.
Quickstart: Importing and using the device
Here is an example of using the
LSM303DLH_Magclass. 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.I2Cobject 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
mag_x, mag_y, mag_z = sensor.magnetic