Go Down

Topic: HMC5883l Compass HELP!! (Read 147 times) previous topic - next topic

dimitriCh

Hello! I use hmc5883l for a project that I want to include compass. I found a nice library that states that does auto calibration, then you can put the values there and you do not have to calibrate it again. It works. The issue is when I change the height from my flat desk to totally flat floor I receive wrong values. Anyone has experience mith hmc 5883l? Also I read that MAG3110 is a little bit easier, is it true? Here is my code:

/* Author = helscream (Omer Ikram ul Haq)
Last edit date = 2014-06-22
Website: http://hobbylogs.me.pn/?p=17
Location: Pakistan
Ver: 0.1 beta --- Start
Ver: 0.2 beta --- Debug feature included
*/

#include <Wire.h>
#include "compass.h"

#define Task_t 10          // Task Time in milli seconds

int dt=0;
unsigned long t;
// Main code -----------------------------------------------------------------
void setup(){
  Serial.begin(9600);
  // Serial.print("Setting up I2C ........\n");
  Wire.begin();
  compass_x_offset = -71.31;     //122.17;
  compass_y_offset = 140.49;   //230.08;
  compass_z_offset = 112.59;     //389.85;
  compass_x_gainError = 1.03;      //1.12;
  compass_y_gainError = 1.06;      //1.13;
  compass_z_gainError = 0.98;          //1.03;
 
 
  compass_init(2);
  //compass_debug = 1;
  //compass_offset_calibration(3);


}

// Main loop
// Main loop -----------------------------------------------------------------
void loop(){
 
  t = millis();
 
  float load;
 
 
 
  compass_scalled_reading();
 
  Serial.print("x = ");
  Serial.println(compass_x_scalled);
  Serial.print("y = ");
  Serial.println(compass_y_scalled);
  Serial.print("z = ");
  Serial.println(compass_z_scalled);
 

  compass_heading();
  Serial.print ("Heading angle = ");
  Serial.print (bearing);
  Serial.println(" Degree");
 
  dt = millis()-t;
  load = (float)dt/(Task_t/100);
  Serial.print ("Load on processor = ");
  Serial.print(load);
  Serial.println("%");

 



 if (bearing <= 4 || bearing >= 333)
   {
    Serial.print ("North") ;
   }

   else if (bearing <= 333 && bearing >= 290)
   {
    Serial.print ("N West") ;
   }

  else if (bearing <= 290 && bearing >= 274)
  {
    Serial.print ("West") ;
  }

 
  delay(1000);
 
 
}



jremington

You must calibrate the compass every time the environment changes significantly.  If it is not working correctly, it needs to be recalibrated.

dimitriCh

if I have it in my car how is possible to calibrate it every time I change my location? For example lets say that I will go 2 miles away, should I have to rotate the car?

dimitriCh

Sorry for the questions, I just used another code to calibrate the compass. It looks like every time I do it I take different values and every time my compass is off and has error. I really appreciate any recommendations and Ideas. Thank you.

Go Up