LSM303D tilt compensation not working

G'day,

i need some help with getting a tilt-compensated compass to work:

i'm using an LSM 303D with an arduino. the I2C is chatting fine, i've calibrated using calibrate.ino and i'm getting all the outputs that the code libraries provide.

so i'm most of the way to getting my tilt-compensated compass (it's for a sailing project) to work, however the heading() is fluctuating when i hold the break-out board's heading the same, but add roll and pitch.

you can see in the .pdf i have heading plotted. i leave the break-out board stationary for a while (heading is stable), then i change roll -90deg,+90deg then pitch-90deg,+90deg. the heading should stay constant but it doesn't ... you can see it fluctuates then returns. this is not tilt-compensated :((

I think heading() should be better than this. So is is better to use raw data + try to source other equations instead OR using am i doing something wrong with heading() ??

thanks,

sixD

Screen Shot 2017-01-02 at 2.21.36 PM.pdf (38.2 KB)

Post your code!

I guess you didn't specify your device type and the default doesn't match the device you linked to.

If the tilt correction is not coded properly, it won't work for 90 degree tilts because of problems with sine/cosine terms. However, it may work for much smaller tilts.

Theory here. You might try Pololu's code for that compass.

thx for the reply. ok fair enuff on the request for the code, though it is pretty much exactly from heading from the example library:

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

LSM303 compass;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  compass.init();
  compass.enableDefault();
  compass.m_min = (LSM303::vector<int16_t>) {  -4926,  -4519,  -4454 };
  compass.m_max = (LSM303::vector<int16_t>) {  +4816,  +4412,  +4366 };
}

void loop() {
  buttonState = digitalRead(buttonPin);
  compass.read();
  float heading = compass.heading(); 
  Serial.println(heading,0);


  delay(200);
}

(note: the min and max numbers in the .ino are taken from the results from running calibrate.ino and doing the 3D 'dance')

regarding the roll approaching 90deg. i agree, but the values go haywire even up to 45deg. infact they start going weird from as little as a few degrees!

Which "example library"? If you are using Pololu's, post on their forum. The engineers are very responsible and helpful.

yes the library i mean is from the link on Pololu's site. Thanks for the suggestion - i will contact them direct + and report back here for anyone else that may need same info. standby....

HI. An update for those following this thread: the issue is not yet resolved. Go to Pololu site:
https://forum.pololu.com/t/lsm303d-tilt-compensation-problem/11611/10