Mysterious(?) output from compass HMC5883L
MCA
Posts: 13
Ive connected a HMC5883L compass to my BS2 using the setup and program code found at the of the kickstart-page, http://learn.parallax.com/KickStart/29133.
Typically I get the following output using default settings, and although the values are varying about +-10 between readings, they do not seem
to change with rotation of the compass:
X = -20
Y = -4
Z = 10
These values do not make any sense to me, they are far too low to be useable. So I suspect either there is either something
I do not understand (likely, since I'm new to this) or there is something wrong with either the code or the compass itself. I tried
maxing the gain in the compass, but still get low values (although sligthly higher). Then I made the compass do the self test. This gave
reasonable results, not the exact ones indicated in the compass data, but not way off ( http://www51.honeywell.com/aero/common/documents/myaerospacecatalog-documents/Defense_Brochures-documents/HMC5883L_3-Axis_Digital_Compass_IC.pdf ).
For Gain 5 I got positive/negative self test:
X = -434
Y = -405
Z = -4096
X = 412
Y = 396
Z = 237
To me this sets off some new questions: How come there is an overflow on negative when not on positive? Do the outputs indicate
the compass is working normally or not (there was no Z overflow when I tried gain 7, the value then was only z = -94!)?
And, my original question remains, how come I get so low values when trying to measure in continuos mode and why don't they
seem to correspond at all to rotation in any axis??
Would be very grateful for any help sorting this out, and/or if someone has tried the BS2 kick-start code for this and and can tell
me their results.
BR / Adam
Typically I get the following output using default settings, and although the values are varying about +-10 between readings, they do not seem
to change with rotation of the compass:
X = -20
Y = -4
Z = 10
These values do not make any sense to me, they are far too low to be useable. So I suspect either there is either something
I do not understand (likely, since I'm new to this) or there is something wrong with either the code or the compass itself. I tried
maxing the gain in the compass, but still get low values (although sligthly higher). Then I made the compass do the self test. This gave
reasonable results, not the exact ones indicated in the compass data, but not way off ( http://www51.honeywell.com/aero/common/documents/myaerospacecatalog-documents/Defense_Brochures-documents/HMC5883L_3-Axis_Digital_Compass_IC.pdf ).
For Gain 5 I got positive/negative self test:
X = -434
Y = -405
Z = -4096
X = 412
Y = 396
Z = 237
To me this sets off some new questions: How come there is an overflow on negative when not on positive? Do the outputs indicate
the compass is working normally or not (there was no Z overflow when I tried gain 7, the value then was only z = -94!)?
And, my original question remains, how come I get so low values when trying to measure in continuos mode and why don't they
seem to correspond at all to rotation in any axis??
Would be very grateful for any help sorting this out, and/or if someone has tried the BS2 kick-start code for this and and can tell
me their results.
BR / Adam
Comments
IIRC, you want to take the arctangent of the x and y values to compute the heading.
I have code for the Propeller to do this but not for the Basic Stamp.
The variable identified by "long[compassPtr][3]" holds the heading. The code uses this notation to make it easier for the parent object to access the results.
Some of the above code I wrote and some I copied (including the part that didn't make sense to me).
I don't know how you go about preforming trig calculations the Basic Stamp.
fundamental to know, but it does not help to sort out the strangenessof the output. Here I go again:
The quantities of the vector elements are still to small to give a decent resolution. Well, today I used an ordinary compass to check directions to see if the vector
element signs (+/-) would at least change correctly when turning it. As you can see from the following, the output is the same no matter
how i turn the damn thing (the direction headings is the actual heading that x+ on the digital compass is pointing and I sampled 4 measurements x,y,z per direction):
North
x = -18
y = 3
z = 12
x = -16
y = -1
z = 11
x = -13
y = -3
z = 12
x = -13
y = -5
z = 13
West
x = -28
y = 3
z = 9
x = -15
y = -1
z = 10
x = -11
y = 0
z = 10
x = -13
y = -3
z = 11
South
x = -23
y = 1
z = 11
x = -20
y = -1
z = 13
x = -19
y = 2
z = 9
x = -11
y = -2
z = 8
Any ideas, anyone??
BR, Adam
BR Adam
Ok, but low accuracy is something I can live with in this case. It's s a lot better then nothing at all which is what I had before...