Shop OBEX P1 Docs P2 Docs Learn Events
HM55B compass output to LCD — Parallax Forums

HM55B compass output to LCD

bentybenty Posts: 20
edited 2008-09-01 18:21 in Propeller 1
Hey all, I've been trying to figure out how to get the output from the HM55 compass to just dump out an angle to an lcd but I'm not really sure how.
The HM55B_DEMO_object_V1.1 code works fine and I get the output to the tv no problem, but the question is how do I take theta(from the demo code below) and
get a useful output from it?


theta := HM55B.theta
gr.arc(0, 0, 50, 50, -theta+2048, 0, 1, 0) 'Draw needle
gr.arc(0, 0, 50, 50, -theta+6144, 0, 1, 1)
gr.arc(0, 0, 5, 5, -theta, 0, 1, 0) ' Draw needle cross
gr.arc(0, 0, 5, 5, -theta+4096, 0, 1, 1)
gr.arc(0, 0, 40, 40, -theta+2048-150, 0, 1, 0) ' Draw needle arrow
gr.arc(0, 0, 50, 50, -theta+2048, 0, 1, 1)
gr.arc(0, 0, 40, 40, -theta+2048+150, 0, 1, 1)

gr.copy(display_base) 'copy bitmap to display


Looking at the BS2 code they perform the following, but I have yet to find an arctan function for the propeller(if it exists?) or am I way off track? confused.gif

angle = x ATN - y ' Convert x and y to brads

Thanks for any info!
benty

Comments

  • Sniper KingSniper King Posts: 221
    edited 2008-09-01 07:12
    The Arctangent function resides in the Float32Full object....Good luck!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·- Ouch, thats not suppose to be hot!··


    Michael King
    Application Engineer
    R&D
    Digital Technology Group
  • Beau SchwabeBeau Schwabe Posts: 6,560
    edited 2008-09-01 15:29
    benty,

    I'm a little confused as to how much more useful information you want from 'theta'.
    The code-snip that you posted simply draws the compass needle for the DEMO·application.

    The returned value for 'theta' from the HM55B is a 13-bit·integer that represents the angle. (0..$1FFF = 0°..359.956°)


    To convert this number into a more "human readable" value ranging from 0 to 360 (<-- perhaps what you mean by more useful), you can do something like this...

    Deg = (theta * 360) / 8192

    ...OR you can simplify it into something like this...

    Deg = (theta * 45) / 1024



    If you want the RAW x and y values, then you can use something like this in your code...

    RAWx := HM55B.HM55B_x
    RAWy := HM55B.HM55B_y



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • bentybenty Posts: 20
    edited 2008-09-01 17:12
    Thanks Beau, that was exactly what I was looking for! I was thinking theta was going to be the angle in degrees and kept getting the 13 bit output(I'm really really new to this) rolleyes.gif
    And now I know where the trig functions are too so killed two birds with one stone, thanks guys! hop.gif
  • Beau SchwabeBeau Schwabe Posts: 6,560
    edited 2008-09-01 18:21
    benty,

    Good, I'm glad that I was able to help.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
Sign In or Register to comment.