当前位置:网站首页>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 !
边栏推荐
- 【Elastic】Elastic缺少xpack无法创建模板 unknown setting index.lifecycle.name index.lifecycle.rollover_alias
- MySQL advanced (index, view, stored procedure, function, password modification)
- 信息与网络安全期末复习(基于老师给的重点)
- Akamai浅谈风控原理与解决方案
- Flink源码解读(一):StreamGraph源码解读
- Coursera cannot play video
- 【逆向初级】独树一帜
- Solr appears write Lock, solrexception: could not get leader props in the log
- 网络分层概念及基本知识
- EasyRE WriteUp
猜你喜欢
The problem of "syntax error" when uipath executes insert statement is solved
Connect to LAN MySQL
Coursera cannot play video
Flink 解析(三):内存管理
集成开发管理平台
pip install pyodbc : ERROR: Command errored out with exit status 1
分布式(一致性协议)之领导人选举( DotNext.Net.Cluster 实现Raft 选举 )
02个人研发的产品及推广-短信平台
Vscode replaces commas, or specific characters with newlines
Final review of information and network security (based on the key points given by the teacher)
随机推荐
DataGridView scroll bar positioning in C WinForm
Flink 解析(四):恢复机制
The NTFS format converter (convert.exe) is missing from the current system
TCP connection is more than communicating with TCP protocol
全网最全tcpdump和Wireshark抓包实践
C WinForm series button easy to use
Interpretation of Flink source code (II): Interpretation of jobgraph source code
[reverse primary] Unique
ByteDance overseas technical team won the championship again: HD video coding has won the first place in 17 items
vscode
自动答题 之 Selenium测试直接运行在浏览器中,就像真正的用户在操作一样。
JVM garbage collector part 2
Interpretation of Flink source code (I): Interpretation of streamgraph source code
Program counter of JVM runtime data area
[VNCTF 2022]ezmath wp
Flink 解析(一):基础概念解析
CTF逆向入门题——掷骰子
The solution to the left-right sliding conflict caused by nesting Baidu MapView in the fragment of viewpager
Start job: operation returned an invalid status code 'badrequst' or 'forbidden‘
Total / statistics function of MySQL