Shop OBEX P1 Docs P2 Docs Learn Events
Problems with the Parallax 3-axis Compass Module HMC5883L Demo Program? — Parallax Forums

Problems with the Parallax 3-axis Compass Module HMC5883L Demo Program?

BonanzaManBonanzaMan Posts: 17
edited 2014-12-16 17:54 in Propeller 1
I am attempting to use the Parallax 3-axis Compass Module HMC5883L. I downloaded, updated and ran the demo program from the Parallax site, HMC5883L_demo.spin (attached). The resulting output would only "swing" through about 90 degrees and remained in the NE quadrant. I dumped the RAW data from the program as I rotated the sensor 360 degrees, stopping at 8 points (N, NW, W, NW, S, SE, E, NE) to capture the raw data. In looking at the demo code, the aziadjust routine is using the value of raw X to and arctan(Y/X) to determine the quadrant (NW, SW, SE, NE) of the the heading. Looking at the raw data (X & Y) and calculated arctan values (see attached .jgp), X is always > 0 and arctan(y/x) is always < 0 - so no wonder the quadrant always fixed in the NE quadrant. Suspecting that the raw data isnt being read off of the sensor registers correctly, I have been staring at these methods can't find any obvious defects.

I am puzzled. I have yet to find any issues with any of the demo programs provided by Parallax - yet the install and localization for this sensor is very basic, so I am assuming something must be amiss in the demo program.

Any help is greatly appreciated.

Thanks!
Greg
388 x 221 - 40K

Comments

  • PublisonPublison Posts: 12,366
    edited 2011-12-31 17:34
    Greg,

    I just picked up a Compass Module today a ran it on a PPDB with no problems.

    Question on your "_clkfreq = 100_000_000" . How did you arrive at that setting?

    Did you change SL32_INTEngine_2.spin any?

    Jim
  • PublisonPublison Posts: 12,366
    edited 2011-12-31 17:44
    I also noted that the Data and Clock lines were reversed in the Documentation.(as opposed to the code listing) I'll seen a message to Parallax about that.

    Jim
  • BonanzaManBonanzaMan Posts: 17
    edited 2012-01-01 14:32
    Hi Jim - I am running the 6.25 MHz crystal on my project. This, plus the pll16x directive results in a clkfreq of 100Mhz. I have put my compass module on a small breadboard and used a 3' cable to connect it to my project board. Placing the compass on a flat surface (the pool table came in handy for this purpose) I got somewhat better results - but still, moving the module through, say 90 degrees, doesnt result in a 90 degree change in the reading - in some quadrants I get less, in others I get more. There is nothing interfering with the magnetic field in the area of the module, a regular compass behaves perfectly in the same area. I am beginning to woder if some sort of scalling factor or calibration needs to be added to the calc?

    What error did you find in the documentation? I looks consistent to me.

    Are you getting good results with your module?

    Thanks,
    Greg
  • PublisonPublison Posts: 12,366
    edited 2012-01-01 16:27
    BonanzaMan wrote: »
    Hi Jim - I am running the 6.25 MHz crystal on my project. This, plus the pll16x directive results in a clkfreq of 100Mhz. I have put my compass module on a small breadboard and used a 3' cable to connect it to my project board. Placing the compass on a flat surface (the pool table came in handy for this purpose) I got somewhat better results - but still, moving the module through, say 90 degrees, doesnt result in a 90 degree change in the reading - in some quadrants I get less, in others I get more. There is nothing interfering with the magnetic field in the area of the module, a regular compass behaves perfectly in the same area. I am beginning to woder if some sort of scalling factor or calibration needs to be added to the calc?

    What error did you find in the documentation? I looks consistent to me.

    Are you getting good results with your module?

    Thanks,
    Greg

    Hi Greg,

    I'm re-arranging my lab right now, so I have everything torn apart right now.

    Monday or Tuesday, I'll set up another board with a 6.25 Mhz xtal and try out the different codes.

    My test yesterday was very quick just to make sure the module was working. I'd like to try and get the raw data and look at it also.


    Jim
  • MoZak18MoZak18 Posts: 26
    edited 2012-03-14 14:32
    I am having the exact same problem with my compass module.......any help or solutions will be greatly appreciated!
  • Mark_TMark_T Posts: 1,981
    edited 2012-03-14 17:04
    BonanzaMan wrote: »
    I am attempting to use the Parallax 3-axis Compass Module HMC5883L. I downloaded, updated and ran the demo program from the Parallax site, HMC5883L_demo.spin (attached). The resulting output would only "swing" through about 90 degrees and remained in the NE quadrant. I dumped the RAW data from the program as I rotated the sensor 360 degrees, stopping at 8 points (N, NW, W, NW, S, SE, E, NE) to capture the raw data. In looking at the demo code, the aziadjust routine is using the value of raw X to and arctan(Y/X) to determine the quadrant (NW, SW, SE, NE) of the the heading.

    Greg

    The normal way to get quadrant information is to call atan2(y, x) - atan2 is the version that looks at the signs of the y and x values to determine the quadrant (which is information that is lost doing the divide)

    If the "SL32_INTEngine_2" object (which I can't find on the obex BTW) doesn't support atan2 or arctan2 or something equivalent you'll need to adapt the code to look at the signs of x and y.

    http://en.wikipedia.org/wiki/Atan2
  • stargazer2050stargazer2050 Posts: 89
    edited 2012-04-04 13:02
    Hmc5883l spin code demo is in 'compass quadrant bearing'

    We want 'azimuth bearing'
    We want horizontal coordinates

    Everyone chant this over and over (and email tech support to look into the conversion)

    in the meantime a temporary fix. gives 360 but theres a 6 degree +/- thing going on at the quadrant corners

    1. in VAR section add WORD azvalue
    2. in PUB MAIN add term.str(String(" ") into the repeat
    3. in PUB MAIN add term.dec(azvalue) into the repeat
    4. in PUB Azijust : value at bottom of it add azvalue := value

    look at the terminal at 9600 baud and there it is
  • BonanzaManBonanzaMan Posts: 17
    edited 2012-04-14 10:41
    No difference. Still have a number ranging 0-90.
  • RoboTunaRoboTuna Posts: 25
    edited 2012-12-10 18:49
    Sorry this is my first posting I hope this works. I was having that same issue I wanted just the degrees and couldn't force the demo code to do it.I found another object and spliced it in with the demo code. It displays just Degrees in the PST.


    My_Compass.spin

    SL32_INTEngine_2.spin
  • shimniokshimniok Posts: 177
    edited 2012-12-11 22:37
    Not familiar with the demo programs but very familiar with magnetometers like this.

    Is there a mention of calibrating the compass by finding its offsets?

    Because any compass I've used that wasn't calibrated for offset would tend to behave similarly to how you are describing. ("Placing the compass on a flat surface (the pool table came in handy for this purpose) I got somewhat better results - but still, moving the module through, say 90 degrees, doesnt result in a 90 degree change in the reading - in some quadrants I get less, in others I get more.")
  • BonanzaManBonanzaMan Posts: 17
    edited 2013-01-26 16:29
    Thanks all for the reply - this remains a mystery to me. I've tried two different modules and, most recently, RoboTuna's sample code. Still, my heading never swings beyond 90 degrees. I think adding calibration code is the answer here. I wonder who, if anybody is using this module?
  • shimniokshimniok Posts: 177
    edited 2013-01-27 00:52
    I've successfully used an earlier rendition of that chip. You *must* calibrate for offsets on all axes.

    Have a look over here: http://www.bot-thoughts.com/2011/04/quick-and-dirty-compass-calibration-in.html
  • IratenateIratenate Posts: 7
    edited 2014-12-16 17:33
    I had this problem with mine as well. I was using the spin sample code and only receiving information from the x axis, while the y and z were reporting constant. Switching power supply from 3.3v to 5v fixed it.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-12-16 17:54
    Iratenate wrote: »
    I had this problem with mine as well. I was using the spin sample code and only receiving information from the x axis, while the y and z were reporting constant. Switching power supply from 3.3v to 5v fixed it.

    The HMC5883L will run on supplies from 2.16V to 3.6V. Unless the board you're using has a voltage regulator to reduce the 5V to a safe level, it will likely damage the sensor board.

    Edit: The Parallax board does have a regulator so 5V is fine when using the Parallax board.

    I've successfully used several different HMC5883L sensors many times powered with 3.3V. Here's a link to my HMC5883L code. I attempted to use a HMC5883L sensor for attitude feedback in this project but I had the sensor too close to the servos. Once I moved the sensor away from the servos a few inches, it worked much better.

    I plan to post a similar reply to the other thread about this sensor. Again, unless the board with the HMC5883L sensor has a way of regulating the power supply, it should NOT be powered with 5V (the Parallax board does regulate the power so 5V is fine when using it). 3.6V is the maximum voltage to be used with the sensor.

    Edit: The Parallax board should work with a power source between 2.7V and 6.5V. It seems strange the Parallax module didn't work correctly when powered by 3.3V. I'm pretty sure I have the Parallax version of this sensor. I'll try to find it to see if I can replicate Iratenate's problem.
Sign In or Register to comment.