Pages: [1]   Go Down
Author Topic: LSM303 DLH Heading not working properly? Digital Compass Spark Fun LSM303 DLH  (Read 1047 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there,

 We are using the book 'Making Things Talk' as a guidance to get heading from the Spark Fun LSM303DLH digital compass.
 The Accelerometer seems to be ok, but the Magnetometer data we get is strange:

 North: around 275
 East: around 305
 South: around 275
 West: around 245

 So it's not useful at all. At least the values in between smoothly change.
 1) Has anyone made their Spark Fun LSM303DLH work properly?
 2) Does anyone know what might have gone wrong? How to solve this?

 We are pretty sure our cables are right.

 Our Code:
// include the necessary libraries:
#include <Wire.h>
#include <LSM303DLH.h>
#include <Button.h>

const int modeButton = 2; // pushbutton for calibration mode
const int buttonLed = 3; // LED for the button

// initialize the compass library
LSM303DLH compass;
// initialize a button on pin 2 :
Button button = Button(modeButton,BUTTON_PULLDOWN);
boolean calibrating = false; // keep track of calibration state

void setup() {
// initialize serial:
// set up the button LED:
// start the Wire library and enable the compass:

void loop() {
// if the button changes state, change the calibration state
// and the state of the LED:
if(button.isPressed() && button.stateChanged()){
calibrating = !calibrating;
digitalWrite(buttonLed, calibrating);

// if you're in calibration mode, calibrate:
if (calibrating) {
else { // if in normal mode, read the heading:;
int heading = compass.heading();
Serial.println("Heading: " + String(heading) + " degrees");
« Last Edit: January 23, 2013, 07:07:08 am by bad_egg » Logged

Massachusetts, USA
Offline Offline
Tesla Member
Karma: 212
Posts: 8967
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What are you supposed to do during calibration?

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

did you get the device to read properly we are having the same problems and getting some strange numbers at random

Pages: [1]   Go Up
Jump to: