nanoFramework.M5Stack 1.0.0

The ID prefix of this package has been reserved for one of the owners of this package by Prefix Reserved
.NET Framework
Suggested Alternatives


There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package nanoFramework.M5Stack --version 1.0.0
NuGet\Install-Package nanoFramework.M5Stack -Version 1.0.0
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.M5Stack" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add nanoFramework.M5Stack --version 1.0.0
#r "nuget: nanoFramework.M5Stack, 1.0.0"
#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.M5Stack as a Cake Addin
#addin nuget:?package=nanoFramework.M5Stack&version=1.0.0

// Install nanoFramework.M5Stack as a Cake Tool
#tool nuget:?package=nanoFramework.M5Stack&version=1.0.0

Quality Gate Status Reliability Rating License NuGet #yourfirstpr Discord

nanoFramework logo

Welcome to the .NET nanoFramework M5Stack Library repository

Build status

Component Build Status NuGet Package
nanoFramework.M5Stack Build Status NuGet
nanoFramework.M5Stack (preview) Build Status NuGet
nanoFramework.M5Stick Build Status NuGet
nanoFramework.M5Stick (preview) Build Status NuGet
nanoFramework.M5StickCPlus Build Status NuGet
nanoFramework.M5StickCPlus (preview) Build Status NuGet
nanoFramework.M5Core2 Build Status NuGet
nanoFramework.M5Core2 (preview) Build Status NuGet


Those 3 nugets provide a support for the M5Stack, M5StickC, M5StickCPlus and M5Core2.

They bring support for the screens as well and require to be flashed with the proper image:

# Replace the com port number by your COM port
# For the M5Stack:
nanoff --target M5Stack --update --preview --serialport COM3
# For the M5StickC:
nanoff --target M5StickC --update --preview --serialport COM3 --baud 115200
# For the M5StickCPlus:
nanoff --target M5StickCPlus --update --preview --serialport COM3 --baud 115200
# For the M5Core2:
nanoff --target M5Core2 --update --preview --serialport COM3

Once you have the nugets, you can then enjoy accessing the screen, the accelerometer, get a Grove I2C connecter, add events on the buttons. And you don't even need to think about anything, all is done for you in the most transparent way!

Note: All the classes that you'll have access are all using the Lazy pattern to be instantiated including the screen. This have the advantage to use as little memory and setup time as possible.

In the samples below, we'll use either M5Stack, either M5Stick as examples, they are all working in a very similar way.


The only thing you need to do to access the screen is to initialize it:


Once you've initialized it, you can access both a Screen static class and a Console static class.

THe Screen one brings primitives to write directly on the screen points or scare of colors as well as writing a text.

For example, you can write a blue square of 10x10 at the position 0, 0 like this:

ushort[] toSend = new ushort[100];
ushort blue = ColorUtility.To16Bpp(Color.Blue);

for (int i = 0; i < toSend.Length; i++)
    toSend[i] = blue;

Screen.Write(0, 0, 10, 10, toSend);

The Console class works in a similar way as the classic System.Console:


// Test the console display
Console.Write("This is a short text. ");
Console.ForegroundColor = Color.Red;
Console.WriteLine("This one displays in red after the previous one and is already at the next line.");
Console.BackgroundColor = Color.Yellow;
Console.ForegroundColor = Color.RoyalBlue;
Console.WriteLine("And this is blue on yellow background");
Console.CursorLeft = 0;
Console.CursorTop = 8;
Console.Write("This is white on black again and on 9th line");

Note: You can change the default font as well, you need to provide it as a property. The Cursor positions are calculated with the largest possible character.

M5Core2 has SPRAM, so you can get a full screen buffer as well. Refer to the Graphics samples to understand all you can do with it.


The main buttons except the power buttons are exposed.

On the M5Stack they are called ButtonLeft, ButtonCenter and ButtonRight. You can get access to the events as well. For example:

M5Stack.ButtonLeft.Press += (sender, e) =>
    Console.ForegroundColor = Color.Yellow;
    Console.CursorLeft = 0;
    Console.CursorTop = 0;
    Console.Write($"Left Pressed  ");

On the M5StickC/CPlus they are called ButtonM5 and ButtonRight. You can get access to the status of the button, the events and everything you need. For example:

while (!M5StickC.ButtonRight.IsPressed)

M5StickC.M5Button.IsHoldingEnabled = true;
M5StickC.M5Button.Holding += (sender, e) =>
    Console.Write("M5 button hold long.");

Note: The M5Core2 has touch screen and the buttons are part of it. So far .NET nanoFramework does not have the support for them and thus, they are not supported yet. PR to improve this situation welcome!

Power management

Both M5Stack and M5StickC/CPlus are exposing their power management elements. It is not recommended to change any default value except if you know what you are doing.

Please refer to the detailed examples for the AXP192 used in the M5StickC/CPlus; M5Core2 and IP5306 for the M5Stack.

Accelerometer and Gyroscope

You can get access to the Accelerometer and Gyroscope like this:

var ag = M5Stack.AccelerometerGyroscope;
// Do not move the M5Stack/M5Stick during the calibration
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");

Refer to the MPU6886 documentation for more detailed usage on this sensor.


The M5Stack has a magnetometer, you can access it as well:

var mag = M5Stack.Magnetometer;
// It is more than strongly recommended to calibrate the magnetometer.
// Move the M5Stack in all directions to have a proper calibration.
var magVal = mag.ReadMagnetometer();
Console.WriteLine($"x={magVal.X:N2}   ");
Console.WriteLine($"y={magVal.Y:N2}   ");
Console.WriteLine($"Z={magVal.Z:N2}   ");
var headDir = Math.Atan2(magVal.X, magVal.Y) * 180.0 / Math.PI;
Console.WriteLine($"h={headDir:N2}  ");


The M5Stack and M5Core2 can provide a Serial Port, just get it like this:

// You can access any of the Serial Port feature
// Do anything else you need

Refer to the SerialPort documentation for more information.

ADC Channels

ADC Channels are pre setup on the M5Stack, access them like this:

// This will give you the ADC1 channel 7 which is on pin 35
AdcChannel myChannel = M5Stack.GetAdcGpio(35);

Refer to the M5Stack documentation to have the mapping of the ADC channels and the pins.

I2C Device/Grove

You can get an I2cDevice/Grove like this:

// In this example, the I2C address of the device is 0x42:
I2cDevice myDevice = M5Stack.GetGrove(0x42);
// replacing GetGrove by GetI2cDevice will have the same impact

SPI Device

The M5Stack provides as well an SPiDevice:

// In this case GPIO5 will be used as chip select:
SpiDevice mySpi = M5Stack.GetSpiDevice(5);

GPIO Controller

Similar as previously, you can get the GpioController on any of the M5Stack, M5Core2 and M5StickC/CPlus:

// This will open the GPIO 36 as output
var pin5 = M5StickC.GpioController.OpenPin(36, PinMode.Output);


The M5Stack exposes 2 DAC and you can access them thru the Dac1 and Dac2 properties. Refer to the DAC documentation for more information.


The M5StickC/CPlus exposes a led. You can access it thru the Led property:

// This will toggle the led:

Infrared Led

The M5StickC/CPlus exposes an infrared led. You can access it thru the InfraredLed property. This will give you a TransmitterChannel. Check out the sample pack to understand how to use it.

Feedback and documentation

For documentation, providing feedback, issues and finding out how to contribute please refer to the Home repo.

Join our Discord community here.


The list of contributors to this project can be found at CONTRIBUTORS.


The nanoFramework Class Libraries are licensed under the MIT license.

Code of Conduct

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behaviour in our community. For more information see the .NET Foundation Code of Conduct.

.NET Foundation

This project is supported by the .NET Foundation.

Product Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

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.0.1-preview.3 192 12/27/2021
1.0.0 326 12/23/2021
1.0.0-preview.99 146 12/23/2021
1.0.0-preview.98 147 12/23/2021
1.0.0-preview.94 197 11/12/2021
1.0.0-preview.91 177 11/9/2021
1.0.0-preview.88 187 11/9/2021
1.0.0-preview.86 162 11/3/2021
1.0.0-preview.83 215 10/28/2021
1.0.0-preview.81 188 10/27/2021
1.0.0-preview.77 199 10/27/2021
1.0.0-preview.75 199 10/27/2021
1.0.0-preview.72 250 9/11/2021
1.0.0-preview.70 168 7/16/2021
1.0.0-preview.68 181 7/14/2021
1.0.0-preview.66 210 6/20/2021
1.0.0-preview.64 232 6/9/2021
1.0.0-preview.62 168 6/8/2021
1.0.0-preview.60 174 6/4/2021
1.0.0-preview.58 196 6/1/2021
1.0.0-preview.56 212 6/1/2021
1.0.0-preview.54 209 6/1/2021
1.0.0-preview.53 208 6/1/2021
1.0.0-preview.51 209 6/1/2021
1.0.0-preview.49 220 6/1/2021
1.0.0-preview.47 219 6/1/2021
1.0.0-preview.46 222 6/1/2021
1.0.0-preview.44 172 6/1/2021
1.0.0-preview.39 201 5/31/2021
1.0.0-preview.37 210 5/31/2021
1.0.0-preview.35 200 5/30/2021
1.0.0-preview.33 178 5/26/2021
1.0.0-preview.31 163 5/20/2021
1.0.0-preview.29 174 5/14/2021
1.0.0-preview.27 167 5/5/2021
1.0.0-preview.23 194 4/11/2021
1.0.0-preview.19 167 3/3/2021
1.0.0-preview.14 290 7/4/2020
1.0.0-preview.11 269 10/21/2020
1.0.0-preview.9 312 10/1/2020
1.0.0-preview.2 258 9/19/2020