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... ![]()
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