当前位置:网站首页>C # nanoframework lighting and key esp32
C # nanoframework lighting and key esp32
2022-07-06 17:36:00 【Dotnet cross platform】
It was supposed to be a big weekend ,WIFI and Web Web pages and so on , Why did it take two days , And after chatting with foreign friends , It was found that there was a problem with the firmware , After communicating with the boss in the evening, I found , original ESP32S There is a problem with the official firmware of , Can't do it .
therefore , If it is recommended to buy ESP32, Just don't bring any models .
The new board I bought is already on the way , We can't follow up until the board comes .
At present, we can also do some simple , Just do it first .
Basic knowledge of embedded
If it's for SCM , Embedded less understood , It is still necessary to have a deep understanding of the basic knowledge of hardware .
You can refer to 《 Zero dead angle play STM32—F429 Challenger .pdf 》 To learn most of the relevant knowledge , Just look at the basic part , Of course, it's better to watch more .
although , The boards are different , however , The basic knowledge is similar , They are all in the same way .
such as STM32 It can reach more than 100 pins , and ESP32 Maybe it's just 40 Left and right pins , In addition to the built-in WIFI Already occupied , Most of the IO The mouth has been drawn out , You can design it at the hardware level by yourself .
On the development board , Generally, such pins will be led out separately , For development and testing .
GPIO
What is GPIO, english : General-purpose input/output Chinese is Short for general purpose input and output , Simply speaking , Namely CPU Controllable pins , adopt CPU Chip GPIO Pins and external devices ( The sensor is ,AD Collection equipment ) Connect , So as to realize external communication 、 Control and data acquisition functions .
GPIO Basic inputs and outputs
Basic input
The most basic output , It is to detect the external input level , such as , Judge whether the current key is pressed down .
Basic output
The most basic output is to control the chip pin output high , Low level , Switch control is realized , such as GPIO Pin into LED The lamp , Then you can control LED The light goes on and off . Connect to relay or triode , Then the switch or on-off of external high-power circuit can be controlled by relay or triode .
GPIO The illustration

That's all GPIO The schematic diagram of , Of course , The hardware may be upgraded , however , The general principle is the same .
For an in-depth explanation, you can read the introduction in the book and online materials , Here I'll talk about my general explanation .
IO The mouth itself shows two meanings , Input and output .
therefore , The function of this circuit is to try to ensure its input and output stability , Security , reliable .
Of course , It is safer and more reliable to pull up from the outside , It's still weak , voltage 3.3V about , The current is estimated to be smaller , Prefer to control signal level .
therefore , Want to get external information , Or output information to the outside , You can roughly know from the figure , The picture also shows these two ways , One is input , One is output .
C# Achieve lighting and get button items
Board related information
My current board is ESP32S, Found the official , Finally found the information , The address is as follows :
https://docs.ai-thinker.com/esp32/boards/nodemcu_32s
Most of the information can be referred to , Can download
The following is its functional pin diagram

The following is its full circuit diagram

We need to light the lights , And the buttons , So we need to find these two functions IO What are they .
LED and Button Of GPIO
It can be seen from the picture that LED Of GPIO yes IO2 (GPIO 2 It means , That's the second one IO Pin )

Press the key , One is EN, It's the switch enabling key of the board , This key , Can not use , We can only use another , That's it IO0, The first 0 Key .

Code related
Need to add several Nuget package
Install-Package nanoFramework.Hardware.Esp32 -Version 1.3.6.7
Install-Package nanoFramework.Runtime.Events -Version 1.10.0
Install-Package nanoFramework.System.Device.Gpio -Version 1.0.4
then , Add point code , The logic is simple , Press down Boot Key , Turn on the light , Release the button , Put out the light .
public class Program
{
public static GpioPin led;
public static GpioPin button;
public static void Main()
{
var gpioController = new GpioController();
button = gpioController.OpenPin(Gpio.IO00, PinMode.Input);
led = gpioController.OpenPin(Gpio.IO02, PinMode.Output);
button.ValueChanged += Button_ValueChanged;
while (true)
{
Thread.Sleep(1000);
}
}
private static void Button_ValueChanged(object sender, PinValueChangedEventArgs e)
{
Debug.WriteLine(" Key events : " + e.ChangeType.ToString());
Debug.WriteLine(" Key current value : " + button.Read());
if (e.ChangeType != PinEventTypes.Rising)
{
// Press to turn on the light
led.Write(PinValue.High);
}
else
{
// Release your hand and turn off the light
led.Write(PinValue.Low);
}
}
}
Result of operation

It can be seen clearly , When you press the key , The current value is Low, After loosening , yes High.

Above is a small picture of pressing the key .
I tried it again and again , If it is started, it is probably 2 Seconds, the key is valid . Logic of keys and lights , The reaction is also very fast .
summary
On the whole , It is much easier to operate , You can also debug , That is, the board should be consistent with the firmware , otherwise , There will be many small problems , Need to overcome .
Code address
https://github.com/kesshei/NanoFreamworkKeyOrButtonDemo.git
https://gitee.com/kesshei/NanoFreamworkKeyOrButtonDemo.git
reading
One button three times !, Thank you for your support , Your support is my motivation !
边栏推荐
- 微信防撤回是怎么实现的?
- 2021-03-22 "display login screen during recovery" can't be canceled. The appearance of lock screen interface leads to the solution that the remotely connected virtual machine can't work normally
- 沉淀下来的数据库操作类-C#版(SQL Server)
- Introduction to spring trick of ByteDance: senior students, senior students, senior students, and the author "brocade bag"
- Deploy flask project based on LNMP
- [mmdetection] solves the installation problem
- 自动答题 之 Selenium测试直接运行在浏览器中,就像真正的用户在操作一样。
- JVM garbage collector part 1
- JVM garbage collection overview
- Start job: operation returned an invalid status code 'badrequst' or 'forbidden‘
猜你喜欢
[reverse primary] Unique
Some feelings of brushing leetcode 300+ questions
信息与网络安全期末复习(完整版)
C version selenium operation chrome full screen mode display (F11)
Concept and basic knowledge of network layering
轻量级计划服务工具研发与实践
Development and practice of lightweight planning service tools
05个人研发的产品及推广-数据同步工具
The most complete tcpdump and Wireshark packet capturing practice in the whole network
虚拟机启动提示Probing EDD (edd=off to disable)错误
随机推荐
【MySQL入门】第四话 · 和kiko一起探索MySQL中的运算符
JVM garbage collector part 2
Wu Jun trilogy insight (IV) everyone's wisdom
04个人研发的产品及推广-数据推送工具
Coursera cannot play video
【逆向】脱壳后修复IAT并关闭ASLR
Display picture of DataGridView cell in C WinForm
03个人研发的产品及推广-计划服务配置器V3.0
Xin'an Second Edition: Chapter 12 network security audit technology principle and application learning notes
The NTFS format converter (convert.exe) is missing from the current system
Flink parsing (VII): time window
Start job: operation returned an invalid status code 'badrequst' or 'forbidden‘
How does wechat prevent withdrawal come true?
TCP connection is more than communicating with TCP protocol
[VNCTF 2022]ezmath wp
Solrcloud related commands
03 products and promotion developed by individuals - plan service configurator v3.0
The problem of "syntax error" when uipath executes insert statement is solved
C#版Selenium操作Chrome全屏模式显示(F11)
复盘网鼎杯Re-Signal Writeup