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.
- HMC5883L datasheet
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);
}
}
- HMC5883L
- Male/Female Jumper Wires
- SCL - SCL
- SDA - SDA
- VCC - 5V
- GND - GND