nanoFramework.AtomLite 1.0.107.13280

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package nanoFramework.AtomLite --version 1.0.107.13280
                    
NuGet\Install-Package nanoFramework.AtomLite -Version 1.0.107.13280
                    
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.AtomLite" Version="1.0.107.13280" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="nanoFramework.AtomLite" Version="1.0.107.13280" />
                    
Directory.Packages.props
<PackageReference Include="nanoFramework.AtomLite" />
                    
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.AtomLite --version 1.0.107.13280
                    
#r "nuget: nanoFramework.AtomLite, 1.0.107.13280"
                    
#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.
#addin nuget:?package=nanoFramework.AtomLite&version=1.0.107.13280
                    
Install nanoFramework.AtomLite as a Cake Addin
#tool nuget:?package=nanoFramework.AtomLite&version=1.0.107.13280
                    
Install nanoFramework.AtomLite 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.M5Stick Build Status NuGet
nanoFramework.M5StickCPlus Build Status NuGet
nanoFramework.M5Core2 Build Status NuGet
nanoFramework.Fire Build Status NuGet
nanoFramework.AtomLite Build Status NuGet
nanoFramework.AtomMatrix Build Status NuGet

Usage

These NuGet packages provide a support for M5Stack products:

Note 1: 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. Note 2: When invoking VS > Project > Manage NuGet Packages make sure that in the Package source drop-down menu (right upper corner) "nuget.org" is selected.

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 --serialport COM3

For the M5StickC:

nanoff --target M5StickC --update --serialport COM3 --baud 115200

For the M5StickCPlus:

nanoff --target M5StickCPlus --update --serialport COM3

For the M5Core2 and Fire:

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

For the Atom Lite and Matrix:

nanoff --target ESP32_PICO --update --serialport COM3

Note 3: If the nanoff commands fails, make sure you have followed instruction from Note 1 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 4: 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 and Fire have PSRAM, so you can get a full screen buffer as well. Refer to the Graphics samples to understand all you can do with it.

If you have intensive graphic need with any of the M5Stack, you can adjust the memory requested. While both M5Core2 and Fire have PSRAM and can accommodate very large amount like 2 Mb or more, the ones without cannot go more than few Kb or tens of Kb.

// This will allocate 2 Mb of memory for the graphics
M5Core2.InitializeScreen(2 * 1024 * 1024);

Buttons

The main buttons except the power buttons are exposed.

On the M5Stack and Fire 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.");
};

On the Atom Lite/Matrix it's called Button. You can get access to the status of the button, the events and everything you need. For example:

AtomLite.Button.Press +=> (sender, e)
{
    var color = AtomLite.NeoPixel.GetColor();
    if(color.R > 0)
    {
        AtomLite.NeoPixel.SetColor(Color.FromArgb(255, 0, 255, 0));
    }
    else if (color.G > 0)
    {
        AtomLite.NeoPixel.SetColor(Color.FromArgb(255, 0, 0, 255));
    }
    else
    {
        AtomLite.NeoPixel.SetColor(Color.FromArgb(255, 255, 0, 0));
    }
};

Note: The M5Core2 has touch screen and the buttons are "virtual"". See next section to see how to use them.

M5Core2 touch panel and buttons

The touch panel comes with the screen. Both are initialized and activated at the same time. To get the touch events, you'll have to register to the TouchEvent event:

M5Core2.InitializeScreen();
M5Core2.TouchEvent += TouchEventCallback;

Here is an example on how to check if you are on a button or not and get the various elements:

void TouchEventCallback(object sender, TouchEventArgs e)
{
    const string StrLB = "LEFT BUTTON PRESSED  ";
    const string StrMB = "MIDDLE BUTTON PRESSED  ";
    const string StrRB = "RIGHT BUTTON PRESSED  ";
    const string StrXY1 = "TOUCHED at X= ";
    const string StrXY2 = ",Y= ";
    const string StrID = ",Id= ";
    const string StrDoubleTouch = "Double touch. ";
    const string StrMove = "Moving... ";
    const string StrLiftUp = "Lift up. ";

    Debug.WriteLine($"Touch Panel Event Received Category= {e.EventCategory} Subcategory= {e.TouchEventCategory}");
    Console.CursorLeft = 0;
    Console.CursorTop = 0;

    Debug.WriteLine(StrXY1 + e.X + StrXY2 + e.Y + StrID + e.Id);
    Console.WriteLine(StrXY1 + e.X + StrXY2 + e.Y + StrID + e.Id + "  ");

    if ((e.TouchEventCategory & TouchEventCategory.LeftButton) == TouchEventCategory.LeftButton)
    {
        Debug.WriteLine(StrLB);
        Console.WriteLine(StrLB);
    }
    else if ((e.TouchEventCategory & TouchEventCategory.MiddleButton) == TouchEventCategory.MiddleButton)
    {
        Debug.WriteLine(StrMB);
        Console.WriteLine(StrMB);
    }
    else if ((e.TouchEventCategory & TouchEventCategory.RightButton) == TouchEventCategory.RightButton)
    {
        Debug.WriteLine(StrRB);
        Console.WriteLine(StrRB);
    }

    if ((e.TouchEventCategory & TouchEventCategory.Moving) == TouchEventCategory.Moving)
    {
        Debug.WriteLine(StrMove);
        Console.Write(StrMove);
    }

    if ((e.TouchEventCategory & TouchEventCategory.LiftUp) == TouchEventCategory.LiftUp)
    {
        Debug.WriteLine(StrLiftUp);
        Console.Write(StrLiftUp);
    }

    if ((e.TouchEventCategory & TouchEventCategory.DoubleTouch) == TouchEventCategory.DoubleTouch)
    {
        Debug.WriteLine(StrDoubleTouch);
        Console.Write(StrDoubleTouch);
    }

    Console.WriteLine("                                    ");
    Console.WriteLine("                                    ");
    Console.WriteLine("                                    ");
}

The TouchEventCategory enum is a flag and can combine buttons and states. The buttons are mutually exclusive, so you can only have the Left, Middle or Right button, the states are Moving and LiftUp. Moving is happening when a contact has already been made and the touch point is moving. LiftUp will appear when the contact is released.

DoubleTouch is a specific that let you know there is another contact point happening. Each contact point will receive this flag. The event will be raised 2 times, one for each point. In a double touch context, you may not get the second point LiftUp event but you'll get the change with the disappearance of the DoubleTouch flag and the final LiftUp on the first point.

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 and Fire.

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, M5Core2, Fire and Atom Lite/Matrix, access them like this:

// This will give you the ADC1 channel 7 which is on pin 35 of M5Core
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, M5Core2, Fire and Atom Lite/Matrix 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, Fire and M5StickC/CPlus:

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

DAC

The M5Core, M5Core2, Fire and Atom Lite/Matrix 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 and Atom Lite/Matrix 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.

NeoPixel on AtomLite

The Atom Lite exposes a rgb led. You can access it thru the NeoPixel property:

// This will set NeoPixel to green:
AtomLite.NeoPixel.Image.SetPixel(0, 0, Color.Green);
AtomLite.NeoPixel.Update();

RGB LED matrix on AtomMatrix and Led bar on Fire

The Atom Matrix has a matrix of 25 RGB LEDs. The position of the LEDs in the array follows their placement in the matrix, being 0 the one at the top left corner, growing left to right, top to bottom.

You can access it thru the LedMatrix property on the AtomMatrix, like this:

// This will set the RGB LED at position 2, 2 to green
AtomMatrix.LedMatrix.Image.SetPixel(2, 2, Color.Green);

Similarly, you have access to the LedBar property on the Fire:

// This will set the second RGB LED to green
Fire.LedBar.Image.SetPixel(2, 0, Color.Green);

After you're done with updating all the LEDs that you want to change, flush the updated to the LEDs, like this:

// This will update all RGB LED 
AtomMatrix.LedMatrix.Update();

And on the Fire:

// This will update all RGB LED 
Fire.LedBar.Update();

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 (1)

Showing the top 1 popular GitHub repositories that depend on nanoFramework.AtomLite:

Repository Stars
nanoframework/Samples
🍬 Code samples from the nanoFramework team used in testing, proof of concepts and other explorational endeavours
Version Downloads Last updated
1.1.280 67 4/28/2025
1.1.279 181 4/7/2025
1.1.278 164 4/2/2025
1.1.277 150 4/2/2025
1.1.276 176 3/12/2025
1.1.275 160 3/10/2025
1.1.274 217 3/5/2025
1.1.273 146 3/3/2025
1.1.272 130 2/27/2025
1.1.271 104 2/27/2025
1.1.270 93 2/27/2025
1.1.269 102 2/26/2025
1.1.268 104 2/26/2025
1.1.267 97 2/25/2025
1.1.266 109 2/25/2025
1.1.265 135 2/10/2025
1.1.264 145 2/5/2025
1.1.263 100 2/4/2025
1.1.262 107 2/4/2025
1.1.261 102 2/4/2025
1.1.260 97 2/3/2025
1.1.259 98 1/31/2025
1.1.255 128 1/20/2025
1.1.253 145 12/30/2024
1.1.252 126 12/23/2024
1.1.249 117 12/16/2024
1.1.248 118 12/16/2024
1.1.247 132 12/4/2024
1.1.246 189 10/31/2024
1.1.245 145 10/18/2024
1.1.244 114 10/16/2024
1.1.243 107 10/12/2024
1.1.242 107 10/11/2024
1.1.241 117 10/4/2024
1.1.240 124 10/2/2024
1.1.239 113 9/27/2024
1.1.238 173 9/6/2024
1.1.236 129 8/30/2024
1.1.235 126 8/28/2024
1.1.234 146 8/16/2024
1.1.232 86 7/31/2024
1.1.229 146 7/19/2024
1.1.228 111 7/17/2024
1.1.227 104 7/12/2024
1.1.225 134 6/28/2024
1.1.223 136 6/19/2024
1.1.220 137 5/31/2024
1.1.217 154 5/15/2024
1.1.215 123 5/10/2024
1.1.213 238 4/17/2024
1.1.211 122 4/15/2024
1.1.209 152 4/5/2024
1.1.207 135 3/27/2024
1.1.203 164 2/28/2024
1.1.201 194 1/31/2024
1.1.199 134 1/26/2024
1.1.197 133 1/24/2024
1.1.187 292 11/17/2023
1.1.185 148 11/14/2023
1.1.183 143 11/9/2023
1.1.180 146 11/8/2023
1.1.177 215 10/11/2023
1.1.175 177 9/29/2023
1.1.171 191 9/8/2023
1.1.169 176 9/6/2023
1.1.167 198 8/18/2023
1.1.163 262 8/2/2023
1.1.161 163 7/28/2023
1.1.157 183 7/19/2023
1.1.155 175 7/14/2023
1.1.152 220 6/21/2023
1.1.150 177 6/14/2023
1.1.148 210 6/7/2023
1.1.146 199 5/31/2023
1.1.144 186 5/24/2023
1.1.142 226 5/17/2023
1.1.139 224 5/11/2023
1.1.137 214 5/5/2023
1.1.135 293 4/5/2023
1.1.133 277 3/29/2023
1.1.131 279 3/24/2023
1.1.128 290 3/17/2023
1.1.125 290 3/16/2023
1.1.123 251 3/13/2023
1.1.121 311 3/9/2023
1.1.119 295 2/27/2023
1.1.117 285 2/27/2023
1.1.115 301 2/22/2023
1.1.113 296 2/20/2023
1.1.111 300 2/16/2023
1.1.106 382 1/10/2023
1.1.104 342 1/9/2023
1.1.102 346 1/6/2023
1.1.100 355 1/6/2023
1.1.98 381 1/5/2023
1.1.96 358 12/29/2022
1.1.90 436 11/15/2022
1.1.88 392 11/14/2022
1.1.86 430 11/5/2022
1.1.84 441 11/5/2022
1.1.82 428 11/4/2022
1.1.80 429 11/3/2022
1.1.78 424 11/1/2022
1.1.76 456 10/27/2022
1.1.70 497 10/13/2022
1.1.68 461 10/12/2022
1.1.64 429 10/7/2022
1.1.62 437 10/7/2022
1.1.58 522 9/23/2022
1.1.55 507 9/23/2022
1.1.53 488 9/22/2022
1.1.47 466 9/21/2022
1.1.45 489 9/16/2022
1.1.42 496 9/15/2022
1.1.40 501 9/8/2022
1.1.38 491 9/7/2022
1.1.36 487 9/3/2022
1.1.34 506 8/15/2022
1.1.32 497 8/6/2022
1.1.30 484 8/5/2022
1.1.28 490 8/4/2022
1.1.26 500 8/3/2022
1.1.24 484 8/3/2022
1.1.22 484 8/2/2022
1.1.20 506 7/30/2022
1.1.18 509 7/26/2022
1.1.16 492 7/24/2022
1.1.14 481 7/23/2022
1.1.12 516 7/13/2022
1.1.7 552 7/7/2022
1.1.5 516 7/7/2022
1.1.3 522 7/6/2022
1.1.1 499 7/5/2022
1.0.107.13280 531 7/1/2022
1.0.105.49254 555 6/30/2022
1.0.102.851 522 6/28/2022
1.0.100.17145 516 6/28/2022
1.0.98.48733 538 6/28/2022
1.0.96.40373 527 6/26/2022
1.0.92.59206 523 6/24/2022
1.0.90.38187 498 6/16/2022
1.0.88.50207 487 6/15/2022
1.0.86.52668 490 6/14/2022
1.0.83.14512 485 6/13/2022
1.0.81.41619 510 6/8/2022
1.0.79.53990 511 6/3/2022
1.0.77.26764 493 6/3/2022
1.0.75.37268 490 6/1/2022
1.0.72.43325 489 5/31/2022
1.0.70.15497 504 5/31/2022
1.0.68.55953 512 5/31/2022
1.0.66.24331 515 5/27/2022
1.0.64.6330 508 5/26/2022
1.0.62.28047 466 5/26/2022
1.0.60.49583 479 5/25/2022
1.0.58.20063 474 5/24/2022
1.0.56.35800 486 5/23/2022
1.0.54.60782 504 5/20/2022
1.0.51.48271 520 5/12/2022
1.0.49.30985 537 5/6/2022
1.0.46 525 5/5/2022
1.0.42 558 4/26/2022
1.0.40 516 4/25/2022
1.0.38 521 4/24/2022
1.0.36 536 4/23/2022
1.0.34 546 4/22/2022
1.0.32 514 4/22/2022
1.0.30 513 4/21/2022
1.0.26 523 4/21/2022
1.0.24 515 4/20/2022
1.0.22 534 4/19/2022
1.0.20 510 4/18/2022
1.0.18 504 4/17/2022
1.0.16 522 4/16/2022
1.0.14 516 4/15/2022
1.0.12 511 4/13/2022
1.0.10 520 4/6/2022
1.0.8 525 4/4/2022
1.0.6 537 4/3/2022
1.0.4 516 3/31/2022
1.0.2 490 3/31/2022
1.0.1-preview.68 155 3/30/2022
1.0.1-preview.67 164 3/25/2022
1.0.1-preview.66 152 3/25/2022
1.0.1-preview.65 157 3/25/2022
1.0.1-preview.64 155 3/23/2022
1.0.1-preview.63 141 3/22/2022
1.0.1-preview.62 144 3/21/2022
1.0.1-preview.61 149 3/20/2022
1.0.1-preview.60 152 3/19/2022
1.0.1-preview.58 152 3/16/2022
1.0.1-preview.57 158 3/16/2022
1.0.1-preview.56 153 3/14/2022
1.0.1-preview.55 156 3/14/2022
1.0.1-preview.54 153 3/11/2022
1.0.1-preview.53 144 3/9/2022
1.0.1-preview.52 158 3/8/2022
1.0.1-preview.51 154 3/7/2022
1.0.1-preview.50 148 3/4/2022
1.0.1-preview.49 153 3/3/2022
1.0.1-preview.48 154 2/27/2022
1.0.1-preview.47 153 2/26/2022
1.0.1-preview.46 148 2/25/2022
1.0.1-preview.45 158 2/18/2022
1.0.1-preview.43 170 2/16/2022
1.0.1-preview.42 168 2/12/2022
1.0.1-preview.41 149 2/10/2022
1.0.1-preview.40 157 2/9/2022
1.0.1-preview.39 170 2/8/2022
1.0.1-preview.38 163 2/6/2022
1.0.1-preview.37 162 2/5/2022
1.0.1-preview.36 169 2/4/2022
1.0.1-preview.35 161 2/3/2022
1.0.1-preview.34 172 1/31/2022