nanoFramework.Iot.Device.Bmm150 1.2.590

预留前缀
dotnet add package nanoFramework.Iot.Device.Bmm150 --version 1.2.590                
NuGet\Install-Package nanoFramework.Iot.Device.Bmm150 -Version 1.2.590                
此命令旨在在 Visual Studio 的包管理器控制台中使用,因为它使用 NuGet 模块版本的 Install-Package
<PackageReference Include="nanoFramework.Iot.Device.Bmm150" Version="1.2.590" />                
对于支持 PackageReference 的项目,将此 XML 节点复制到项目文件中以引用软件包。
paket add nanoFramework.Iot.Device.Bmm150 --version 1.2.590                
#r "nuget: nanoFramework.Iot.Device.Bmm150, 1.2.590"                
#r 指令可用于 F# Interactive 和 Polyglot Notebooks。将其复制到交互式工具或脚本的源代码中以引用软件包。
// Install nanoFramework.Iot.Device.Bmm150 as a Cake Addin
#addin nuget:?package=nanoFramework.Iot.Device.Bmm150&version=1.2.590

// Install nanoFramework.Iot.Device.Bmm150 as a Cake Tool
#tool nuget:?package=nanoFramework.Iot.Device.Bmm150&version=1.2.590                

Bmm150 - 磁力计

Bmm150 是一个磁力计,可通过 I2C 或 SPI 进行控制。此实现已在 ESP32 平台上进行了测试,具体是在 M5Stack Grey 上。

文档

Bmm150 的文档可以在 这里找到

用法

重要:在创建 I2cDevice 之前,请确保适当地设置了 I2C 引脚,特别是对于 ESP32,确保已安装 nanoFramework.Hardware.ESP32 nuget

//////////////////////////////////////////////////////////////////////
// when connecting to an ESP32 device, need to configure the I2C GPIOs
// used for the bus
Configuration.SetPinFunction(21, DeviceFunction.I2C1_DATA);
Configuration.SetPinFunction(22, DeviceFunction.I2C1_CLOCK);

对于其他设备如 STM32,请确保您正在使用您要使用的 I2C 总线的预置引脚。

您可以在 示例 目录中找到一个示例。用法简单,包括校准的可能性。

// The I2C pins 21 and 22 in the sample below are ESP32 specific and may differ from other platforms.
// Please double check your device datasheet.
Configuration.SetPinFunction(22, DeviceFunction.I2C1_CLOCK);
Configuration.SetPinFunction(21, DeviceFunction.I2C1_DATA);

I2cConnectionSettings mpui2CConnectionSettingmpus = new(1, Bmm150.DefaultI2cAddress);

using Bmm150 bmm150 = new Bmm150(I2cDevice.Create(mpui2CConnectionSettingmpus));

Debug.WriteLine($"Please move your device in all directions...");

bmm150.CalibrateMagnetometer();

Debug.WriteLine($"Calibration completed.");

while (true)
{
    Vector3 magne = bmm150.ReadMagnetometer(true, TimeSpan.FromMilliseconds(11));

    var head_dir = Math.Atan2(magne.X, magne.Y) * 180.0 / Math.PI;

    Debug.WriteLine($"Mag data: X={magne.X,15}, Y={magne.Y,15}, Z={magne.Z,15}, head_dir: {head_dir}");

    Thread.Sleep(100);
}

预期输出

Please move your device in all directions...
Calibration completed.
Mag data: X=    32.97089767, Y=   -10.99029922, Z=   -27.41439819, head_dir: 108.43494945
Mag data: X=    38.83239364, Y=   -10.62395668, Z=    -22.2116661, head_dir: 105.30084201
Mag data: X=    43.96039581, Y=     -8.4257431, Z=     4.60182046, head_dir: 100.85010634
Mag data: X=    42.49582672, Y=   -8.059553146, Z=   9.0047292709, head_dir: 100.7388972
Mag data: X=    42.86371994, Y=    -12.8224802, Z=     8.20643711, head_dir: 106.65430547
Mag data: X=    36.26864242, Y=    -6.22794914, Z=   -21.41402244, head_dir: 99.74364301
Mag data: X=    29.30693054, Y=    -9.89108943, Z=   -32.21274185, head_dir: 108.6495335
Mag data: X=    15.75333309, Y=    -8.42620182, Z=  -37.029045104, head_dir: 118.14159082
Mag data: X=      4.7626357, Y=    -6.22806167, Z=   -42.23312759, head_dir: 142.59463794
Mag data: X=    -4.39627885, Y=    -6.59441852, Z=   -36.22841644, head_dir: -146.309933
Mag data: X=   -10.25779819, Y=    -5.12889909, Z=   -38.62528991, head_dir: -116.56504656
Mag data: X=  -19.050889968, Y=     0.73272651, Z=  -37.033847808, head_dir: -87.7974031
Mag data: X=   -35.90294647, Y=     1.46542632, Z=   -18.61460113, head_dir: -87.66269127
Mag data: X=   -37.73472976, Y=     8.42620182, Z=   -13.41051959, head_dir: -77.41230537
Mag data: X=   -37.73472976, Y=     9.52527141, Z=   -12.20957756, head_dir: -75.83294707
Mag data: X=   -18.31749725, Y=     0.73269987, Z=   -31.42057418, head_dir: -87.70938928
Mag data: X=    -2.19813942, Y=    -7.69348812, Z=  -37.029045104, head_dir: -164.054600542

校准

您可以通过CalibrateMagnetometer函数获得访问并执行校准,该函数将...注意,校准需要几秒钟。

bmm150.CalibrateMagnetometer();

如果不进行校准,您将得到一个类似以下的数据云

raw data

进行正确的校准时,需要在执行校准的过程中将传感器移动到所有可能的方向。您应该考虑使用足够的样本运行,至少几百个。默认设置为100。在远离任何磁场的所有方向移动传感器时,您将得到上述云。从这些云中计算平均值并将其从读取值中减去,将得到像这样居中的数据云

raw data

要创建这些点云图,每个云是X-Y、Y-Z和Z-X的坐标。

校准完成一次后,您将能够使用带有偏差校正的ReadMagnetometer函数读取数据。您仍然可以使用ReadMagnetometerWithoutCalibration函数读取未经校准的数据。

Bmm150不支持/未实现的功能

  • 设备自检
  • 设备复位
  • 切换操作模式(默认为正常模式)

测试

单元测试项目位于\Bmm150.tests。您可以使用VS2019内置的测试功能,如下所示

unit tests

[TestMethod]
public void TestCompensateVector3()
{
        uint rhall = 42;
        Vector3 rawMagnetormeterData = new Vector3 { X = 13.91375923, Y = -28.74289894, Z = 10.16711997 };
        Bmm150TrimRegisterData trimRegisterData = new Bmm150TrimRegisterData()
        {
            DigX1 = 0,
            DigX2 = 26,
            DigXy1 = 29,
            DigXy2 = -3,
            DigXyz1 = 7053,
            DigY1 = 0,
            DigY2 = 26,
            DigZ1 = 24747,
            DigZ2 = 763,
            DigZ3 = 0,
            DigZ4 = 0
        };

        double x = Bmm150Compensation.CompensateX(rawMagnetormeterData.X, rhall, trimRegisterData);
        double y = Bmm150Compensation.CompensateY(rawMagnetormeterData.Y, rhall, trimRegisterData);
        double z = Bmm150Compensation.CompensateZ(rawMagnetormeterData.Z, rhall, trimRegisterData);

        // Calculated value should be: -1549.91882323
        Assert.Equal(Math.Ceiling(x), Math.Ceiling(-1549.918823), "Unexpected x-axis value.");

        // Calculated value should be: 3201.80615234
        Assert.Equal(Math.Ceiling(y), Math.Ceiling(3201.80615234), "Unexpected y-axis value.");

        // Calculated value should be: 26.20077896
        Assert.Equal(Math.Ceiling(z), Math.Ceiling(26.20077896), "Unexpected z-axis value.");
}

备注

  • BMI160嵌入BMM150。
产品 兼容和额外的计算目标框架版本。
.NET Framework net兼容。
兼容的目标框架
包含的目标框架(在包中)
有关目标框架.NET标准的更多信息。

NuGet包 (4)

显示依赖于nanoFramework.Iot.Device.Bmm150的前4个NuGet包

下载
nanoFramework.M5Core2

此包包含nanoFramework.M5Core2的程序集,适用于.NET nanoFramework C#项目。

nanoFramework.M5Core

此包包含nanoFramework.M5Core的程序集,适用于.NET nanoFramework C#项目。

nanoFramework.Fire

此包包括为.NET nanoFramework C#项目准备的nanoFramework.Fire程序集。

nanoFramework.M5Stack

此包包括为.NET nanoFramework C#项目准备的nanoFramework.M5Stack程序集。

GitHub仓库 (1)

显示最受关注的1个依赖nanoFramework.Iot.Device.Bmm150的GitHub仓库

仓库 星数
nanoframework/nanoFramework.IoT.Device
📦 本仓库包括各种传感器、芯片、显示屏、帽子以及驱动程序的.NET nanoFramework实现
版本 下载 最后更新
1.2.590 386 7/17/2024
1.2.570 453 6/14/2024
1.2.560 244 5/29/2024
1.2.552 181 5/17/2024
1.2.536 476 4/15/2024
1.2.514 448 3/22/2024
1.2.436 1,243 11/10/2023
1.2.416 314 11/8/2023
1.2.329 2,599 5/26/2023
1.2.313 538 5/12/2023
1.2.308 370 5/11/2023
1.2.302 197 5/10/2023
1.2.297 387 5/3/2023
1.2.273 1,571 3/17/2023
1.2.253 2,712 2/22/2023
1.2.222 1,629 1/9/2023
1.2.217 1,245 1/6/2023
1.2.215 789 1/6/2023
1.2.212 796 1/5/2023
1.2.208 539 1/3/2023
1.2.203 846 12/28/2022
1.2.159 1,205 11/14/2022
1.2.153 2,280 11/5/2022
1.2.141 3,018 10/25/2022
1.2.128 475 10/22/2022
1.2.87 8,515 9/15/2022
1.2.32 7,927 8/2/2022
1.1.116.8772 14,319 6/24/2022
1.1.113.2032 454 6/23/2022
1.1.97.17326 3,819 6/13/2022
1.1.92.53000 1,372 6/8/2022
1.1.58.10097 9,468 5/23/2022
1.1.3 16,130 4/15/2022
1.1.1 469 4/14/2022
1.0.300 4,942 3/31/2022
1.0.288-preview.114 149 3/25/2022
1.0.288-preview.113 121 3/25/2022
1.0.288-preview.106 136 3/23/2022
1.0.288-preview.104 113 3/22/2022
1.0.288-preview.100 127 3/19/2022
1.0.288-preview.99 134 3/18/2022
1.0.288-preview.98 120 3/18/2022
1.0.288-preview.93 156 3/15/2022
1.0.288-preview.86 175 3/8/2022
1.0.288-preview.65 181 2/18/2022
1.0.288-preview.50 176 2/5/2022
1.0.288-preview.48 141 2/4/2022
1.0.288-preview.41 150 1/31/2022
1.0.288-preview.29 194 1/28/2022
1.0.288-preview.22 186 1/27/2022
1.0.288-preview.20 144 1/27/2022
1.0.288-preview.19 131 1/27/2022
1.0.288-preview.5 173 1/24/2022
1.0.288-preview.1 160 1/21/2022
1.0.272 541 1/10/2022
1.0.260 772 12/10/2021
1.0.259 314 12/9/2021
1.0.218 511 10/18/2021
1.0.207 368 10/11/2021
1.0.191 333 9/29/2021
1.0.170 336 9/17/2021