nanoFramework.M5Core 1.0.1-preview.8

Prefix Reserved
This is a prerelease version of nanoFramework.M5Core.
There is a newer version of this package available.
See the version list below for details.
dotnet add package nanoFramework.M5Core --version 1.0.1-preview.8
                    
NuGet\Install-Package nanoFramework.M5Core -Version 1.0.1-preview.8
                    
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.M5Core" Version="1.0.1-preview.8" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="nanoFramework.M5Core" Version="1.0.1-preview.8" />
                    
Directory.Packages.props
<PackageReference Include="nanoFramework.M5Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add nanoFramework.M5Core --version 1.0.1-preview.8
                    
#r "nuget: nanoFramework.M5Core, 1.0.1-preview.8"
                    
#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.
#:package nanoFramework.M5Core@1.0.1-preview.8
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=nanoFramework.M5Core&version=1.0.1-preview.8&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=nanoFramework.M5Core&version=1.0.1-preview.8&prerelease
                    
Install as a Cake Tool

Quality Gate Status Reliability Rating License NuGet #yourfirstpr Discord

nanoFramework logo


Welcome to the .NET nanoFramework M5Stack Libraries repository

Build status

Component Build Status NuGet Package
nanoFramework.M5Core Build Status NuGet
nanoFramework.M5Core (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

These NuGet packages provide a support for M5Stack products:

NOTE1: Before trying to add NuGet packages to your projects and/or before flashing the devices (see next section) using MS Visual Studio (VS), open VS > Tools > Options > NuGet Package Manager > Package Sources and make sure that it contains an entry pointing to https://api.nuget.org/v3/index.json , otherwise add it. NOTE2: When invoking VS > Project > Manage NuGet Packages make sure that in the Package source drop-down menu (right upper corner) "nuget.org" is selected. Also if you're using preview version the "include prerelease" checkbox should be clicked/selected as well.

The NuGets bring support for the screens as well and require to be flashed with the proper image (using nanoff dotnet CLI). On the examples below replace COM3 with the appropriate number of the COM port to which your device is connected. (on Windows you can check this in the Device Manager).

For the M5Core:

nanoff --target M5Core --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

For the M5Core2:

nanoff --target M5Core2 --update --preview --serialport COM3

NOTE3: If the nanoff commands fails, make sure you have followed instruction from NOTE1 above.

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 M5Core or M5Stick as examples, they are all working in a very similar way.

Namespaces

Make sure you add the proper namespaces reference to your C# program header e.g. using nanoFramework;

Screen

The only thing you need to do to access the screen is to initialize it (please note that InitializeScreen() it's target specific) e.g.:

For Core:

M5Core.InitializeScreen();

For StickCPlus:

M5StickCPlus.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 colours 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. In order to use it you have to reference it using the fully qualified name of the methods, like this:

nanoFramework.Console.Clear();

// Test the console display
nanoFramework.Console.Write("This is a short text. ");
nanoFramework.Console.ForegroundColor = nanoFramework.Presentation.Media.Color.Red;
nanoFramework.Console.WriteLine("This one displays in red after the previous one and is already at the next line.");
nanoFramework.Console.BackgroundColor = nanoFramework.Presentation.Media.Color.Yellow;
nanoFramework.Console.ForegroundColor = nanoFramework.Presentation.Media.Color.RoyalBlue;
nanoFramework.Console.WriteLine("And this is blue on yellow background");
nanoFramework.Console.ResetColor();
nanoFramework.Console.CursorLeft = 0;
nanoFramework.Console.CursorTop = 8;
nanoFramework.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 "virtual"". At the time of this writing the .NET nanoFramework team is implementing and testing the touch-screen (touch-panel) functionality (will be released soon).

Power management

The M5Core 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 M5Core.

Accelerometer and Gyroscope

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

var ag = M5Core.AccelerometerGyroscope;
// Do not move the M5Core/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 M5Core has a magnetometer, you can access it as well:

var mag = M5Core.Magnetometer;
// It is more than strongly recommended to calibrate the magnetometer.
// Move the M5Core 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 M5Core and M5Core2 can provide a Serial Port, just get it like this:

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

Refer to the SerialPort documentation for more information.

ADC Channels

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

// This will give you the ADC1 channel 7 which is on pin 35
AdcChannel myChannel = M5Core.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 = M5Core.GetGrove(0x42);
// replacing GetGrove by GetI2cDevice will have the same impact

SPI Device

The M5Core provides as well an SpiDevice:

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

GPIO Controller

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

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

DAC

The M5Core 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.1.281 91 14 days ago
1.1.280 202 3 months ago
1.1.279 195 4 months ago
1.1.278 198 4 months ago
1.1.277 200 4 months ago
1.1.276 189 5 months ago
1.1.275 194 5 months ago
1.1.274 250 5 months ago
1.1.273 176 5 months ago
1.1.272 149 5 months ago
1.1.271 133 6 months ago
1.1.270 134 6 months ago
1.1.269 142 6 months ago
1.1.268 152 6 months ago
1.1.267 131 6 months ago
1.1.266 143 6 months ago
1.1.265 155 6 months ago
1.1.264 143 6 months ago
1.1.263 139 6 months ago
1.1.262 154 6 months ago
1.1.261 136 6 months ago
1.1.260 125 6 months ago
1.1.259 134 6 months ago
1.1.255 140 7 months ago
1.1.253 156 7 months ago
1.1.252 145 8 months ago
1.1.249 145 8 months ago
1.1.248 126 8 months ago
1.1.247 164 8 months ago
1.1.246 162 9 months ago
1.1.245 165 10 months ago
1.1.244 130 10 months ago
1.1.243 141 10 months ago
1.1.242 150 10/11/2024
1.1.241 136 10/4/2024
1.1.240 144 10/2/2024
1.1.239 149 9/27/2024
1.1.238 145 9/6/2024
1.1.236 158 8/30/2024
1.1.235 162 8/28/2024
1.1.234 177 8/16/2024
1.1.232 134 7/31/2024
1.1.229 157 7/19/2024
1.1.228 153 7/17/2024
1.1.227 138 7/12/2024
1.1.225 160 6/28/2024
1.1.223 158 6/19/2024
1.1.220 165 5/31/2024
1.1.217 171 5/15/2024
1.1.215 156 5/10/2024
1.1.213 169 4/17/2024
1.1.211 165 4/15/2024
1.1.209 175 4/5/2024
1.1.207 141 3/27/2024
1.1.203 171 2/28/2024
1.1.201 192 1/31/2024
1.1.199 164 1/26/2024
1.1.197 161 1/24/2024
1.1.187 283 11/17/2023
1.1.185 173 11/14/2023
1.1.183 193 11/9/2023
1.1.180 173 11/8/2023
1.1.177 220 10/11/2023
1.1.175 212 9/29/2023
1.1.171 213 9/8/2023
1.1.169 187 9/6/2023
1.1.167 237 8/18/2023
1.1.163 267 8/2/2023
1.1.161 236 7/28/2023
1.1.157 238 7/19/2023
1.1.155 231 7/14/2023
1.1.152 234 6/21/2023
1.1.150 215 6/14/2023
1.1.148 238 6/7/2023
1.1.146 225 5/31/2023
1.1.144 244 5/24/2023
1.1.142 254 5/17/2023
1.1.139 243 5/11/2023
1.1.137 279 5/5/2023
1.1.135 314 4/5/2023
1.1.133 323 3/29/2023
1.1.131 342 3/24/2023
1.1.128 330 3/17/2023
1.1.125 326 3/16/2023
1.1.123 325 3/13/2023
1.1.121 350 3/9/2023
1.1.119 339 2/27/2023
1.1.117 362 2/27/2023
1.1.115 358 2/22/2023
1.1.113 351 2/20/2023
1.1.111 330 2/16/2023
1.1.106 385 1/10/2023
1.1.104 386 1/9/2023
1.1.102 388 1/6/2023
1.1.100 391 1/6/2023
1.1.98 424 1/5/2023
1.1.96 403 12/29/2022
1.1.90 459 11/15/2022
1.1.88 456 11/14/2022
1.1.86 456 11/5/2022
1.1.84 482 11/5/2022
1.1.82 431 11/4/2022
1.1.80 452 11/3/2022
1.1.78 480 11/1/2022
1.1.76 473 10/27/2022
1.1.70 518 10/13/2022
1.1.68 517 10/12/2022
1.1.64 484 10/7/2022
1.1.62 505 10/7/2022
1.1.58 585 9/23/2022
1.1.55 555 9/23/2022
1.1.53 529 9/22/2022
1.1.47 548 9/21/2022
1.1.45 558 9/16/2022
1.1.42 546 9/15/2022
1.1.40 520 9/8/2022
1.1.38 528 9/7/2022
1.1.36 531 9/3/2022
1.1.34 553 8/15/2022
1.1.32 566 8/6/2022
1.1.30 514 8/5/2022
1.1.28 528 8/4/2022
1.1.26 563 8/3/2022
1.1.24 527 8/3/2022
1.1.22 539 8/2/2022
1.1.20 592 7/30/2022
1.1.18 537 7/26/2022
1.1.16 543 7/24/2022
1.1.14 540 7/23/2022
1.1.12 565 7/13/2022
1.1.7 552 7/7/2022
1.1.5 591 7/7/2022
1.1.3 592 7/6/2022
1.1.1 565 7/5/2022
1.0.107.13280 555 7/1/2022
1.0.105.49254 593 6/30/2022
1.0.102.851 579 6/28/2022
1.0.100.17145 569 6/28/2022
1.0.98.48733 589 6/28/2022
1.0.96.40373 560 6/26/2022
1.0.92.59206 590 6/24/2022
1.0.90.38187 561 6/16/2022
1.0.88.50207 542 6/15/2022
1.0.86.52668 544 6/14/2022
1.0.83.14512 597 6/13/2022
1.0.81.41619 548 6/8/2022
1.0.79.53990 554 6/3/2022
1.0.77.26764 549 6/3/2022
1.0.75.37268 556 6/1/2022
1.0.72.43325 563 5/31/2022
1.0.70.15497 555 5/31/2022
1.0.68.55953 573 5/31/2022
1.0.66.24331 524 5/27/2022
1.0.64.6330 558 5/26/2022
1.0.62.28047 533 5/26/2022
1.0.60.49583 547 5/25/2022
1.0.58.20063 549 5/24/2022
1.0.56.35800 554 5/23/2022
1.0.54.60782 564 5/20/2022
1.0.51.48271 582 5/12/2022
1.0.49.30985 557 5/6/2022
1.0.46 548 5/5/2022
1.0.42 569 4/26/2022
1.0.40 570 4/25/2022
1.0.38 564 4/24/2022
1.0.36 570 4/23/2022
1.0.34 571 4/22/2022
1.0.32 550 4/22/2022
1.0.30 554 4/21/2022
1.0.26 580 4/21/2022
1.0.24 548 4/20/2022
1.0.22 580 4/19/2022
1.0.20 553 4/18/2022
1.0.18 564 4/17/2022
1.0.16 565 4/16/2022
1.0.14 564 4/15/2022
1.0.12 616 4/13/2022
1.0.10 576 4/6/2022
1.0.8 564 4/4/2022
1.0.6 559 4/3/2022
1.0.4 571 3/31/2022
1.0.2 571 3/31/2022
1.0.1-preview.68 196 3/30/2022
1.0.1-preview.67 207 3/25/2022
1.0.1-preview.66 214 3/25/2022
1.0.1-preview.65 196 3/25/2022
1.0.1-preview.64 204 3/23/2022
1.0.1-preview.63 188 3/22/2022
1.0.1-preview.62 200 3/21/2022
1.0.1-preview.61 203 3/20/2022
1.0.1-preview.60 204 3/19/2022
1.0.1-preview.58 203 3/16/2022
1.0.1-preview.57 197 3/16/2022
1.0.1-preview.56 196 3/14/2022
1.0.1-preview.55 204 3/14/2022
1.0.1-preview.54 200 3/11/2022
1.0.1-preview.53 201 3/9/2022
1.0.1-preview.52 213 3/8/2022
1.0.1-preview.51 210 3/7/2022
1.0.1-preview.50 205 3/4/2022
1.0.1-preview.49 200 3/3/2022
1.0.1-preview.48 206 2/27/2022
1.0.1-preview.47 199 2/26/2022
1.0.1-preview.46 204 2/25/2022
1.0.1-preview.45 205 2/18/2022
1.0.1-preview.43 209 2/16/2022
1.0.1-preview.42 223 2/12/2022
1.0.1-preview.41 202 2/10/2022
1.0.1-preview.40 205 2/9/2022
1.0.1-preview.39 211 2/8/2022
1.0.1-preview.38 217 2/6/2022
1.0.1-preview.37 222 2/5/2022
1.0.1-preview.36 215 2/4/2022
1.0.1-preview.35 230 2/3/2022
1.0.1-preview.34 218 1/31/2022
1.0.1-preview.32 224 1/31/2022
1.0.1-preview.31 218 1/29/2022
1.0.1-preview.30 220 1/28/2022
1.0.1-preview.28 219 1/28/2022
1.0.1-preview.26 216 1/27/2022
1.0.1-preview.25 235 1/27/2022
1.0.1-preview.24 217 1/26/2022
1.0.1-preview.23 213 1/24/2022
1.0.1-preview.22 229 1/21/2022
1.0.1-preview.21 220 1/21/2022
1.0.1-preview.20 212 1/21/2022
1.0.1-preview.19 216 1/21/2022
1.0.1-preview.18 236 1/20/2022
1.0.1-preview.17 228 1/20/2022
1.0.1-preview.16 230 1/16/2022
1.0.1-preview.15 223 1/14/2022
1.0.1-preview.14 228 1/14/2022
1.0.1-preview.13 217 1/12/2022
1.0.1-preview.12 219 1/11/2022
1.0.1-preview.9 216 1/5/2022
1.0.1-preview.8 217 12/31/2021
1.0.1-preview.7 217 12/31/2021
1.0.1-preview.6 218 12/29/2021
1.0.1-preview.5 234 12/28/2021