{"id":19244463,"url":"https://github.com/nanoframework/nanoframework.m5stack","last_synced_at":"2025-04-08T00:37:02.845Z","repository":{"id":37829022,"uuid":"203641100","full_name":"nanoframework/nanoFramework.M5Stack","owner":"nanoframework","description":":package: Board support package for M5Stack, M5StickC and M5StickCPlus for .NET nanoFramework","archived":false,"fork":false,"pushed_at":"2024-10-25T03:31:07.000Z","size":2006,"stargazers_count":98,"open_issues_count":2,"forks_count":34,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-10-29T21:06:15.316Z","etag":null,"topics":["csharp","dotnet","esp32","hacktoberfest","library","m5stack","nanoframework"],"latest_commit_sha":null,"homepage":"https://www.nanoframework.net","language":"C#","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nanoframework.png","metadata":{"funding":{"open_collective":"nanoframework","github":"nanoframework"},"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-21T18:21:15.000Z","updated_at":"2024-10-18T22:56:07.000Z","dependencies_parsed_at":"2023-10-16T03:29:48.119Z","dependency_job_id":"ede7492f-ce07-42f3-9cd7-43dbe7a75644","html_url":"https://github.com/nanoframework/nanoFramework.M5Stack","commit_stats":{"total_commits":536,"total_committers":17,"mean_commits":"31.529411764705884","dds":"0.47388059701492535","last_synced_commit":"8d9dee0d312e54f53f8e955cef799f6e5b5f1aee"},"previous_names":[],"tags_count":281,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoframework%2FnanoFramework.M5Stack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoframework%2FnanoFramework.M5Stack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoframework%2FnanoFramework.M5Stack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoframework%2FnanoFramework.M5Stack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nanoframework","download_url":"https://codeload.github.com/nanoframework/nanoFramework.M5Stack/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247755560,"owners_count":20990620,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","dotnet","esp32","hacktoberfest","library","m5stack","nanoframework"],"created_at":"2024-11-09T17:23:39.612Z","updated_at":"2025-04-08T00:37:02.813Z","avatar_url":"https://github.com/nanoframework.png","language":"C#","funding_links":["https://opencollective.com/nanoframework","https://github.com/sponsors/nanoframework"],"categories":[],"sub_categories":[],"readme":"[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=nanoframework_lib-nanoFramework.M5Stack\u0026metric=reliability_rating)](https://sonarcloud.io/dashboard?id=nanoframework_lib-nanoFramework.M5Stack) [![#yourfirstpr](https://img.shields.io/badge/first--timers--only-friendly-blue.svg)](https://github.com/nanoframework/Home/blob/main/CONTRIBUTING.md) [![Discord](https://img.shields.io/discord/478725473862549535.svg?logo=discord\u0026logoColor=white\u0026label=Discord\u0026color=7289DA)](https://discord.gg/gCyBu8T)\n\n![nanoFramework logo](https://raw.githubusercontent.com/nanoframework/Home/main/resources/logo/nanoFramework-repo-logo.png)\n\n-----\n\n# Welcome to the .NET **nanoFramework** M5Stack Libraries repository\n\n## Build status\n\n| Component | Build Status | NuGet Package |\n|:-|---|---|\n| nanoFramework.M5Core | [![Build Status](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_apis/build/status/nanoFramework.M5Stack?repoName=nanoframework%2FnanoFramework.M5Stack\u0026branchName=main)](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_build/latest?definitionId=52\u0026repoName=nanoframework%2FnanoFramework.M5Stack\u0026branchName=main) | [![NuGet](https://img.shields.io/nuget/v/nanoFramework.M5Core.svg?label=NuGet\u0026style=flat\u0026logo=nuget)](https://www.nuget.org/packages/nanoFramework.M5Stack/) |\n| nanoFramework.M5Stick | [![Build Status](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_apis/build/status/nanoFramework.M5Stack?repoName=nanoframework%2FnanoFramework.M5Stack\u0026branchName=main)](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_build/latest?definitionId=52\u0026repoName=nanoframework%2FnanoFramework.M5Stack\u0026branchName=main) | [![NuGet](https://img.shields.io/nuget/v/nanoFramework.M5StickC.svg?label=NuGet\u0026style=flat\u0026logo=nuget)](https://www.nuget.org/packages/nanoFramework.M5StickC/) |\n| nanoFramework.M5StickCPlus | [![Build Status](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_apis/build/status/nanoFramework.M5Stack?repoName=nanoframework%2FnanoFramework.M5Stack\u0026branchName=main)](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_build/latest?definitionId=52\u0026repoName=nanoframework%2FnanoFramework.M5Stack\u0026branchName=main) | [![NuGet](https://img.shields.io/nuget/v/nanoFramework.M5StickCPlus.svg?label=NuGet\u0026style=flat\u0026logo=nuget)](https://www.nuget.org/packages/nanoFramework.M5StickCPlus/) |\n| nanoFramework.M5Core2 | [![Build Status](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_apis/build/status/nanoFramework.M5Stack?repoName=nanoframework%2FnanoFramework.M5Stack\u0026branchName=main)](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_build/latest?definitionId=52\u0026repoName=nanoframework%2FnanoFramework.M5Stack\u0026branchName=main) | [![NuGet](https://img.shields.io/nuget/v/nanoFramework.M5Core2.svg?label=NuGet\u0026style=flat\u0026logo=nuget)](https://www.nuget.org/packages/nanoFramework.M5Core2/) |\n| nanoFramework.Fire | [![Build Status](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_apis/build/status/nanoFramework.M5Stack?repoName=nanoframework%2FnanoFramework.M5Stack\u0026branchName=main)](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_build/latest?definitionId=52\u0026repoName=nanoframework%2FnanoFramework.M5Stack\u0026branchName=main) | [![NuGet](https://img.shields.io/nuget/v/nanoFramework.Fire.svg?label=NuGet\u0026style=flat\u0026logo=nuget)](https://www.nuget.org/packages/nanoFramework.Fire/) |\n| nanoFramework.AtomLite | [![Build Status](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_apis/build/status/nanoFramework.M5Stack?repoName=nanoframework%2FnanoFramework.M5Stack\u0026branchName=main)](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_build/latest?definitionId=52\u0026repoName=nanoframework%2FnanoFramework.M5Stack\u0026branchName=main) | [![NuGet](https://img.shields.io/nuget/v/nanoFramework.AtomLite.svg?label=NuGet\u0026style=flat\u0026logo=nuget)](https://www.nuget.org/packages/nanoFramework.AtomLite/) |\n| nanoFramework.AtomMatrix | [![Build Status](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_apis/build/status/nanoFramework.M5Stack?repoName=nanoframework%2FnanoFramework.M5Stack\u0026branchName=main)](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_build/latest?definitionId=52\u0026repoName=nanoframework%2FnanoFramework.M5Stack\u0026branchName=main) | [![NuGet](https://img.shields.io/nuget/v/nanoFramework.AtomMatrix.svg?label=NuGet\u0026style=flat\u0026logo=nuget)](https://www.nuget.org/packages/nanoFramework.AtomMatrix/) |\n| nanoFramework.Tough | [![Build Status](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_apis/build/status/nanoFramework.M5Stack?repoName=nanoframework%2FnanoFramework.M5Stack\u0026branchName=main)](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_build/latest?definitionId=52\u0026repoName=nanoframework%2FnanoFramework.M5Stack\u0026branchName=main) | [![NuGet](https://img.shields.io/nuget/v/nanoFramework.Tough.svg?label=NuGet\u0026style=flat\u0026logo=nuget)](https://www.nuget.org/packages/nanoFramework.Tough/) |\n| nanoFramework.CoreInk | [![Build Status](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_apis/build/status/nanoFramework.M5Stack?repoName=nanoframework%2FnanoFramework.M5Stack\u0026branchName=main)](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_build/latest?definitionId=52\u0026repoName=nanoframework%2FnanoFramework.M5Stack\u0026branchName=main) | [![NuGet](https://img.shields.io/nuget/v/nanoFramework.CoreInk.svg?label=NuGet\u0026style=flat\u0026logo=nuget)](https://www.nuget.org/packages/nanoFramework.CoreInk/) |\n\n## Usage\n\nThese NuGet packages provide a support for M5Stack products:\n\n- [Core (gray) and Basic](https://docs.m5stack.com/en/products?id=core)\n- [M5StickC](https://docs.m5stack.com/en/core/m5stickc)\n- [M5StickCPlus](https://docs.m5stack.com/en/core/m5stickc_plus)\n- [M5Core2](https://docs.m5stack.com/en/core/core2)\n- [Fire](https://docs.m5stack.com/en/core/fire)\n- [Atom Lite](https://docs.m5stack.com/en/core/atom_lite)\n- [Atom Matrix](https://docs.m5stack.com/en/core/atom_matrix)\n- [Tough](https://docs.m5stack.com/en/core/tough)\n- [CoreInk](https://docs.m5stack.com/en/core/coreink)\n\n\u003e 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 \u003e Tools \u003e Options \u003e NuGet Package Manager \u003e Package Sources  and make sure that it contains an entry pointing to \u003chttps://api.nuget.org/v3/index.json\u003e, otherwise add it.\n\u003e Note 2: When invoking VS \u003e Project \u003e Manage NuGet Packages make sure that in the Package source drop-down menu (right upper corner) \"nuget.org\" is selected.\n\nThe NuGets bring support for the screens as well and require to be flashed with the proper image (using [`nanoff`](https://github.com/nanoframework/nanoFirmwareFlasher) dotnet CLI).\nOn 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).\n\nFor the M5Core:\n\n```shell\nnanoff --target M5Core --update --serialport COM3\n```\n\nFor the M5StickC:\n\n```shell\nnanoff --target M5StickC --update --serialport COM3 --baud 115200\n```\n\nFor the M5StickCPlus:\n\n```shell\nnanoff --target M5StickCPlus --update --serialport COM3\n```\n\nFor the M5Core2, Tough and Fire:\n\n```shell\nnanoff --target M5Core2 --update --serialport COM3\n```\n\nFor the Atom Lite, Matrix and CoreInk:\n\n```shell\nnanoff --target ESP32_PICO --update --serialport COM3\n```\n\n\u003e Note 3: If the `nanoff` commands fails, make sure you have followed instruction from Note 1 above.\n\nOnce 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!\n\n\u003e 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.\n\nIn the samples below, we'll use either M5Core or M5Stick as examples, they are all working in a very similar way.\n\n### Namespaces\n\nMake sure you add the proper namespaces reference to your C# program header e.g.\nusing nanoFramework;\n\n### Screen\n\nThe only thing you need to do to access the screen is to initialize it (please note that `InitializeScreen()` it's target specific) e.g.:\n\nFor Core:\n\n```csharp\nM5Core.InitializeScreen();\n```\n\nFor StickCPlus:\n\n```csharp\nM5StickCPlus.InitializeScreen();\n```\n\nOnce you've initialized it, you can access both a `Screen` static class and a `Console` static class.\n\nTHe `Screen` one brings primitives to write directly on the screen points or scare of colours as well as writing a text.\n\nFor example, you can write a blue square of 10x10 at the position 0, 0 like this:\n\n```csharp\nushort[] toSend = new ushort[100];\nushort blue = ColorUtility.To16Bpp(Color.Blue);\n\nfor (int i = 0; i \u003c toSend.Length; i++)\n{\n    toSend[i] = blue;\n}\n\nScreen.Write(0, 0, 10, 10, toSend);\n```\n\nThe 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:\n\n```csharp\nnanoFramework.Console.Clear();\n\n// Test the console display\nnanoFramework.Console.Write(\"This is a short text. \");\nnanoFramework.Console.ForegroundColor = nanoFramework.Presentation.Media.Color.Red;\nnanoFramework.Console.WriteLine(\"This one displays in red after the previous one and is already at the next line.\");\nnanoFramework.Console.BackgroundColor = nanoFramework.Presentation.Media.Color.Yellow;\nnanoFramework.Console.ForegroundColor = nanoFramework.Presentation.Media.Color.RoyalBlue;\nnanoFramework.Console.WriteLine(\"And this is blue on yellow background\");\nnanoFramework.Console.ResetColor();\nnanoFramework.Console.CursorLeft = 0;\nnanoFramework.Console.CursorTop = 8;\nnanoFramework.Console.Write(\"This is white on black again and on 9th line\");\n```\n\n\u003e 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.\n\nM5Core2 and Fire have PSRAM, so you can get a full screen buffer as well. Refer to the [Graphics samples](https://github.com/nanoframework/Samples#graphics-for-screens) to understand all you can do with it.\n\nIf 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.\n\n```csharp\n// This will allocate 2 Mb of memory for the graphics\nM5Core2.InitializeScreen(2 * 1024 * 1024);\n```\n\n### Buttons\n\nThe main buttons except the power buttons are exposed.\n\nOn the M5Stack and Fire they are called `ButtonLeft`, `ButtonCenter` and `ButtonRight`. You can get access to the events as well. For example:\n\n```csharp\nM5Stack.ButtonLeft.Press += (sender, e) =\u003e\n{\n    Console.ForegroundColor = Color.Yellow;\n    Console.CursorLeft = 0;\n    Console.CursorTop = 0;\n    Console.Write($\"Left Pressed  \");\n};\n```\n\nOn 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:\n\n```csharp\nwhile (!M5StickC.ButtonRight.IsPressed)\n{\n    Thread.Sleep(10);\n}\n\nM5StickC.M5Button.IsHoldingEnabled = true;\nM5StickC.M5Button.Holding += (sender, e) =\u003e\n{\n    Console.Write(\"M5 button hold long.\");\n};\n```\n\nOn 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:\n\n```csharp\nAtomLite.Button.Press +=\u003e (sender, e)\n{\n    var color = AtomLite.NeoPixel.GetColor();\n    if(color.R \u003e 0)\n    {\n        AtomLite.NeoPixel.SetColor(Color.FromArgb(255, 0, 255, 0));\n    }\n    else if (color.G \u003e 0)\n    {\n        AtomLite.NeoPixel.SetColor(Color.FromArgb(255, 0, 0, 255));\n    }\n    else\n    {\n        AtomLite.NeoPixel.SetColor(Color.FromArgb(255, 255, 0, 0));\n    }\n};\n```\n\n\u003e Note: The M5Core2 has touch screen and the buttons are \"virtual\"\". See next section to see how to use them.\n\n### M5Core2 touch panel and buttons\n\nThe 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:\n\n```csharp\nM5Core2.InitializeScreen();\nM5Core2.TouchEvent += TouchEventCallback;\n```\n\nHere is an example on how to check if you are on a button or not and get the various elements:\n\n```csharp\nvoid TouchEventCallback(object sender, TouchEventArgs e)\n{\n    const string StrLB = \"LEFT BUTTON PRESSED  \";\n    const string StrMB = \"MIDDLE BUTTON PRESSED  \";\n    const string StrRB = \"RIGHT BUTTON PRESSED  \";\n    const string StrXY1 = \"TOUCHED at X= \";\n    const string StrXY2 = \",Y= \";\n    const string StrID = \",Id= \";\n    const string StrDoubleTouch = \"Double touch. \";\n    const string StrMove = \"Moving... \";\n    const string StrLiftUp = \"Lift up. \";\n\n    Debug.WriteLine($\"Touch Panel Event Received Category= {e.EventCategory} Subcategory= {e.TouchEventCategory}\");\n    Console.CursorLeft = 0;\n    Console.CursorTop = 0;\n\n    Debug.WriteLine(StrXY1 + e.X + StrXY2 + e.Y + StrID + e.Id);\n    Console.WriteLine(StrXY1 + e.X + StrXY2 + e.Y + StrID + e.Id + \"  \");\n\n    if ((e.TouchEventCategory \u0026 TouchEventCategory.LeftButton) == TouchEventCategory.LeftButton)\n    {\n        Debug.WriteLine(StrLB);\n        Console.WriteLine(StrLB);\n    }\n    else if ((e.TouchEventCategory \u0026 TouchEventCategory.MiddleButton) == TouchEventCategory.MiddleButton)\n    {\n        Debug.WriteLine(StrMB);\n        Console.WriteLine(StrMB);\n    }\n    else if ((e.TouchEventCategory \u0026 TouchEventCategory.RightButton) == TouchEventCategory.RightButton)\n    {\n        Debug.WriteLine(StrRB);\n        Console.WriteLine(StrRB);\n    }\n\n    if ((e.TouchEventCategory \u0026 TouchEventCategory.Moving) == TouchEventCategory.Moving)\n    {\n        Debug.WriteLine(StrMove);\n        Console.Write(StrMove);\n    }\n\n    if ((e.TouchEventCategory \u0026 TouchEventCategory.LiftUp) == TouchEventCategory.LiftUp)\n    {\n        Debug.WriteLine(StrLiftUp);\n        Console.Write(StrLiftUp);\n    }\n\n    if ((e.TouchEventCategory \u0026 TouchEventCategory.DoubleTouch) == TouchEventCategory.DoubleTouch)\n    {\n        Debug.WriteLine(StrDoubleTouch);\n        Console.Write(StrDoubleTouch);\n    }\n\n    Console.WriteLine(\"                                    \");\n    Console.WriteLine(\"                                    \");\n    Console.WriteLine(\"                                    \");\n}\n```\n\nThe `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.\n\n`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.\n\n### Power management\n\nThe 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.\n\nPlease refer to the detailed examples for the [AXP192](https://github.com/nanoframework/nanoFramework.IoT.Device/blob/develop/devices/Axp192/README.md) used in the M5StickC/CPlus; M5Core2 and [IP5306](https://github.com/nanoframework/nanoFramework.IoT.Device/blob/develop/devices/Ip5306/README.md) for the M5Core and Fire.\n\n### Accelerometer and Gyroscope\n\nYou can get access to the Accelerometer and Gyroscope like this:\n\n```csharp\nvar ag = M5Core.AccelerometerGyroscope;\n// Do not move the M5Core/M5Stick during the calibration\nag.Calibrate(100);\nvar acc = ag.GetAccelerometer();\nvar gyr = ag.GetGyroscope();\nDebug.WriteLine($\"Accelerometer data x:{acc.X} y:{acc.Y} z:{acc.Z}\");\nDebug.WriteLine($\"Gyroscope data x:{gyr.X} y:{gyr.Y} z:{gyr.Z}\\n\");\n```\n\nRefer to the [MPU6886 documentation](https://github.com/nanoframework/nanoFramework.IoT.Device/blob/develop/devices/Mpu6886/README.md) for more detailed usage on this sensor.\n\n### Magnetometer\n\nThe M5Core has a magnetometer, you can access it as well:\n\n```csharp\nvar mag = M5Core.Magnetometer;\n// It is more than strongly recommended to calibrate the magnetometer.\n// Move the M5Core in all directions to have a proper calibration.\nmag.CalibrateMagnetometer(100);\nvar magVal = mag.ReadMagnetometer();\nConsole.WriteLine($\"x={magVal.X:N2}   \");\nConsole.WriteLine($\"y={magVal.Y:N2}   \");\nConsole.WriteLine($\"Z={magVal.Z:N2}   \");\nvar headDir = Math.Atan2(magVal.X, magVal.Y) * 180.0 / Math.PI;\nConsole.WriteLine($\"h={headDir:N2}  \");\n```\n\n### SerialPort\n\nThe M5Core and M5Core2 can provide a Serial Port, just get it like this:\n\n```csharp\n// You can access any of the Serial Port feature\nM5Core.SerialPort.Open(115200);\n// Do anything else you need\nM5Core.SerialPort.Close();\n```\n\nRefer to the [SerialPort documentation](https://github.com/nanoframework/System.IO.Ports) for more information.\n\n### ADC Channels\n\nADC Channels are pre setup on the M5Core, M5Core2, Fire and Atom Lite/Matrix, access them like this:\n\n```csharp\n// This will give you the ADC1 channel 7 which is on pin 35 of M5Core\nAdcChannel myChannel = M5Core.GetAdcGpio(35);\n```\n\nRefer to the M5Stack documentation to have the mapping of the ADC channels and the pins.\n\n### I2C Device/Grove\n\nYou can get an I2cDevice/Grove like this:\n\n```csharp\n// In this example, the I2C address of the device is 0x42:\nI2cDevice myDevice = M5Core.GetGrove(0x42);\n// replacing GetGrove by GetI2cDevice will have the same impact\n```\n\n### SPI Device\n\nThe M5Core, M5Core2, Fire and Atom Lite/Matrix provides as well an `SpiDevice`:\n\n```csharp\n// In this case GPIO5 will be used as chip select:\nSpiDevice mySpi = M5Core.GetSpiDevice(5);\n```\n\n### GPIO Controller\n\nSimilar as previously, you can get the `GpioController` on any of the M5Core, M5Core2, Fire and M5StickC/CPlus:\n\n```csharp\n// This will open the GPIO 36 as output\nvar pin5 = M5StickC.GpioController.OpenPin(36, PinMode.Output);\n```\n\n### DAC\n\nThe 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](https://github.com/nanoframework/System.Device.Dac) for more information.\n\n### I2S (sound)\n\nOn the M5Core2, wav files can be played using I2S by installing the package [nanoFramework.System.Device.I2s](https://github.com/nanoframework/System.Device.I2S). \nTo play wav files on the M5Core2, use following initialization:\n\n```csharp\nint bckPin = 12;\nint dataPin = 2;\nint wsPin = 0;\nI2sWavPlayer.Bus bus = I2sWavPlayer.Bus.One;\nvar audioFile = \"D:\\\\Variation-CLJ013901.wav\";\nusing (var player = new I2sWavPlayer(bus, audioFile, bckPin, dataPin, wsPin))\n{\n    M5Core2.Power.Gpio2Value = PinValue.High; //speaker power on\n    player.Play();\n    M5Core2.Power.Gpio2Value = PinValue.Low; //speaker power off\n}\n```\n\n### Led\n\nThe M5StickC/CPlus exposes a led. You can access it thru the `Led` property:\n\n```csharp\n// This will toggle the led:\nM5StickC.Led.Toggle();\n```\n\n### Infrared Led\n\nThe 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](https://github.com/nanoframework/Samples/tree/main/samples/Hardware.Esp32.Rmt) to understand how to use it.\n\n### NeoPixel on AtomLite\n\nThe Atom Lite exposes a rgb led. You can access it thru the `NeoPixel` property:\n\n```csharp\n// This will set NeoPixel to green:\nAtomLite.NeoPixel.Image.SetPixel(0, 0, Color.Green);\nAtomLite.NeoPixel.Update();\n```\n\n### RGB LED matrix on AtomMatrix and Led bar on Fire\n\nThe Atom Matrix has a matrix of 25 RGB LEDs.\nThe 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.\n\nYou can access it thru the `LedMatrix` property on the AtomMatrix, like this:\n\n```csharp\n// This will set the RGB LED at position 2, 2 to green\nAtomMatrix.LedMatrix.Image.SetPixel(2, 2, Color.Green);\n```\n\nSimilarly, you have access to the `LedBar` property on the Fire:\n\n```csharp\n// This will set the second RGB LED to green\nFire.LedBar.Image.SetPixel(2, 0, Color.Green);\n```\n\nAfter you're done with updating all the LEDs that you want to change, flush the updated to the LEDs, like this:\n\n```csharp\n// This will update all RGB LED \nAtomMatrix.LedMatrix.Update();\n```\n\nAnd on the Fire:\n\n```csharp\n// This will update all RGB LED \nFire.LedBar.Update();\n```\n\n### SD Card\n\nThe M5Core, M5Core2, Fire and Tough have a SD Card reader. You can simply access it like:\n\n```csharp\nSDCard sdCard = M5Core.SDCard;\ntry\n{\n    // This will actually mount the SD Card, if no card, you will get an exception\n    sdCard.Mount();\n    // Mounting properly a card can take a bit of time, so wait for the card to be mounted\n    // Note: it is recommended to use a cancellation token or equivalent to make sure you are not in a dead loop\n    while (!sdCard.IsMounted)\n    {\n        Thread.Sleep(10);\n    }\n\n    // You can now access the files on the SD Card\n    // As an example you can read a json file and deserialize it\n    // D: is the drive from the SD Card\n    const string ParamFile = \"D:\\\\params.json\";\n    using FileStream fs = new FileStream(ParamFile, FileMode.Open, FileAccess.Read);\n    // In this case, you will need to have a class called Configuration and a properly serialized file\n    Configuration config = (Configuration)JsonConvert.DeserializeObject(fs, typeof(Configuration));\n}\ncatch\n{\n    // Something wrong happened\n}\n```\n\nMore samples on how to use the file system are [available here](https://github.com/nanoframework/Samples/tree/main/samples/System.IO.FileSystem).\n\n## Feedback and documentation\n\nFor documentation, providing feedback, issues and finding out how to contribute please refer to the [Home repo](https://github.com/nanoframework/Home).\n\nJoin our Discord community [here](https://discord.gg/gCyBu8T).\n\n## Credits\n\nThe list of contributors to this project can be found at [CONTRIBUTORS](https://github.com/nanoframework/Home/blob/main/CONTRIBUTORS.md).\n\n## License\n\nThe **nanoFramework** Class Libraries are licensed under the [MIT license](LICENSE.md).\n\n## Code of Conduct\n\nThis project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behaviour in our community.\nFor more information see the [.NET Foundation Code of Conduct](https://dotnetfoundation.org/code-of-conduct).\n\n### .NET Foundation\n\nThis project is supported by the [.NET Foundation](https://dotnetfoundation.org).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnanoframework%2Fnanoframework.m5stack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnanoframework%2Fnanoframework.m5stack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnanoframework%2Fnanoframework.m5stack/lists"}