page_type | urlFragment | languages | products | description | |||
---|---|---|---|---|---|---|---|
sample |
I2CCompass |
|
|
This sample uses I2C on Windows 10 IoT Core to communicate with an HMC5883L Magnetometer device. |
This sample uses I2C on Windows IoT Core to communicate with an HMC5883L Magnetometer device.
Please reference the datasheet for the HMC3883L found here.
For more information on compass heading using magnetometers please see here.
You can find the source code for this sample by downloading a zip of all of our samples here. Extract the zip to your disk, then open the Samples\I2CCompass\CS\I2CCompass.sln
project from Visual Studio.
Build the project, then deploy the application to your device.
The HMC3883L device is accessed through the Windows.Devices.I2c API using the default I2C controller and the address 0x1E.
// Setup the settings to address 0x1E with a 400KHz bus speed
var i2cSettings = new I2cConnectionSettings(ADDRESS);
i2cSettings.BusSpeed = I2cBusSpeed.FastMode;
// Create an I2cDevice with our selected bus controller ID and I2C settings
var controller = await I2cController.GetDefaultAsync();
_i2cController = controller.GetDevice(i2cSettings);