My Raspberry Pi Pico is connected to a 9 DOF IMU like this one, Adafruit 9-DOF IMU Breakout - L3GD20H + LSM303, through an I2C connection.

For some reason, whenever I try and get values from the magnetometer, the values I get barely change, even when I move the IMU around.

This is the code I wrote for the Pico:

import adafruit_lsm303dlh_mag
import board
import busio

i2c = busio.I2C(board.GP21, board.GP20)
sensor_mag = adafruit_lsm303dlh_mag.LSM303DLH_Mag(i2c)

while True:
    mag_x, mag_y, mag_z = sensor_mag.magnetic

These are the approximated values I get back from it while moving it around:

-51.1818  -49.0909  -417.959
-51.4545  -50.0909  -417.959
-51.6364  -48.7273  -417.959
-51.2727  -48.4545  -417.959
-51.2727  -49.2727  -417.959

The gyroscope and the accelerometer seem to be working fine. Is my magnetometer broken or am I missing something?



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.