Shop OBEX P1 Docs P2 Docs Learn Events
HMC5883L Simple 0-359 degree out for Prop — Parallax Forums

HMC5883L Simple 0-359 degree out for Prop

SeekerSeeker Posts: 58
edited 2014-04-22 07:29 in Accessories
I have been working with the demo code and the kickstart code trying to get a simple decimal number showing the heading in degrees. I have had some luck altering the demo code to get a numeric value, but its range is way over 360 and seems to jump around in odd ways. I was wondering if anyone had written an object for this sensor (Parallax # 29133) that outputs just degree heading. The NxxE and SxxW of the demo looks cool for demo purposes, but is hard to use in a guidance system. :)

Part of the problem is getting my head around the math. It has been 30+ years since my last trig class... and it shows. That and my Spin skills are still growing. The platform will be leveled in real time using a gyro and tilt sensor, so I am not too worried about compensating for tilt in the math. Just looking for a reasonably accurate heading.

Anyone have something they can share?

Thanks!

Comments

  • FranklinFranklin Posts: 4,747
    edited 2012-03-27 19:36
    Could you show us the code you are using and the output it is giving you?
  • SeekerSeeker Posts: 58
    edited 2012-03-28 05:03
    I don't have the code in front of me right now, but basically I was taking the "value" variable from the "aziadjust" block (in the demo code) and using it. It seemed like the most logical place to start. I even thought of parsing the NxxE type output, but that seemed like a huge waste of memory to go through all of that effort to convert a number to text, just to convert it back again to a number again. I do have a HM55B available that I could use, but the resolution is so low... it would be usable, but limited. I would prefer the accuracy of the HMC5883L.
  • SeekerSeeker Posts: 58
    edited 2012-03-28 05:09
    I forgot to add... the output was more like a 0-980 (? Best guess from memory) that had large jumps between some of the output numbers. It would jump forward large amounts, then back again when the compass was rotated. Not sure if that is environmental though since I am working on a breadboard near my laptop. When I move the compass in a circle, it does encounter sources of interference.
  • Mark_TMark_T Posts: 1,981
    edited 2012-03-29 05:26
    The sensor give x,y,z information from the datasheet - surely if its level all you need is atan2(y, x)? Obex seems to have some objects that support atan2
  • SeekerSeeker Posts: 58
    edited 2012-03-29 08:06
    Yeah that was all I needed, and it was there. I had one of those "DOH!" moments. The print to terminal line I added neglected clearing out to the end of the line... so when it got to 3 digits, then went back down to 2 the final digit stayed behind making it appear that I was getting bad data when in fact it was dumb programmer strikes again. I should have known better... it just took a fresh look to see the obvious. It was just one of those errors that in haste you over look. I should know better. ;)

    So now I am getting the data I want. Still one odd problem though. Sometimes when I first power up after letting it sit awhile, one or more of the x,y,z outputs (from demo code, not my mistaken code) is stuck at -4096 (or something like that). The only fix I have found is to remove it from the breadboard, wait, then plug it back in. This will free up the stuck digit, but then another might be stuck. A few rounds of this and it all clears up and works. A simple power cycle doesn't do it. Since this is just a testbed setup, it is not too big of a deal. I just hope that once I place it in the completed circuit it doesn't happen.
  • rohit.bbrohit.bb Posts: 1
    edited 2014-04-21 03:33
    This could be just because of some strong magnetic field in the vicinity of the magnetometer.
  • TymkrsTymkrs Posts: 539
    edited 2014-04-22 07:29
    I thought for sure I had code that did this, so I'm gonna look for it, but in the mean time, see if any of this helps:

    http://tymkrs.tumblr.com/post/22258810035/parallax-compass-module-3-axis-hmc5883l-29133-part
Sign In or Register to comment.