Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Honeywell HMC5843 3-Axis Digital Compass


  • Please log in to reply
3 replies to this topic

#1 Shaw

Shaw

    Member

  • Members
  • PipPip
  • 14 posts

Posted 20 November 2010 - 05:59 AM

Based on the work by phatomtypist on the "Bosch BMP085 digital pressure and temperature sensor" I have implemented a basic driver for the HMC5843.

A sample use:

        private static HMC5843 magSensor = new HMC5843(0x1E);

        public static void Main()
        {
            // Create a new I2C bus instance at startup.
            I2CBus i2cBus = I2CBus.Instance;

            magSensor.DirectionChanged += new HMC5843.DirectionChangedDelegate(magSensor_DirectionChanged);
            magSensor.StatusChanged += new HMC5843.StatusChangedDelegate(magSensor_StatusChanged);
            magSensor.ModeChanged += new HMC5843.ModeChangedDelegate(magSensor_ModeChanged);

            while (true)
            {
                magSensor.Start();
                Thread.Sleep(30000);

                magSensor.Stop();
                Thread.Sleep(30000);
            }
       }

        static void magSensor_ModeChanged(HMC5843.ModeBits mode)
        {
            Debug.Print("Mode Changed to " + mode.ToString());
            if (mode == HMC5843.ModeBits.Idle || mode == HMC5843.ModeBits.Sleep)
            {
                LED.Write(false);
            }
            else
            {
                LED.Write(true);
            }
         } 

        static void magSensor_StatusChanged(HMC5843.StatusBits status)
        {
            Debug.Print("Status Changed to " + status.ToString());
            
        }

        static void magSensor_DirectionChanged(short X, short Y, short Z)
        {
            Debug.Print("XYZ = " + X + ", " + Y + ", " + Z);
        }

Attached Files



#2 Michel Trahan

Michel Trahan

    Advanced Member

  • Members
  • PipPipPip
  • 155 posts

Posted 11 April 2011 - 10:54 PM

            I2CBus i2cBus = I2CBus.Instance;

Which I2CBus implementation are you using ... it refuses to compile due to missing ".Instance" ...
Started with C in 1985, moved to Vb3 ... to vb6 and stopped. Now started with .Net and learning C# and VB.net and wishing VB.net was on MF !

#3 BitFlipper

BitFlipper

    Advanced Member

  • Members
  • PipPipPip
  • 61 posts

Posted 14 May 2011 - 08:06 PM


    magSensor.DirectionChanged += new HMC5843.DirectionChangedDelegate(magSensor_DirectionChanged);


As a bit of a simplification, the above can be re-written like this:

    magSensor.DirectionChanged += magSensor_DirectionChanged;

I'm not sure why VS still insists on using the long-form format, but I always remove the extraneous code afterwards.

Another way to clean up code a bit:

    I2CBus i2cBus = I2CBus.Instance;

...can be rewritten as:

    var i2cBus = I2CBus.Instance;

I find that it cleans up the code nicely, especially if you have a long list of local variables.

#4 ScottyG

ScottyG

    New Member

  • Members
  • Pip
  • 6 posts

Posted 02 August 2011 - 02:38 AM

Can someone help me as how to wire this (HMC5843)up and a general getting started? It looks simple but I cannot find a thing except for the Honeywell HMC5843 specification. Thanks,




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.