Shop OBEX P1 Docs P2 Docs Learn Events
Javalin code for HM55B Compass — Parallax Forums

Javalin code for HM55B Compass

JavalinJavalin Posts: 892
edited 2006-07-05 19:00 in General Discussion
All,

Attached is Java example code for Parallax's HM55B compass module.

Think it works (my compass has not been calibrated yet...) - but best test yourselves to be sure!!

You'll need to save the files and rename them .java (for some reason the forums dont seem to allow .java uploads??!)

The trig.java and unsignedintclass.java need to go in the \lib\stamp\math directory under the GUI's install.

The the HM55B_Compass.java just save and run.

Have fun,

James

Post Edited (Javalin) : 1/12/2006 10:32:16 PM GMT

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-01-12 23:36
    Another HM55B class, written some time ago, can be found here:
    http://groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/peripheral/sensor/compass/HM55B/
    This particular class allows a single pin for data input and output.

    Why does this not work in your class?
    To use a single pin, you connect a 1k resistor between Din and Dout,
    then connect Din to the Javelin·pin used for data.

    regards peter
    ·
  • JavalinJavalin Posts: 892
    edited 2006-01-13 10:38
    Peter,

    Thanks for that. I am not sure why it does not work - I will try the resister and see what happens.

    Cheers

    james
  • RituRitu Posts: 39
    edited 2006-06-30 13:59
    I tried out the first compass code with the three files; however all that keeps coming out is status= 0 readyis=12. What do you think my problem could be?
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-06-30 14:33
    And have you tried the other class from the 2nd post?
    What does this class give as results?

    I noticed the first class (the one you use) mirrored the bits in the command constants
    and then using CPU.SHIFT_LSB.
    The other class uses the normal command constants and CPU.SHIFT_MSB.

    Both techniques should give the same result but the 2nd class makes more sense
    since it uses the command constants as given by the HM55B manual.


    I have no HM55B so I cannot test it for myself.

    regards peter
  • RituRitu Posts: 39
    edited 2006-07-05 18:35
    What should my main for the 2nd post class be? I am not sure. Since it needs a main to run.
    Thanks,
    Ritu
  • RituRitu Posts: 39
    edited 2006-07-05 18:53
    Here is the main that I created, how can I fix it?
    public static void main()
    {
    static HM55B cp1 = new HM55B(cp1_DinDout,cp1_Clk,cp1_En);
    boolean repeat = true;
    while( repeat=true)
    {
    cp1.start();
    cp1.poll();
    if(result = true)
    {
    System.out.println("X-axis:");
    System.out.println(getCompassX());
    System.out.println("Y-axis:");
    System.out.println(getCompassY());
    System.out.println("Compass Angle:");
    System.out.println(getCompassAngle());
    }
    else()
    {
    repeat= false;
    }
    }
    }
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-07-05 19:00
    Try this.
    regards peter
Sign In or Register to comment.