Arduino Nano 33 IoT IMU Angle issue

Hi, I’m using IMU in Arduino Nano 33 IoT to get the heading, pitch and roll using the MadgwickAHRS library. When I lay the board flat on the table, the pitch and roll gives consistent value. However, the heading keeps decreading linearly even if the board is not moving. Here is the code:

#include <MadgwickAHRS.h>
#include <Arduino_LSM6DS3.h>

// initialize a Madgwick filter:
Madgwick filter;
// sensor's sample rate is fixed at 104 Hz:
const float sensorRate = 104.00;
int motorPin = 6;
void setup() {
  pinMode(motorPin, OUTPUT);
  // attempt to start the IMU:
  if (!IMU.begin()) {
    Serial.println("Failed to initialize IMU");
    // stop here if you can't access the IMU:
    while (true);
  // start the filter to run at the sample rate:

boolean WasInRange = false;

void loop() {
  // values for acceleration & rotation:
  float xAcc, yAcc, zAcc;
  float xGyro, yGyro, zGyro;
  // values for orientation:
  double roll, pitch, heading;
  // check if the IMU is ready to read:
  if (IMU.accelerationAvailable() &&
      IMU.gyroscopeAvailable()) {
    // read accelerometer & gyrometer:
    IMU.readAcceleration(xAcc, yAcc, zAcc);
    IMU.readGyroscope(xGyro, yGyro, zGyro);
    // update the filter, which computes orientation:
    filter.updateIMU(xGyro, yGyro, zGyro, xAcc, yAcc, zAcc);
    // print the heading, pitch and roll
    roll = filter.getRoll();
    pitch = filter.getPitch();
    heading = filter.getYaw();
    Serial.print("Orientation: ");
    Serial.print(" ");
    Serial.print(" ");

I’ve attached the Serial Plotter output. How do I fix it so the heading can have consistent output?

Your image:

disclaimer: Not sure if it's related and I've never used that arduino...

Is there a way to look at the gyroscope biases ? if they are too high it results in a constant drift of the Yaw output. (read more about Manual Gyro Bias Estimation)