nanoFramework.Iot.Device.Lsm9Ds1 1.2.590

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

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

LSM9DS1 - 3D 加速计、陀螺仪和磁力计

LSM9DS1 内部使用2个总线

  • 加速度计和陀螺仪
  • 磁力计

因此功能已被分割成2个类,允许独立使用。

文档

  • 您可以在此处找到数据表

使用方法

重要:在创建“I2cDevice”之前,确保您已正确设置了I2C引脚,特别是对于ESP32之前的ESPLink,确保已安装“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总线的预设引脚。

加速度计和陀螺仪

class Program
{
    public const int I2cAddress = 0x6A;

    static void Main(string[] args)
    {
        using (var ag = new Lsm9Ds1AccelerometerAndGyroscope(CreateI2cDevice()))
        {
            while (true)
            {
                Debug.WriteLine($"Acceleration={ag.Acceleration}");
                Debug.WriteLine($"AngularRate={ag.AngularRate}");
                Thread.Sleep(100);
            }
        }
    }

    private static I2cDevice CreateI2cDevice()
    {
        var settings = new I2cConnectionSettings(1, I2cAddress);
        return I2cDevice.Create(settings);
    }
}

磁力计

class Magnetometer
{
    public const int I2cAddress = 0x1C;

    public static void Run()
    {
        using (var m = new Lsm9Ds1Magnetometer(CreateI2cDevice()))
        {
            Debug.WriteLine("Calibrating...");
            Debug.WriteLine("Move the sensor around Z for the next 20 seconds, try covering every angle");
            Stopwatch sw = Stopwatch.StartNew();
            Vector3 min = m.MagneticInduction;
            Vector3 max = m.MagneticInduction;
            while (sw.ElapsedMilliseconds < 20 * 1000)
            {
                Vector3 sample = m.MagneticInduction;
                min = Vector3.Min(min, sample);
                max = Vector3.Max(max, sample);
                Thread.Sleep(50);
            }
            Debug.WriteLine("Stop moving for some time...");
            Thread.Sleep(3000);
            const int intervals = 32;
            bool[,] data = new bool[32,32];
            Vector3 size = max - min;
            int n = 0;
            while (true)
            {
                n++;
                Vector3 sample = m.MagneticInduction;
                Vector3 pos = Vector3.Divide(Vector3.Multiply((sample - min), intervals - 1), size);
                int x = Math.Clamp((int)pos.X, 0, intervals - 1);
                int y = Math.Clamp((int)pos.Y, 0, intervals - 1);
                data[x, y] = true;
                if (n % 10 == 0)
                {
                    Debug.WriteLine("Now move the sensor around again but slower...");
                    for (int i = 0; i < intervals; i++)
                    {
                        for (int j = 0; j < intervals; j++)
                        {
                            if (i == x && y == j)
                            {
                                Debug.Write('#');
                            }
                            else
                            {
                                Debug.Write(data[i, j] ? '#' : ' ');
                            }
                        }
                        Debug.WriteLine();
                    }
                }
                Thread.Sleep(50);
            }
        }
    }

    private static I2cDevice CreateI2cDevice()
    {
        var settings = new I2cConnectionSettings(1, I2cAddress);
        return I2cDevice.Create(settings);
    }
}
产品 兼容和额外计算的目标框架版本。
.NET Framework net is compatible. 
兼容的目标框架
包含的目标框架(在包中)
了解更多关于目标框架.NET Standard的信息。

NuGet 包

此包未被任何 NuGet 包使用。

GitHub 仓库

此包未被任何流行 GitHub 仓库使用。

版本 下载 最后更新
1.2.590 68 7/17/2024
1.2.570 81 6/14/2024
1.2.436 230 11/10/2023
1.2.416 102 11/8/2023
1.2.329 140 5/26/2023
1.2.313 132 5/12/2023
1.2.297 141 5/3/2023
1.2.253 240 2/22/2023
1.2.222 276 1/9/2023
1.2.217 298 1/6/2023
1.2.212 286 1/5/2023
1.2.208 289 1/3/2023
1.2.203 276 12/28/2022
1.2.159 347 11/14/2022
1.2.153 344 11/5/2022
1.2.141 376 10/25/2022
1.2.128 373 10/22/2022
1.2.87 473 9/15/2022
1.2.82 473 9/14/2022
1.1.116.8772 419 6/24/2022
1.1.113.2032 416 6/23/2022
1.1.97.17326 425 6/13/2022
1.1.92.53000 396 6/8/2022
1.1.3 451 4/15/2022
1.1.1 421 4/14/2022
1.0.300 415 3/31/2022
1.0.288-preview.114 114 3/25/2022
1.0.288-preview.113 104 3/25/2022
1.0.288-preview.106 105 3/23/2022
1.0.288-preview.104 97 3/22/2022
1.0.288-preview.100 106 3/19/2022
1.0.288-preview.98 114 3/18/2022
1.0.288-preview.95 114 3/15/2022
1.0.288-preview.93 107 3/15/2022
1.0.288-preview.87 106 3/10/2022
1.0.288-preview.65 109 2/18/2022
1.0.288-preview.48 127 2/4/2022
1.0.288-preview.41 120 1/31/2022
1.0.288-preview.29 125 1/28/2022
1.0.288-preview.20 132 1/27/2022
1.0.288-preview.1 112 1/21/2022
1.0.259 307 12/9/2021
1.0.155 299 8/31/2021
1.0.130 150 7/6/2021
1.0.129 152 7/6/2021
1.0.125 188 7/5/2021
1.0.121 194 6/29/2021
1.0.119 223 6/28/2021
1.0.52 199 5/24/2021