LSM303DLH Accuracy

I am having a bit of a tough time getting accurate readings from this compass.

I have gone through the calibration process a few times but it’s not a happy compass.

I purchased two of them and they both giving a nice north but 90 Degrees and 180 and 270 are about 30 degrees off.

Any help would be great !

Hi Richard,

There are various levels of calibration for the LSM303, Adafruit have a guide that you might find helpful. They list different approachs, you may need to experiment to find what works best for your project.

Here is my code

#include <Wire.h>
#include <LSM303.h>

LSM303 compass;

void setup() {
  Calibration values; the default values of +/-32767 for each axis
  lead to an assumed magnetometer bias of 0. Use the Calibrate example
  program to determine appropriate values for your particular unit.
  compass.m_min = (LSM303::vector<int16_t>){-716,   -589,   -614};
  compass.m_max = (LSM303::vector<int16_t>){+458,   +577,   +577};

void loop() {;
  When given no arguments, the heading() function returns the angular
  difference in the horizontal plane between a default vector and
  north, in degrees.
  The default vector is chosen by the library to point along the
  surface of the PCB, in the direction of the top of the text on the
  silkscreen. This is the +X axis on the Pololu LSM303D carrier and
  the -Y axis on the Pololu LSM303DLHC, LSM303DLM, and LSM303DLH
  To use a different vector as a reference, use the version of heading()
  that takes a vector argument; for example, use
    compass.heading((LSM303::vector<int>){0, 0, 1});
  to use the +Z axis as a reference.
  float heading = compass.heading();

Hi Richard
I am struggling to get reliable compass readings from my LSM303D with Python on a Raspberry Pi. Did calibration solve your problems? Please let me know if you made any progress.
Richard G