nanoFramework.Hardware.Esp32
1.6.23
Prefix Reserved
dotnet add package nanoFramework.Hardware.Esp32 --version 1.6.23
NuGet\Install-Package nanoFramework.Hardware.Esp32 -Version 1.6.23
<PackageReference Include="nanoFramework.Hardware.Esp32" Version="1.6.23" />
paket add nanoFramework.Hardware.Esp32 --version 1.6.23
#r "nuget: nanoFramework.Hardware.Esp32, 1.6.23"
// Install nanoFramework.Hardware.Esp32 as a Cake Addin #addin nuget:?package=nanoFramework.Hardware.Esp32&version=1.6.23 // Install nanoFramework.Hardware.Esp32 as a Cake Tool #tool nuget:?package=nanoFramework.Hardware.Esp32&version=1.6.23
Welcome to the .NET nanoFramework nanoFramework.Hardware.Esp32 Library repository
Build status
Component | Build Status | NuGet Package |
---|---|---|
nanoFramework.Hardware.Esp32 |
Touch Pad essentials
This section will give you essential elements about how to use Touch Pad pins on ESP32 and ESP32-S2.
Touch Pad vs GPIO pins
Touch Pad pins numbering is different from GPIO pin. You can check which GPIO pins correspond to which GPIO pin using the following:
const int TouchPadNumber = 5;
var pinNum = TouchPad.GetGpioNumberFromTouchNumber(TouchPadNumber);
Console.WriteLine($"Pad {TouchPadNumber} is GPIO{pinNum}");
The pin numbering is different on ESP32 and S2. There are 10 valid touch pad on ESP32 (0 to 9) and 13 on S2 (1 to 13).
In this example touch pad 5 will be GPIO 12 on ESP32 and GPIO 5 on S2.
Basic usage ESP32
On ESP32, if you touch the sensor, the values will be lower, so you have to set a threshold that is lower than the calibration data:
TouchPad touchpad = new(TouchPadNumber);
Console.WriteLine($"Calibrating touch pad {touchpad.TouchPadNumber}, DO NOT TOUCH it during the process.");
var calib = touchpad.GetCalibrationData();
Console.WriteLine($"calib: {calib} vs Calibration {touchpad.CalibrationData}");
// On ESP32: Setup a threshold, usually 2/3 or 80% is a good value.
touchpad.Threshold = (uint)(touchpad.CalibrationData * 2 / 3);
touchpad.ValueChanged += TouchpadValueChanged;
Thread.Sleep(Timeout.Infinite);
private static void TouchpadValueChanged(object sender, TouchPadEventArgs e)
{
Console.WriteLine($"Touchpad {e.PadNumber} is {(e.Touched ? "touched" : "not touched")}");
}
Basic usage S2
On S2, if you touch the sensor, the values will be higher, so you have to set a threshold that is higher than the calibration data and set trigger mode as above:
TouchPad touchpad = new(TouchPadNumber);
Console.WriteLine($"Calibrating touch pad {touchpad.TouchPadNumber}, DO NOT TOUCH it during the process.");
var calib = touchpad.GetCalibrationData();
Console.WriteLine($"calib: {calib} vs Calibration {touchpad.CalibrationData}");
// On S2/S3, the actual read values will be higher, so let's use 20% more
TouchPad.TouchTriggerMode = TouchTriggerMode.AboveThreshold;
touchpad.Threshold = (uint)(touchpad.CalibrationData * 1.2);
touchpad.ValueChanged += TouchpadValueChanged;
Thread.Sleep(Timeout.Infinite);
private static void TouchpadValueChanged(object sender, TouchPadEventArgs e)
{
Console.WriteLine($"Touchpad {e.PadNumber} is {(e.Touched ? "touched" : "not touched")}");
}
Other features
You have quite a lot of other features available, filters, some specific denoising. You can check the sample repository for more details.
Sleep mode
You can wake up your ESP32 or ESP32-S2 by touch.
Sleep modes on ESP32
ESP32 can be woke up by 1 or 2 touch pad. Here is how to do it with 1:
Sleep.EnableWakeupByTouchPad(PadForSleep1, thresholdCoefficient: 80);
And with 2 pads:
Sleep.EnableWakeupByTouchPad(PadForSleep1, PadForSleep2);
Note that the coefficient can be adjusted by doing couple of tests, there is default value of 80 that seems to work in all cases. The coefficient represent a percentage value.
Sleep modes on S2
S2 can only be woke up with 1 touch pad. It is recommended to do tests to find the best coefficient:
Sleep.EnableWakeupByTouchPad(PadForSleep, thresholdCoefficient: 90);
UART wake up from light sleep mode
It is possible to use light sleep in any supported nanoFramework ESP32 with UART wake up. There are few elements to keep in mind:
You must properly setup your COM port, in the following for COM2:
nanoFramework.Hardware.Esp32.Configuration.SetPinFunction(19, nanoFramework.Hardware.Esp32.DeviceFunction.COM2_TX); nanoFramework.Hardware.Esp32.Configuration.SetPinFunction(21, nanoFramework.Hardware.Esp32.DeviceFunction.COM2_RX);
Only COM1 and COM2 are supported. Note that by default COM1 is used for debug. Except if you've build your own version, you may not necessarily use it are a normal UART. But you can definitely use it to wake up your board. In that case, the pins are the default ones and the previous step is not necessary.
In order to wake up the board, you need to set a threshold on how many changes in the RX pin (the reception pin of the UART) is necessary. According to the documentation, you will lose few characters. So the sender should take this into consideration in the protocol.
Usage is straight forward:
EnableWakeupByUart(WakeUpPort.COM2, 5);
StartLightSleep();
Pulse Counter
Pulse counter allows to count pulses without having to setup a GPIO controller and events. It's a fast way to get count during a specific amount of time. This pulse counter allows as well to use 2 different pins and get a pulse count depending on their respective polarities.
Pulse Counter with 1 pin
The following code illustrate how to setup a counter for 1 pin:
GpioPulseCounter counter = new GpioPulseCounter(26);
counter.Polarity = GpioPulsePolarity.Rising;
counter.FilterPulses = 0;
counter.Start();
int inc = 0;
GpioPulseCount counterCount;
while (inc++ < 100)
{
counterCount = counter.Read();
Console.WriteLine($"{counterCount.RelativeTime}: {counterCount.Count}");
Thread.Sleep(1000);
}
counter.Stop();
counter.Dispose();
The counter will always be positive and incremental. You can reset to 0 the count by calling the Reset
function:
GpioPulseCount pulses = counter.Reset();
// pulses.Count contains the actual count, it is then put to 0 once the function is called
Pulse Counter with 2 pins
This is typically a rotary encoder scenario. In this case, you need 2 pins and they'll act like in this graphic:**
You can then use a rotary encoder connected to 2 pins:
The associated code is the same as for 1 pin except in the constructor:
GpioPulseCounter encoder = new GpioPulseCounter(12, 14);
encoder.Start();
int incEncod = 0;
GpioPulseCount counterCountEncode;
while (incEncod++ < 100)
{
counterCountEncode = encoder.Read();
Console.WriteLine($"{counterCountEncode.RelativeTime}: {counterCountEncode.Count}");
Thread.Sleep(1000);
}
encoder.Stop();
encoder.Dispose();
As a result, you'll get positives and negative pulses
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.15.5)
- nanoFramework.Runtime.Events (>= 1.11.18)
NuGet packages (13)
Showing the top 5 NuGet packages that depend on nanoFramework.Hardware.Esp32:
Package | Downloads |
---|---|
nanoFramework.M5Core2
This package includes the nanoFramework.M5Core2 assembly for .NET nanoFramework C# projects. |
|
nanoFramework.M5StickC
This package includes the nanoFramework.M5StickC assembly for .NET nanoFramework C# projects. |
|
nanoFramework.M5Core
This package includes the nanoFramework.M5Core assembly for .NET nanoFramework C# projects. |
|
nanoFramework.M5StickCPlus
This package includes the nanoFramework.M5StickCPlus assembly for .NET nanoFramework C# projects. |
|
nanoFramework.AtomLite
This package includes the nanoFramework.AtomLite assembly for .NET nanoFramework C# projects. |
GitHub repositories (3)
Showing the top 3 popular GitHub repositories that depend on nanoFramework.Hardware.Esp32:
Repository | Stars |
---|---|
nanoframework/Samples
🍬 Code samples from the nanoFramework team used in testing, proof of concepts and other explorational endeavours
|
|
nanoframework/nanoFramework.IoT.Device
📦 This repo includes .NET nanoFramework implementations for various sensors, chips, displays, hats and drivers
|
|
nanoframework/nanoFramework.M5Stack
:package: Board support package for M5Stack, M5StickC and M5StickCPlus for .NET nanoFramework
|
Version | Downloads | Last updated |
---|---|---|
1.6.23 | 1,926 | 12/2/2024 |
1.6.19 | 6,925 | 7/19/2024 |
1.6.18 | 106 | 7/19/2024 |
1.6.15 | 4,358 | 5/13/2024 |
1.6.12 | 9,784 | 11/9/2023 |
1.6.10 | 167 | 11/9/2023 |
1.6.8 | 4,920 | 9/4/2023 |
1.6.3 | 11,991 | 3/25/2023 |
1.6.1 | 12,423 | 2/15/2023 |
1.5.1 | 11,047 | 12/28/2022 |
1.4.8 | 19,274 | 10/21/2022 |
1.4.4 | 5,778 | 10/8/2022 |
1.4.1 | 38,188 | 8/3/2022 |
1.3.6.7 | 50,208 | 6/15/2022 |
1.3.6 | 82,869 | 3/28/2022 |
1.3.5-preview.14 | 171 | 3/28/2022 |
1.3.5-preview.12 | 147 | 3/28/2022 |
1.3.5-preview.10 | 476 | 3/17/2022 |
1.3.5-preview.9 | 328 | 3/14/2022 |
1.3.5-preview.7 | 739 | 2/17/2022 |
1.3.5-preview.6 | 835 | 1/28/2022 |
1.3.5-preview.5 | 416 | 1/20/2022 |
1.3.5-preview.3 | 534 | 12/28/2021 |
1.3.4 | 1,830 | 12/2/2021 |
1.3.4-preview.18 | 178 | 12/2/2021 |
1.3.4-preview.16 | 178 | 12/2/2021 |
1.3.4-preview.14 | 183 | 11/30/2021 |
1.3.4-preview.11 | 421 | 11/3/2021 |
1.3.4-preview.8 | 574 | 10/22/2021 |
1.3.4-preview.7 | 257 | 10/20/2021 |
1.3.4-preview.5 | 450 | 10/17/2021 |
1.3.4-preview.4 | 413 | 9/25/2021 |
1.3.3 | 1,949 | 7/16/2021 |
1.3.3-preview.24 | 226 | 7/15/2021 |
1.3.3-preview.23 | 209 | 7/14/2021 |
1.3.3-preview.22 | 859 | 6/19/2021 |
1.3.3-preview.21 | 309 | 6/7/2021 |
1.3.3-preview.20 | 253 | 6/6/2021 |
1.3.3-preview.19 | 207 | 6/4/2021 |
1.3.3-preview.18 | 272 | 6/1/2021 |
1.3.3-preview.17 | 253 | 5/31/2021 |
1.3.3-preview.16 | 218 | 5/31/2021 |
1.3.3-preview.15 | 229 | 5/30/2021 |
1.3.3-preview.14 | 292 | 5/19/2021 |
1.3.3-preview.13 | 214 | 5/19/2021 |
1.3.3-preview.12 | 225 | 5/13/2021 |
1.3.3-preview.11 | 229 | 5/11/2021 |
1.3.3-preview.10 | 204 | 5/11/2021 |
1.3.3-preview.3 | 863 | 3/21/2021 |
1.3.3-preview.1 | 590 | 3/10/2021 |
1.3.2-preview.26 | 203 | 3/8/2021 |
1.3.2-preview.24 | 210 | 3/2/2021 |
1.3.2-preview.21 | 845 | 1/6/2021 |
1.3.2-preview.19 | 417 | 12/29/2020 |
1.3.2-preview.14 | 251 | 12/7/2020 |
1.3.2-preview.11 | 366 | 10/20/2020 |
1.3.2-preview.9 | 313 | 9/30/2020 |
1.3.2-preview.7 | 276 | 9/30/2020 |
1.3.2-preview.5 | 275 | 9/28/2020 |
1.3.2-preview.1 | 248 | 9/24/2020 |
1.3.1-preview.6 | 356 | 7/2/2020 |
1.3.1-preview.4 | 282 | 7/1/2020 |
1.3.1-preview.2 | 298 | 6/16/2020 |
1.3.0 | 883 | 6/16/2020 |
1.3.0-preview.5 | 285 | 6/16/2020 |
1.2.1 | 610 | 6/12/2020 |
1.2.1-preview.17 | 276 | 6/12/2020 |
1.2.1-preview.15 | 309 | 6/11/2020 |
1.2.1-preview.12 | 374 | 5/8/2020 |
1.2.1-preview.11 | 300 | 5/8/2020 |
1.2.1-preview.10 | 289 | 4/27/2020 |
1.2.1-preview.9 | 311 | 4/16/2020 |
1.2.1-preview.8 | 280 | 4/14/2020 |
1.2.1-preview.7 | 332 | 3/15/2020 |
1.2.1-preview.5 | 276 | 3/10/2020 |
1.2.1-preview.4 | 268 | 3/10/2020 |
1.2.1-preview.3 | 299 | 3/9/2020 |
1.2.1-preview.1 | 348 | 2/27/2020 |
1.2.0-preview.8 | 426 | 11/18/2019 |
1.2.0-preview.7 | 290 | 11/7/2019 |
1.2.0-preview.6 | 305 | 11/5/2019 |
1.2.0-preview.5 | 301 | 11/4/2019 |
1.2.0-preview.4 | 291 | 10/23/2019 |
1.2.0-preview.3 | 289 | 10/18/2019 |
1.1.0 | 811 | 10/17/2019 |
1.1.0-preview.3 | 277 | 10/17/2019 |
1.0.10 | 636 | 10/15/2019 |
1.0.10-preview.31 | 291 | 10/15/2019 |
1.0.10-preview.30 | 314 | 10/15/2019 |
1.0.10-preview.29 | 305 | 9/30/2019 |
1.0.10-preview.21 | 361 | 7/18/2019 |
1.0.10-preview.18 | 305 | 7/16/2019 |
1.0.10-preview.16 | 376 | 6/23/2019 |
1.0.10-preview.9 | 352 | 6/20/2019 |
1.0.10-preview.6 | 397 | 6/12/2019 |
1.0.10-preview.2 | 345 | 6/12/2019 |
1.0.9-preview-003 | 558 | 4/24/2019 |
1.0.9-preview-001 | 717 | 4/23/2019 |
1.0.8 | 911 | 2/4/2019 |
1.0.7 | 837 | 1/22/2019 |
1.0.6-preview-022 | 585 | 4/23/2019 |
1.0.6-preview-017 | 527 | 4/7/2019 |
1.0.6-preview-015 | 512 | 4/3/2019 |
1.0.6-preview-013 | 531 | 3/11/2019 |
1.0.6-preview-009 | 526 | 3/10/2019 |
1.0.5 | 879 | 1/3/2019 |
1.0.2-preview-012 | 660 | 11/20/2018 |
1.0.2-preview-009 | 665 | 11/9/2018 |
1.0.2-preview-004 | 654 | 11/8/2018 |
1.0.0 | 954 | 10/17/2018 |
1.0.0-preview031 | 688 | 10/9/2018 |
1.0.0-preview021 | 712 | 9/18/2018 |
1.0.0-preview020 | 729 | 9/18/2018 |
1.0.0-preview017 | 714 | 9/12/2018 |
1.0.0-preview012 | 750 | 8/27/2018 |
1.0.0-preview009 | 774 | 8/9/2018 |
1.0.0-preview008 | 914 | 8/3/2018 |
1.0.0-preview007 | 772 | 7/24/2018 |
1.0.0-preview004 | 855 | 6/16/2018 |
0.0.0 | 370 | 12/27/2022 |