nanoFramework.M5StickCPlus
1.0.0-preview.94
Prefix Reserved
See the version list below for details.
dotnet add package nanoFramework.M5StickCPlus --version 1.0.0-preview.94
NuGet\Install-Package nanoFramework.M5StickCPlus -Version 1.0.0-preview.94
<PackageReference Include="nanoFramework.M5StickCPlus" Version="1.0.0-preview.94" />
paket add nanoFramework.M5StickCPlus --version 1.0.0-preview.94
#r "nuget: nanoFramework.M5StickCPlus, 1.0.0-preview.94"
// Install nanoFramework.M5StickCPlus as a Cake Addin #addin nuget:?package=nanoFramework.M5StickCPlus&version=1.0.0-preview.94&prerelease // Install nanoFramework.M5StickCPlus as a Cake Tool #tool nuget:?package=nanoFramework.M5StickCPlus&version=1.0.0-preview.94&prerelease
Welcome to the .NET nanoFramework M5Stack Library repository
Build status
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 | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net is compatible. |
-
- nanoFramework.CoreLibrary (>= 1.10.5)
- nanoFramework.Graphics (>= 1.0.1-preview.8)
- nanoFramework.Hardware.Esp32 (>= 1.3.4-preview.8)
- nanoFramework.Hardware.Esp32.Rmt (>= 1.2.1-preview.5)
- nanoFramework.Iot.Device.Axp192 (>= 1.0.235)
- nanoFramework.Iot.Device.Button (>= 1.0.218)
- nanoFramework.Iot.Device.Buzzer (>= 1.0.218)
- nanoFramework.Iot.Device.Common.NumberHelper (>= 1.0.160)
- nanoFramework.Iot.Device.Mpu6886 (>= 1.0.224)
- nanoFramework.Iot.Device.Rtc (>= 1.0.225)
- nanoFramework.ResourceManager (>= 1.1.2)
- nanoFramework.Runtime.Events (>= 1.9.2-preview.8)
- nanoFramework.Runtime.Native (>= 1.5.1)
- nanoFramework.System.Buffers.Binary.BinaryPrimitives (>= 1.0.160)
- nanoFramework.System.Collections (>= 1.2.0)
- nanoFramework.System.Device.Gpio (>= 1.0.2-preview.7)
- nanoFramework.System.Device.I2c (>= 1.0.1)
- nanoFramework.System.Device.Model (>= 1.0.176)
- nanoFramework.System.Device.Pwm (>= 1.0.0-preview.14)
- nanoFramework.System.Diagnostics.Stopwatch (>= 1.0.160)
- nanoFramework.System.Math (>= 1.4.1)
- nanoFramework.System.Numerics (>= 1.0.160)
- UnitsNet.nanoFramework.ElectricCurrent (>= 4.102.0)
- UnitsNet.nanoFramework.ElectricPotential (>= 4.102.0)
- UnitsNet.nanoFramework.Power (>= 4.102.0)
- UnitsNet.nanoFramework.Temperature (>= 4.102.0)
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.246 | 89 | 10/31/2024 |
1.1.245 | 113 | 10/18/2024 |
1.1.244 | 75 | 10/16/2024 |
1.1.243 | 85 | 10/12/2024 |
1.1.242 | 88 | 10/11/2024 |
1.1.241 | 87 | 10/4/2024 |
1.1.240 | 87 | 10/2/2024 |
1.1.239 | 93 | 9/27/2024 |
1.1.238 | 110 | 9/6/2024 |
1.1.236 | 93 | 8/30/2024 |
1.1.235 | 90 | 8/28/2024 |
1.1.234 | 118 | 8/16/2024 |
1.1.232 | 60 | 7/31/2024 |
1.1.229 | 98 | 7/19/2024 |
1.1.228 | 75 | 7/17/2024 |
1.1.227 | 73 | 7/12/2024 |
1.1.225 | 111 | 6/28/2024 |
1.1.223 | 106 | 6/19/2024 |
1.1.220 | 104 | 5/31/2024 |
1.1.217 | 116 | 5/15/2024 |
1.1.215 | 114 | 5/10/2024 |
1.1.213 | 111 | 4/17/2024 |
1.1.211 | 103 | 4/15/2024 |
1.1.209 | 121 | 4/5/2024 |
1.1.207 | 108 | 3/27/2024 |
1.1.203 | 121 | 2/28/2024 |
1.1.201 | 136 | 1/31/2024 |
1.1.199 | 107 | 1/26/2024 |
1.1.197 | 109 | 1/24/2024 |
1.1.187 | 217 | 11/17/2023 |
1.1.185 | 123 | 11/14/2023 |
1.1.183 | 118 | 11/9/2023 |
1.1.180 | 115 | 11/8/2023 |
1.1.177 | 146 | 10/11/2023 |
1.1.175 | 141 | 9/29/2023 |
1.1.171 | 152 | 9/8/2023 |
1.1.169 | 150 | 9/6/2023 |
1.1.167 | 142 | 8/18/2023 |
1.1.163 | 158 | 8/2/2023 |
1.1.161 | 146 | 7/28/2023 |
1.1.157 | 145 | 7/19/2023 |
1.1.155 | 158 | 7/14/2023 |
1.1.152 | 147 | 6/21/2023 |
1.1.150 | 147 | 6/14/2023 |
1.1.148 | 151 | 6/7/2023 |
1.1.146 | 153 | 5/31/2023 |
1.1.144 | 151 | 5/24/2023 |
1.1.142 | 168 | 5/17/2023 |
1.1.139 | 178 | 5/11/2023 |
1.1.137 | 172 | 5/5/2023 |
1.1.135 | 216 | 4/5/2023 |
1.1.133 | 222 | 3/29/2023 |
1.1.131 | 233 | 3/24/2023 |
1.1.128 | 239 | 3/17/2023 |
1.1.125 | 223 | 3/16/2023 |
1.1.123 | 224 | 3/13/2023 |
1.1.121 | 255 | 3/9/2023 |
1.1.119 | 259 | 2/27/2023 |
1.1.117 | 261 | 2/27/2023 |
1.1.115 | 272 | 2/22/2023 |
1.1.113 | 256 | 2/20/2023 |
1.1.111 | 250 | 2/16/2023 |
1.1.106 | 333 | 1/10/2023 |
1.1.104 | 317 | 1/9/2023 |
1.1.102 | 292 | 1/6/2023 |
1.1.100 | 302 | 1/6/2023 |
1.1.98 | 321 | 1/5/2023 |
1.1.96 | 309 | 12/29/2022 |
1.1.90 | 343 | 11/15/2022 |
1.1.88 | 348 | 11/14/2022 |
1.1.86 | 369 | 11/5/2022 |
1.1.84 | 390 | 11/5/2022 |
1.1.82 | 364 | 11/4/2022 |
1.1.80 | 360 | 11/3/2022 |
1.1.78 | 366 | 11/1/2022 |
1.1.76 | 391 | 10/27/2022 |
1.1.70 | 434 | 10/13/2022 |
1.1.68 | 410 | 10/12/2022 |
1.1.64 | 419 | 10/7/2022 |
1.1.62 | 386 | 10/7/2022 |
1.1.58 | 473 | 9/23/2022 |
1.1.55 | 493 | 9/23/2022 |
1.1.53 | 461 | 9/22/2022 |
1.1.47 | 431 | 9/21/2022 |
1.1.45 | 446 | 9/16/2022 |
1.1.42 | 451 | 9/15/2022 |
1.1.40 | 473 | 9/8/2022 |
1.1.38 | 440 | 9/7/2022 |
1.1.36 | 432 | 9/3/2022 |
1.1.34 | 439 | 8/15/2022 |
1.1.32 | 451 | 8/6/2022 |
1.1.30 | 437 | 8/5/2022 |
1.1.28 | 422 | 8/4/2022 |
1.1.26 | 457 | 8/3/2022 |
1.1.24 | 434 | 8/3/2022 |
1.1.22 | 446 | 8/2/2022 |
1.1.20 | 463 | 7/30/2022 |
1.1.18 | 457 | 7/26/2022 |
1.1.16 | 436 | 7/24/2022 |
1.1.14 | 454 | 7/23/2022 |
1.1.12 | 478 | 7/13/2022 |
1.1.7 | 496 | 7/7/2022 |
1.1.5 | 477 | 7/7/2022 |
1.1.3 | 486 | 7/6/2022 |
1.1.1 | 462 | 7/5/2022 |
1.0.107.13280 | 464 | 7/1/2022 |
1.0.105.49254 | 474 | 6/30/2022 |
1.0.102.851 | 460 | 6/28/2022 |
1.0.100.17145 | 453 | 6/28/2022 |
1.0.98.48733 | 462 | 6/28/2022 |
1.0.96.40373 | 462 | 6/26/2022 |
1.0.92.59206 | 455 | 6/24/2022 |
1.0.90.38187 | 447 | 6/16/2022 |
1.0.88.50207 | 436 | 6/15/2022 |
1.0.86.52668 | 434 | 6/14/2022 |
1.0.83.14512 | 441 | 6/13/2022 |
1.0.81.41619 | 467 | 6/8/2022 |
1.0.79.53990 | 459 | 6/3/2022 |
1.0.77.26764 | 473 | 6/3/2022 |
1.0.75.37268 | 471 | 6/1/2022 |
1.0.72.43325 | 443 | 5/31/2022 |
1.0.70.15497 | 452 | 5/31/2022 |
1.0.68.55953 | 471 | 5/31/2022 |
1.0.66.24331 | 475 | 5/27/2022 |
1.0.64.6330 | 439 | 5/26/2022 |
1.0.62.28047 | 441 | 5/26/2022 |
1.0.60.49583 | 455 | 5/25/2022 |
1.0.58.20063 | 471 | 5/24/2022 |
1.0.56.35800 | 444 | 5/23/2022 |
1.0.54.60782 | 452 | 5/20/2022 |
1.0.51.48271 | 475 | 5/12/2022 |
1.0.49.30985 | 448 | 5/6/2022 |
1.0.46 | 471 | 5/5/2022 |
1.0.42 | 483 | 4/26/2022 |
1.0.40 | 454 | 4/25/2022 |
1.0.38 | 451 | 4/24/2022 |
1.0.36 | 455 | 4/23/2022 |
1.0.34 | 449 | 4/22/2022 |
1.0.32 | 474 | 4/22/2022 |
1.0.30 | 477 | 4/21/2022 |
1.0.26 | 499 | 4/21/2022 |
1.0.24 | 477 | 4/20/2022 |
1.0.22 | 459 | 4/19/2022 |
1.0.20 | 469 | 4/18/2022 |
1.0.18 | 478 | 4/17/2022 |
1.0.16 | 476 | 4/16/2022 |
1.0.14 | 457 | 4/15/2022 |
1.0.12 | 465 | 4/13/2022 |
1.0.10 | 450 | 4/6/2022 |
1.0.8 | 457 | 4/4/2022 |
1.0.6 | 448 | 4/3/2022 |
1.0.4 | 468 | 3/31/2022 |
1.0.2 | 457 | 3/31/2022 |
1.0.1-preview.68 | 121 | 3/30/2022 |
1.0.1-preview.67 | 124 | 3/25/2022 |
1.0.1-preview.66 | 123 | 3/25/2022 |
1.0.1-preview.65 | 121 | 3/25/2022 |
1.0.1-preview.64 | 121 | 3/23/2022 |
1.0.1-preview.63 | 103 | 3/22/2022 |
1.0.1-preview.62 | 109 | 3/21/2022 |
1.0.1-preview.61 | 118 | 3/20/2022 |
1.0.1-preview.60 | 119 | 3/19/2022 |
1.0.1-preview.58 | 125 | 3/16/2022 |
1.0.1-preview.57 | 127 | 3/16/2022 |
1.0.1-preview.56 | 122 | 3/14/2022 |
1.0.1-preview.55 | 126 | 3/14/2022 |
1.0.1-preview.54 | 120 | 3/11/2022 |
1.0.1-preview.53 | 119 | 3/9/2022 |
1.0.1-preview.52 | 130 | 3/8/2022 |
1.0.1-preview.51 | 122 | 3/7/2022 |
1.0.1-preview.50 | 115 | 3/4/2022 |
1.0.1-preview.49 | 122 | 3/3/2022 |
1.0.1-preview.48 | 120 | 2/27/2022 |
1.0.1-preview.47 | 117 | 2/26/2022 |
1.0.1-preview.46 | 112 | 2/25/2022 |
1.0.1-preview.45 | 125 | 2/18/2022 |
1.0.1-preview.43 | 120 | 2/16/2022 |
1.0.1-preview.42 | 121 | 2/12/2022 |
1.0.1-preview.41 | 118 | 2/10/2022 |
1.0.1-preview.40 | 124 | 2/9/2022 |
1.0.1-preview.39 | 127 | 2/8/2022 |
1.0.1-preview.38 | 132 | 2/6/2022 |
1.0.1-preview.37 | 136 | 2/5/2022 |
1.0.1-preview.36 | 132 | 2/4/2022 |
1.0.1-preview.35 | 136 | 2/3/2022 |
1.0.1-preview.34 | 141 | 1/31/2022 |
1.0.1-preview.32 | 141 | 1/31/2022 |
1.0.1-preview.31 | 143 | 1/29/2022 |
1.0.1-preview.30 | 135 | 1/28/2022 |
1.0.1-preview.28 | 137 | 1/28/2022 |
1.0.1-preview.26 | 134 | 1/27/2022 |
1.0.1-preview.25 | 135 | 1/27/2022 |
1.0.1-preview.24 | 132 | 1/26/2022 |
1.0.1-preview.23 | 134 | 1/24/2022 |
1.0.1-preview.22 | 135 | 1/21/2022 |
1.0.1-preview.21 | 136 | 1/21/2022 |
1.0.1-preview.20 | 137 | 1/21/2022 |
1.0.1-preview.19 | 133 | 1/21/2022 |
1.0.1-preview.18 | 135 | 1/20/2022 |
1.0.1-preview.17 | 149 | 1/20/2022 |
1.0.1-preview.16 | 140 | 1/16/2022 |
1.0.1-preview.15 | 128 | 1/14/2022 |
1.0.1-preview.14 | 142 | 1/14/2022 |
1.0.1-preview.13 | 141 | 1/12/2022 |
1.0.1-preview.12 | 142 | 1/11/2022 |
1.0.1-preview.9 | 143 | 1/5/2022 |
1.0.1-preview.8 | 137 | 12/31/2021 |
1.0.1-preview.7 | 133 | 12/31/2021 |
1.0.1-preview.6 | 139 | 12/29/2021 |
1.0.1-preview.5 | 138 | 12/28/2021 |
1.0.1-preview.3 | 141 | 12/27/2021 |
1.0.0 | 333 | 12/23/2021 |
1.0.0-preview.99 | 144 | 12/23/2021 |
1.0.0-preview.98 | 145 | 12/23/2021 |
1.0.0-preview.94 | 179 | 11/12/2021 |
1.0.0-preview.91 | 169 | 11/9/2021 |
1.0.0-preview.88 | 172 | 11/9/2021 |
1.0.0-preview.86 | 158 | 11/3/2021 |
1.0.0-preview.83 | 210 | 10/28/2021 |
1.0.0-preview.81 | 195 | 10/27/2021 |