![]() |
VOOZH | about |
dotnet add package nanoFramework.Iot.Device.Mpu6886 --version 1.2.952
NuGet\Install-Package nanoFramework.Iot.Device.Mpu6886 -Version 1.2.952
<PackageReference Include="nanoFramework.Iot.Device.Mpu6886" Version="1.2.952" />
<PackageVersion Include="nanoFramework.Iot.Device.Mpu6886" Version="1.2.952" />Directory.Packages.props
<PackageReference Include="nanoFramework.Iot.Device.Mpu6886" />Project file
paket add nanoFramework.Iot.Device.Mpu6886 --version 1.2.952
#r "nuget: nanoFramework.Iot.Device.Mpu6886, 1.2.952"
#:package nanoFramework.Iot.Device.Mpu6886@1.2.952
#addin nuget:?package=nanoFramework.Iot.Device.Mpu6886&version=1.2.952Install as a Cake Addin
#tool nuget:?package=nanoFramework.Iot.Device.Mpu6886&version=1.2.952Install as a Cake Tool
The MPU-6886 is a 6-axis motion tracking sensor that combines a 3-axis gyroscope and a 3-axis accelerometer including the following features:
Create the Mpu6886 class and pass the I2C device. By default the I2C address for this sensor is 0x68.
// I2C pins need to be configured, for example for pin 22 & 21 for
// the M5StickC Plus. These pins might be different for other boards.
Configuration.SetPinFunction(22, DeviceFunction.I2C1_CLOCK);
Configuration.SetPinFunction(21, DeviceFunction.I2C1_DATA);
I2cConnectionSettings settings = new(1, Mpu6886AccelerometerGyroscope.DefaultI2cAddress);
using (Mpu6886AccelerometerGyroscope ag = new(I2cDevice.Create(settings)))
{
Debug.WriteLine("Start calibration ...");
var offset = ag.Calibrate(1000);
Debug.WriteLine($"Calibration done, calculated offsets {offset.X} {offset.Y} {offset.Y}");
Debug.WriteLine($"Internal temperature: {ag.GetInternalTemperature().DegreesCelsius} C");
while (true)
{
var acc = ag.GetAccelerometer();
var gyr = ag.GetGyroscope();
Debug.WriteLine($"Accelerometer data x:{acc.X} y:{acc.Y} z:{acc.Z}");
Debug.WriteLine($"Gyroscope data x:{gyr.X} y:{gyr.Y} z:{gyr.Z}\n");
Thread.Sleep(100);
}
}
Start calibration ...
Calibration done, calculated offsets 49.189 -86.21099999 -86.21099999
Internal temperature: 64.21664626 C
Accelerometer data x:-0.041503906 y:0 z:1.056884765
Gyroscope data x:4.94384765 y:-8.60595703 z:-15.68603515
Accelerometer data x:-0.040771484 y:-0.0051269531 z:1.062988281
Gyroscope data x:4.94384765 y:-7.56835937 z:-15.014648437
Accelerometer data x:-0.046630859 y:-0.0068359375 z:1.055175781
Gyroscope data x:3.60107421 y:-7.62939453 z:-15.1977539
Accelerometer data x:-0.049560546 y:-0 z:1.061279296
Gyroscope data x:4.39453125 y:-7.32421875 z:-14.28222656
See for a complete sample application.
The gyroscope can be calibrated using the Calibrate function. With the iterations parameter
you can specify how many values should be read from the sensor to calculate an average (1000 iterations seems
to be a good number). During the calibration you want to keep the sensor still and in a fixed position (e.g. lying
flat on a table). The Calibrate function will write the values to the corresponding compensation registers
of the sensor, values are corrected when retrieved automatically.
The return value of the Calibrate method gives a vector containing the 3 (for the X,Y and Z axes) calculated
compensation values.
var offset = ag.Calibrate(1000);
Debug.WriteLine($"Calibration done, calculated offsets {offset.X} {offset.Y} {offset.Y}");
It is possible to write directly to the compensation registers using the SetGyroscopeOffset function. You might
want to do this when you create your own custom calibration method, or you retrieve existing calibration data from
a persisted data store or memory location.
⚠ When the devices reboots, the offset registers are cleared. So if you don't persist the calibration data yourself you will have to run the calibration method every time the device boots.
The sensor can be put in sleep mode by calling the Sleep function. After that the WakeUp function should be called.
Both for the gyroscope and accelerometer you can set the desired scales using the AccelerometerScale and GyroscopeScale
properties.
// Set the scale of the accelerometer to 2G
ag.AccelerometerScale = AccelerometerScale.Scale2G;
By default all gyroscope and accelerometer axes are enabled. If desired you can specify explicitly which axes should be enabled. In that case, all other axes will be disabled. When an axis is disabled, data can still be read for that axis but the values will not change anymore.
// Enable only the X axis of the gyroscope and accelerometer
ag.EnabledAxes = EnabledAxis.GyroscopeX | EnabledAxis.AccelerometerX;
The following features are enabled in the MPU6886 but not yet implemented in this driver:
0x05 to 0x0b: low noise to low power offset0x0d to 0x0F: self test0x1a: FIFO mode, DLPF (digital low pass filter)0x1d bit 0 to 3: DLPF0x1e bit 4 to 6: averaging filter for low power mode0x20 to 0x22: threshold for wake-on motion0x36: fsync interrupt status0x37: INT/DRDY pin config0x39 and 0x3a: FIFO watermark interrupt0x60 and 0x61: FIFO watermark interrupt0x68: signal path reset0x69: acc. intelligence control| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET Framework | net net is compatible. |
Showing the top 5 NuGet packages that depend on nanoFramework.Iot.Device.Mpu6886:
| Package | Downloads |
|---|---|
|
nanoFramework.M5Core2
This package includes the nanoFramework.M5Core2 assembly for .NET nanoFramework C# projects. |
|
|
nanoFramework.M5StickC
This package includes the nanoFramework.M5StickC assembly for .NET nanoFramework C# projects. |
|
|
nanoFramework.M5Core
This package includes the nanoFramework.M5Core assembly for .NET nanoFramework C# projects. |
|
|
nanoFramework.M5StickCPlus
This package includes the nanoFramework.M5StickCPlus assembly for .NET nanoFramework C# projects. |
|
|
nanoFramework.AtomMatrix
This package includes the nanoFramework.AtomMatrix assembly for .NET nanoFramework C# projects. |
Showing the top 1 popular GitHub repositories that depend on nanoFramework.Iot.Device.Mpu6886:
| Repository | Stars |
|---|---|
|
nanoframework/nanoFramework.M5Stack
📦 Board support package for M5Stack, M5StickC and M5StickCPlus for .NET nanoFramework
|
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.0-preview.85 | 63 | 6/1/2026 |
| 2.0.0-preview.80 | 63 | 5/27/2026 |
| 2.0.0-preview.73 | 95 | 5/20/2026 |
| 2.0.0-preview.69 | 56 | 5/18/2026 |
| 2.0.0-preview.62 | 76 | 5/13/2026 |
| 2.0.0-preview.45 | 96 | 4/29/2026 |
| 2.0.0-preview.32 | 80 | 4/20/2026 |
| 2.0.0-preview.16 | 96 | 3/10/2026 |
| 1.2.952 | 672 | 3/4/2026 |
| 1.2.907 | 1,595 | 10/2/2025 |
| 1.2.889 | 657 | 7/28/2025 |
| 1.2.869 | 1,204 | 4/2/2025 |
| 1.2.864 | 627 | 4/2/2025 |
| 1.2.852 | 930 | 3/11/2025 |
| 1.2.846 | 626 | 3/10/2025 |
| 1.2.822 | 2,070 | 2/26/2025 |
| 1.2.775 | 2,412 | 2/4/2025 |
| 1.2.772 | 334 | 2/4/2025 |
| 1.2.755 | 1,124 | 1/31/2025 |
| 1.2.743 | 713 | 1/20/2025 |