Zhang Yuexin

C# programmer. Know a bit of hardware knowledge. 3D model design novice.

张高兴 - 土味儿编程

高兴不高兴

张高兴的 Windows 10 IoT 开发笔记:三轴数字罗盘 HMC5883L

本文约 225 字,包含 1 张图片,4 个代码段,阅读时间约 1 分钟
QR Code

在手机上查看此页面


This is a Windows 10 IoT Core project on the Raspberry Pi 2/3, coded by C#.

GitHub:https://github.com/ZhangGaoxing/windows-iot-demo/tree/master/HMC5883L

Screenshot

Attention

I don't know how to check the sensor data, so...But the direction looks good.

Connect

  • SDA - Pin3
  • SCL - Pin5
  • VCC - 3.3/5V
  • GND - GND

Reference

https://github.com/ZhangGaoxing/windows-iot-demo/tree/master/HMC5883L/Reference

What Contains

In HMC5883L.cs file

/// <summary>
/// Initialize
/// </summary>
/// <returns></returns>
public async Task InitializeAsync();
/// <summary>
/// Read raw data from HMC5883L
/// </summary>
/// <returns>Raw data</returns>
public HMC5883LData ReadRaw();
/// <summary>
/// Calculate direction angle
/// </summary>
/// <param name="rawData">HMC5883LData</param>
/// <returns>Angle</returns>
public double RawToDirectionAngle(HMC5883LData rawData);
/// <summary>
/// Cleanup
/// </summary>
public void Dispose();

How to Use

  • First, you need to create a HMC5883L object. After that you should call InitializeAsync() to initialize.
HMC5883L sensor = new HMC5883L(MeasurementMode.Continuous);
await sensor.InitializeAsync();
  • Secondly
var data = sensor.ReadRaw();
double angle = sensor.RawToDirectionAngle(data);
  • If you want to close the sensor, call Dispose().
sensor.Dispose();
最后更新时间 : 2019/06/25 17:31 张高兴 阅读(205) 评论(0)
文章标签: C# UWP IoT Raspberry Pi
  发表评论
Click to Refresh