Skip to content

intentfulmotion/lib-driver-lis2mdl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LIS2MDL

Arduino library for the LIS2MDL magnetometer with communication over SPI / I2C

Usage

#include <Arduino.h>
#include <LIS2MDL.h>

LIS2MDL mag;
float x, y, z;

void setup() {
  Serial.begin(115200);

  // configure the magnetometer
  // settings below are default settings
  mag.settings.tempCompensationEnabled = LIS2MDL_TEMP_COMPENSATION_ENABLED;
  mag.settings.magSampleRate = LIS2MDL_MAG_ODR_10Hz;

  // set up the wire interface
  mag_status_t result = mag.begin();

  if (result != MAG_SUCCESS)
    Serial.println("Magnetometer Error");
  else {
    // probably a good idea to calibrate
    Serial.println("Calibrating: move the magnetometer all around");
    delay(4000);
    mag.calibrate();

    Serial.println("Calibration Complete");
  }
}

void loop() {
  x = mag.readFloatMagX();
  y = mag.readFloatMagY();
  z = mag.readFloatMagZ();

  Serial.print("x: ");
  Serial.print(x);
  Serial.print(" y: ");
  Serial.print(y);
  Serial.print(" z: ");
  Serial.println(z);
}

License Information

This code is released under the MIT License.

Releases

No releases published

Packages

No packages published

Languages