当前位置:网站首页>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 !
边栏推荐
- 07个人研发的产品及推广-人力资源信息管理系统
- Integrated development management platform
- 【Elastic】Elastic缺少xpack无法创建模板 unknown setting index.lifecycle.name index.lifecycle.rollover_alias
- Case: check the empty field [annotation + reflection + custom exception]
- mysql高級(索引,視圖,存儲過程,函數,修改密碼)
- Flink 解析(三):内存管理
- Xin'an Second Edition: Chapter 23 cloud computing security requirements analysis and security protection engineering learning notes
- Wu Jun trilogy insight (IV) everyone's wisdom
- Concept and basic knowledge of network layering
- The most complete tcpdump and Wireshark packet capturing practice in the whole network
猜你喜欢
EasyRE WriteUp
Flink parsing (VII): time window
Display picture of DataGridView cell in C WinForm
全网最全tcpdump和Wireshark抓包实践
【ASM】字节码操作 ClassWriter 类介绍与使用
02 personal developed products and promotion - SMS platform
Grafana 9 正式发布,更易用,更酷炫了!
How does wechat prevent withdrawal come true?
Virtual machine startup prompt probing EDD (edd=off to disable) error
EasyRE WriteUp
随机推荐
Redis installation on centos7
03个人研发的产品及推广-计划服务配置器V3.0
Akamai anti confusion
Akamai talking about risk control principles and Solutions
自动答题 之 Selenium测试直接运行在浏览器中,就像真正的用户在操作一样。
PySpark算子处理空间数据全解析(5): 如何在PySpark里面使用空间运算接口
04 products and promotion developed by individuals - data push tool
[reverse] repair IAT and close ASLR after shelling
Connect to LAN MySQL
C WinForm series button easy to use
ByteDance overseas technical team won the championship again: HD video coding has won the first place in 17 items
Grafana 9 正式发布,更易用,更酷炫了!
Some feelings of brushing leetcode 300+ questions
Uipath browser performs actions in the new tab
Introduction to spring trick of ByteDance: senior students, senior students, senior students, and the author "brocade bag"
vscode
The problem of "syntax error" when uipath executes insert statement is solved
Xin'an Second Edition: Chapter 23 cloud computing security requirements analysis and security protection engineering learning notes
PostgreSQL 14.2, 13.6, 12.10, 11.15 and 10.20 releases
复盘网鼎杯Re-Signal Writeup