当前位置:网站首页>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.4then , 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 !
边栏推荐
- Redis quick start
- Start job: operation returned an invalid status code 'badrequst' or 'forbidden‘
- CTF reverse entry question - dice
- TCP连接不止用TCP协议沟通
- Concept and basic knowledge of network layering
- 基于LNMP部署flask项目
- SQL tuning notes
- Solrcloud related commands
- Development and practice of lightweight planning service tools
- Vscode replaces commas, or specific characters with newlines
猜你喜欢

PySpark算子处理空间数据全解析(5): 如何在PySpark里面使用空间运算接口

Flink parsing (VII): time window

Akamai anti confusion

【逆向】脱壳后修复IAT并关闭ASLR

Take you hand-in-hand to do intensive learning experiments -- knock the level in detail

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

Wordcloud colormap color set and custom colors

Application service configurator (regular, database backup, file backup, remote backup)

C# WinForm中DataGridView单元格显示图片

03个人研发的产品及推广-计划服务配置器V3.0
随机推荐
Xin'an Second Edition; Chapter 11 learning notes on the principle and application of network physical isolation technology
CTF reverse entry question - dice
Akamai浅谈风控原理与解决方案
04 products and promotion developed by individuals - data push tool
Akamai anti confusion
How does wechat prevent withdrawal come true?
华为认证云计算HICA
分布式(一致性协议)之领导人选举( DotNext.Net.Cluster 实现Raft 选举 )
Flink 解析(三):内存管理
Precipitated database operation class - version C (SQL Server)
Flink 解析(六):Savepoints
【MMdetection】一文解决安装问题
Junit单元测试
Xin'an Second Edition: Chapter 23 cloud computing security requirements analysis and security protection engineering learning notes
Re signal writeup
MySQL advanced (index, view, stored procedure, function, password modification)
C version selenium operation chrome full screen mode display (F11)
C#WinForm中的dataGridView滚动条定位
当前系统缺少NTFS格式转换器(convert.exe)
mysql的合计/统计函数