nanoFramework.Iot.Device.Lsm9Ds1
1.2.852
Prefix Reserved
dotnet add package nanoFramework.Iot.Device.Lsm9Ds1 --version 1.2.852
NuGet\Install-Package nanoFramework.Iot.Device.Lsm9Ds1 -Version 1.2.852
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="nanoFramework.Iot.Device.Lsm9Ds1" Version="1.2.852" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add nanoFramework.Iot.Device.Lsm9Ds1 --version 1.2.852
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: nanoFramework.Iot.Device.Lsm9Ds1, 1.2.852"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install nanoFramework.Iot.Device.Lsm9Ds1 as a Cake Addin #addin nuget:?package=nanoFramework.Iot.Device.Lsm9Ds1&version=1.2.852 // Install nanoFramework.Iot.Device.Lsm9Ds1 as a Cake Tool #tool nuget:?package=nanoFramework.Iot.Device.Lsm9Ds1&version=1.2.852
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
LSM9DS1 - 3D accelerometer, gyroscope and magnetometer
LSM9DS1 internally uses 2 buses:
- Accelerometer and gyroscope
- Magnetometer
and therefore functionality has been split into 2 classes which allows using them independently.
Documentation
- You can find the datasheet here
Usage
Important: make sure you properly setup the I2C pins especially for ESP32 before creating the I2cDevice
, make sure you install the 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);
For other devices like STM32, please make sure you're using the preset pins for the I2C bus you want to use.
Accelerometer and gyroscope
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);
}
}
Magnetometer
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);
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net is compatible. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
- nanoFramework.CoreLibrary (>= 1.17.7)
- nanoFramework.System.Buffers.Binary.BinaryPrimitives (>= 1.2.848)
- nanoFramework.System.Device.I2c (>= 1.1.28)
- nanoFramework.System.Device.Model (>= 1.2.848)
- nanoFramework.System.Diagnostics.Stopwatch (>= 1.2.848)
- nanoFramework.System.Math (>= 1.5.112)
- nanoFramework.System.Numerics (>= 1.2.848)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.2.852 | 0 | 3/11/2025 |
1.2.822 | 103 | 2/26/2025 |
1.2.775 | 96 | 2/4/2025 |
1.2.772 | 89 | 2/4/2025 |
1.2.755 | 94 | 1/31/2025 |
1.2.737 | 68 | 1/13/2025 |
1.2.704 | 99 | 12/18/2024 |
1.2.696 | 86 | 12/16/2024 |
1.2.673 | 108 | 10/23/2024 |
1.2.662 | 100 | 10/11/2024 |
1.2.631 | 120 | 8/28/2024 |
1.2.590 | 104 | 7/17/2024 |
1.2.570 | 114 | 6/14/2024 |
1.2.436 | 261 | 11/10/2023 |
1.2.416 | 135 | 11/8/2023 |
1.2.329 | 170 | 5/26/2023 |
1.2.313 | 160 | 5/12/2023 |
1.2.297 | 167 | 5/3/2023 |
1.2.253 | 275 | 2/22/2023 |
1.2.222 | 309 | 1/9/2023 |
1.2.217 | 329 | 1/6/2023 |
1.2.212 | 317 | 1/5/2023 |
1.2.208 | 323 | 1/3/2023 |
1.2.203 | 309 | 12/28/2022 |
1.2.159 | 384 | 11/14/2022 |
1.2.153 | 379 | 11/5/2022 |
1.2.141 | 410 | 10/25/2022 |
1.2.128 | 407 | 10/22/2022 |
1.2.87 | 510 | 9/15/2022 |
1.2.82 | 508 | 9/14/2022 |
1.1.116.8772 | 457 | 6/24/2022 |
1.1.113.2032 | 452 | 6/23/2022 |
1.1.97.17326 | 463 | 6/13/2022 |
1.1.92.53000 | 434 | 6/8/2022 |
1.1.3 | 492 | 4/15/2022 |
1.1.1 | 459 | 4/14/2022 |
1.0.300 | 457 | 3/31/2022 |
1.0.288-preview.114 | 139 | 3/25/2022 |
1.0.288-preview.113 | 129 | 3/25/2022 |
1.0.288-preview.106 | 126 | 3/23/2022 |
1.0.288-preview.104 | 121 | 3/22/2022 |
1.0.288-preview.100 | 130 | 3/19/2022 |
1.0.288-preview.98 | 139 | 3/18/2022 |
1.0.288-preview.95 | 140 | 3/15/2022 |
1.0.288-preview.93 | 132 | 3/15/2022 |
1.0.288-preview.87 | 132 | 3/10/2022 |
1.0.288-preview.65 | 137 | 2/18/2022 |
1.0.288-preview.48 | 153 | 2/4/2022 |
1.0.288-preview.41 | 146 | 1/31/2022 |
1.0.288-preview.29 | 152 | 1/28/2022 |
1.0.288-preview.20 | 156 | 1/27/2022 |
1.0.288-preview.1 | 136 | 1/21/2022 |
1.0.259 | 347 | 12/9/2021 |
1.0.155 | 340 | 8/31/2021 |
1.0.130 | 180 | 7/6/2021 |
1.0.129 | 180 | 7/6/2021 |
1.0.125 | 217 | 7/5/2021 |
1.0.121 | 222 | 6/29/2021 |
1.0.119 | 252 | 6/28/2021 |
1.0.52 | 228 | 5/24/2021 |