nanoFramework.M5Stack 1.0.0-preview.94

Prefix Reserved
Suggested Alternatives

nanoFramework.M5Core

This is a prerelease version of nanoFramework.M5Stack.
There is a newer version of this package available.
See the version list below for details.
dotnet add package nanoFramework.M5Stack --version 1.0.0-preview.94                
NuGet\Install-Package nanoFramework.M5Stack -Version 1.0.0-preview.94                
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-preview.94" />                
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-preview.94                
#r "nuget: nanoFramework.M5Stack, 1.0.0-preview.94"                
#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-preview.94&prerelease

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

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

Usage

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.

Screen

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

M5Stack.InitializeScreen();

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:

Console.Clear();

// 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.ResetColor();
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.

Buttons

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)
{
    Thread.Sleep(10);
}

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
ag.Calibrate(100);
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.

Magnetometer

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.
mag.CalibrateMagnetometer(100);
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}  ");

SerialPort

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

// You can access any of the Serial Port feature
M5Stack.SerialPort.Open(115200);
// Do anything else you need
M5Stack.SerialPort.Close();

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);

DAC

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

Led

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

// This will toggle the led:
M5StickC.Led.Toggle();

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.

Credits

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

License

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)
Included target framework(s) (in package)
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 255 12/27/2021 1.0.1-preview.3 is deprecated because it is no longer maintained.
1.0.0 493 12/23/2021 1.0.0 is deprecated because it is no longer maintained.
1.0.0-preview.99 188 12/23/2021 1.0.0-preview.99 is deprecated because it is no longer maintained.
1.0.0-preview.98 188 12/23/2021 1.0.0-preview.98 is deprecated because it is no longer maintained.
1.0.0-preview.94 242 11/12/2021 1.0.0-preview.94 is deprecated because it is no longer maintained.
1.0.0-preview.91 223 11/9/2021 1.0.0-preview.91 is deprecated because it is no longer maintained.
1.0.0-preview.88 226 11/9/2021 1.0.0-preview.88 is deprecated because it is no longer maintained.
1.0.0-preview.86 204 11/3/2021 1.0.0-preview.86 is deprecated because it is no longer maintained.
1.0.0-preview.83 261 10/28/2021 1.0.0-preview.83 is deprecated because it is no longer maintained.
1.0.0-preview.81 231 10/27/2021 1.0.0-preview.81 is deprecated because it is no longer maintained.
1.0.0-preview.77 246 10/27/2021 1.0.0-preview.77 is deprecated because it is no longer maintained.
1.0.0-preview.75 239 10/27/2021 1.0.0-preview.75 is deprecated because it is no longer maintained.
1.0.0-preview.72 295 9/11/2021 1.0.0-preview.72 is deprecated because it is no longer maintained.
1.0.0-preview.70 213 7/16/2021 1.0.0-preview.70 is deprecated because it is no longer maintained.
1.0.0-preview.68 225 7/14/2021 1.0.0-preview.68 is deprecated because it is no longer maintained.
1.0.0-preview.66 252 6/20/2021 1.0.0-preview.66 is deprecated because it is no longer maintained.
1.0.0-preview.64 274 6/9/2021 1.0.0-preview.64 is deprecated because it is no longer maintained.
1.0.0-preview.62 216 6/8/2021 1.0.0-preview.62 is deprecated because it is no longer maintained.
1.0.0-preview.60 214 6/4/2021 1.0.0-preview.60 is deprecated because it is no longer maintained.
1.0.0-preview.58 238 6/1/2021 1.0.0-preview.58 is deprecated because it is no longer maintained.
1.0.0-preview.56 257 6/1/2021 1.0.0-preview.56 is deprecated because it is no longer maintained.
1.0.0-preview.54 252 6/1/2021 1.0.0-preview.54 is deprecated because it is no longer maintained.
1.0.0-preview.53 254 6/1/2021 1.0.0-preview.53 is deprecated because it is no longer maintained.
1.0.0-preview.51 250 6/1/2021 1.0.0-preview.51 is deprecated because it is no longer maintained.
1.0.0-preview.49 266 6/1/2021 1.0.0-preview.49 is deprecated because it is no longer maintained.
1.0.0-preview.47 265 6/1/2021 1.0.0-preview.47 is deprecated because it is no longer maintained.
1.0.0-preview.46 266 6/1/2021 1.0.0-preview.46 is deprecated because it is no longer maintained.
1.0.0-preview.44 447 6/1/2021 1.0.0-preview.44 is deprecated because it is no longer maintained.
1.0.0-preview.39 249 5/31/2021 1.0.0-preview.39 is deprecated because it is no longer maintained.
1.0.0-preview.37 255 5/31/2021 1.0.0-preview.37 is deprecated because it is no longer maintained.
1.0.0-preview.35 242 5/30/2021 1.0.0-preview.35 is deprecated because it is no longer maintained.
1.0.0-preview.33 219 5/26/2021 1.0.0-preview.33 is deprecated because it is no longer maintained.
1.0.0-preview.31 210 5/20/2021 1.0.0-preview.31 is deprecated because it is no longer maintained.
1.0.0-preview.29 218 5/14/2021 1.0.0-preview.29 is deprecated because it is no longer maintained.
1.0.0-preview.27 211 5/5/2021 1.0.0-preview.27 is deprecated because it is no longer maintained.
1.0.0-preview.23 236 4/11/2021 1.0.0-preview.23 is deprecated because it is no longer maintained.
1.0.0-preview.19 215 3/3/2021 1.0.0-preview.19 is deprecated because it is no longer maintained.
1.0.0-preview.14 337 7/4/2020 1.0.0-preview.14 is deprecated because it is no longer maintained.
1.0.0-preview.11 312 10/21/2020 1.0.0-preview.11 is deprecated because it is no longer maintained.
1.0.0-preview.9 357 10/1/2020 1.0.0-preview.9 is deprecated because it is no longer maintained.
1.0.0-preview.2 301 9/19/2020 1.0.0-preview.2 is deprecated because it is no longer maintained.