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
print(f"{mag_x:<10}{mag_y:<10}{mag_z:<10}")
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?