Skip to content

Latest commit

 

History

History
66 lines (46 loc) · 1.51 KB

README.md

File metadata and controls

66 lines (46 loc) · 1.51 KB

HMC5883L - 3 Axis Digital Compass

HMC5883L is a surface-mount, multi-chip module designed for low-field magnetic sensing with a digital interface for applications such as lowcost compassing and magnetometry.

Documentation

sensor

Usage

I2cConnectionSettings settings = new I2cConnectionSettings(1, Hmc5883l.DefaultI2cAddress);
I2cDevice device = I2cDevice.Create(settings);

using (Hmc5883l sensor = new Hmc5883l(device))
{
    // read direction vector
    Vector3 directionVector = sensor.DirectionVector;
    // read heading
    double heading = sensor.Heading;
    // read status
    Status status = sensor.DeviceStatus;
}

From the HMC5883L sample, you can go further with the following:

I2cConnectionSettings settings = new I2cConnectionSettings(1, Hmc5883l.DefaultI2cAddress);
I2cDevice device = I2cDevice.Create(settings);

using (Hmc5883l sensor = new Hmc5883l(device))
{
    while (true)
    {
        // read heading
        Console.WriteLine($"Heading: {sensor.Heading.ToString("0.00")} °");
        Console.WriteLine();

        // wait for a second
        Thread.Sleep(1000);
    }
}

Hardware Required

  • HMC5883L
  • Male/Female Jumper Wires

Circuit

circuit

  • SCL - SCL
  • SDA - SDA
  • VCC - 5V
  • GND - GND

Result

running result