Sparkfun 1052L (Magnetometer) eval. board

Hi,

Please bear with me - bit of a newbie....

I've got a Sparkfun 1052L eval board (Triple Axis Magnetometer Breakout - HMC5843 - SEN-09371 - SparkFun Electronics) which I am trying to use as a compass. According to the sparkfun site, I should be able to get a Mag heading. However I'm getting nonsense from the board. Regardless of the direction/inclination of the board, the Arduino ADC gives the same (or nearly the same) results. Further, if left alone on the desk, the device gives fluctuating results.

The device is directly connected to the Arduino.

Here's my sketch

/*
 * Test the Sparkfun 1052L Eval board
 *
 * Connected as
 * VCC - 5V
 * Gnd - Gnd
 * Out1 - Pin 4
 * Out2 - Pin 5
 * Set - Pin 7
 *
 * No other circuitry
 */
 
const int compass_out1_pin = 4;
const int compass_out2_pin = 5;
const int compass_set_pin = 7;

void setup() {
  Serial.begin(9600);
  pinMode(compass_set_pin,OUTPUT);
}

void loop() {
  int compass1;
  int compass2;
  for(;;) {
    // pulse the SET line (suggested elsewhere, not strictly reqd I think)
    digitalWrite(compass_set_pin,HIGH);
    delay(50);
    digitalWrite(compass_set_pin,LOW);

    // Read the OUT1, OUT2 pins
    compass1 = analogRead(compass_out1_pin);
    compass2 = analogRead(compass_out2_pin);

    Serial.print("Compass1 = ");
    Serial.print(compass1,DEC);
    Serial.print(" Compass2 = ");
    Serial.print(compass2,DEC);
    Serial.println(".");
    delay(1000);
  }
}

And here's some results of it just left on my desk

Compass1 = 92 Compass2 = 80.
Compass1 = 88 Compass2 = 92.
Compass1 = 93 Compass2 = 81.
Compass1 = 89 Compass2 = 92.
Compass1 = 98 Compass2 = 90.
Compass1 = 91 Compass2 = 83.
Compass1 = 93 Compass2 = 81.
Compass1 = 89 Compass2 = 80.
Compass1 = 94 Compass2 = 90.
Compass1 = 90 Compass2 = 91.
Compass1 = 96 Compass2 = 81.
Compass1 = 104 Compass2 = 84.
Compass1 = 100 Compass2 = 93.

and here's a slow rotation of the device

Compass1 = 85 Compass2 = 87.
Compass1 = 88 Compass2 = 83.
Compass1 = 86 Compass2 = 82.
Compass1 = 99 Compass2 = 87.
Compass1 = 86 Compass2 = 94.
Compass1 = 99 Compass2 = 93.
Compass1 = 85 Compass2 = 94.
Compass1 = 85 Compass2 = 79.
Compass1 = 85 Compass2 = 95.
Compass1 = 95 Compass2 = 90.
Compass1 = 98 Compass2 = 83.
Compass1 = 99 Compass2 = 91.
Compass1 = 102 Compass2 = 84.
Compass1 = 86 Compass2 = 79.
Compass1 = 95 Compass2 = 78.
Compass1 = 88 Compass2 = 87.
Compass1 = 86 Compass2 = 78.
Compass1 = 97 Compass2 = 94.

I'm not sure I can spot the difference... :frowning:

The SF website suggests a 16 bit ADC and the Arduino is only 10, so maybe I'll only be able to see fewer directions, however, I'm not sure I'm seeing anything.

This is very disappointing for a first real project so any ideas would be appreciated.

Mark

I haven't used this but you appere to be resetting it just before you take the readings and not giving it any time to settle.
Move the reset to the setup() part. Also remove the for(; ; ) the loop function will automatically repeat.
These sorts of sensors are not as good as you hope they would be but are better than you are getting. You are connecting it to analogue pins 4 & 5 and digital pin 7 and you have common ground?

Did that, no real change :frowning: Wired exactly as you summarised. I'm powering the board from the arduino 5V pin (have tried the 3V3 pin). I wonder if it's not getting enough power?

What's puzzling me is the fluctuation whilst the device is just lying on the desk. It's connected to the arduino via a piece of ribbon cable around 25cm long with a connector on the end. This is then connected to the breadboard using 10cm patch leads, I wonder if that's too lossy/noisy. I'll try removing the cable and soldering some header pins on instead. That way it can go directly onto the breadboard...

Thanks for your help so far.

Mark

What's puzzling me is the fluctuation whilst the device is just lying on the desk

that level of fluctuations is to be expected with this sort of sensor, it's just general noise. Have you tried putting a magnet close to it. Not too close mind, just to see if it changes as the magnet approaches. That way you will know if you have a wiring / sensor problem or if it is just one of sensitivity.

Tried the magnet - no change in measured inputs.

I rigged a seperate power supply for it - a 5VDC mains adapter. Joined the board's ground and the power supply ground. I get very similar behaviour except that the anologue readings are around 900 rather than 100 when using the Arduino to power the sensor... That doesn't sound right to me.

I've checked and double checked my sensor lead - that all buzzes through OK. I'll try resoldering the breakout board onto the lead again later.

Given that there are only 5 wires, and no components I'm at a loss to know what else to do.

Perhaps the board is DOA..

Cheers, Mark

ps. I really do appreciate your help here. Thank you.

I found one of the HMC1052L eval boards lying about, wired it, and ran it the same way you did. I got the same random numbers as you.

Then I pulled the lead to the compass SET pin out of the Arduino and grounded it. The compass started working: the numbers are in the 430-510 range, they aren't random, they change as I rotate the compass, and they change when a magnet is brought near.

I have no idea why this helped. I would have thought that an Arduino digital output pin set to LOW would be the same as GND.

I got my 1052L eval board working last night. It was a really painful board to use due to the lack of documentation. At this point I have mine wired the same as yours, except I'm using a separate 5V power supply for the compass board and a common ground. I have the compass SET pin grounded.

The OUT1, OUT2 analog signals from the compass are VCC / 2, or in the 400-500 range. You need to center these values about zero, so subtract 512 from them to start. 10-bit A/D = 2^10 = 1024 at 5V, thus the 512. So set X = OUT1 - 512, Y = OUT2 - 512, then the compass heading in radians is atan2(Y, X). N.B. The 512 is a nominal value, you will have to adjust it downward during calibration. I get the best results using a bias of about 476. I.e. X = OUT1 - 476. Remember that the bias is around VCC / 2, so that you will need a different bias if you are driving the compass at 3V or 9V etc.

BEGIN EDIT >>>
After some thought, I suspect that you need a separate bias for each axis, and that the bias values are (OUT1max - OUT1min)/2 and (OUT2max - OUT2min) /2. That is, in a calibration step, set the bias to zero, rotate the compass at least 360 degress while taking continuous readings, and compute the maximum and minumum values of OUT1 and OUT2. Then, set the bias for OUT1 as (OUT1max - OUT1min)/2, and the bias for OUT2 as (OUT2max - OUT2min) /2. My value of 476 is suspiciously close to these mean values.
<<< END EDIT.

Compass calibration (not just the 1052L) looks like a major PITA -- it looks like you need to do a best fit to an ellipse and then figure out how to offset, rotate, or scale that ellipse so that it becomes a circle centered at the origin.

This US patent application has a full algorithm, but the math is beyond me and probably beyond 32K of memory:

You may find these Honeywell documents slightly helpful (The Hitchhiker's Guide to the Galaxy would describe them as "almost, but not completely harmful"):
"REFERENCE DESIGN: LOW COST COMPASS"
http://www.ssec.honeywell.com/magnetic/datasheets/an214.pdf
and
"Applications of Magnetic Sensors for Low Cost Compass Systems"
http://www.ssec.honeywell.com/magnetic/datasheets/lowcost.pdf

Hi. I'm just starting an arduino project and working with the exact same sensor and having the exact same problems. My only extra problem is that I'm having a tough time finding out which pin the "set" pin is. There are two pins labeled sr+ and sr- that are my prime candidates, but I'm not sure.

In fact, the + and - pins for everything have been confusing me slightly. There are positive and negative pins for ground, output, sr, and something labeled "off".

Can anyone help me?

Thanks