当前位置:网站首页>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 !
边栏推荐
猜你喜欢
Flink 解析(二):反压机制解析
Kali2021 installation and basic configuration
Serial serialold parnew of JVM garbage collector
【逆向】脱壳后修复IAT并关闭ASLR
How does wechat prevent withdrawal come true?
Flink 解析(一):基础概念解析
TCP连接不止用TCP协议沟通
Introduction to spring trick of ByteDance: senior students, senior students, senior students, and the author "brocade bag"
Deploy flask project based on LNMP
Integrated development management platform
随机推荐
JVM 垃圾回收器之Serial SerialOld ParNew
Flink 解析(一):基础概念解析
[mmdetection] solves the installation problem
微信防撤回是怎么实现的?
Akamai anti confusion
PostgreSQL 14.2, 13.6, 12.10, 11.15 and 10.20 releases
04 products and promotion developed by individuals - data push tool
网络分层概念及基本知识
mysql高級(索引,視圖,存儲過程,函數,修改密碼)
yarn : 无法加载文件 D:\ProgramFiles\nodejs\yarn.ps1,因为在此系统上禁止运行脚本
Final review of information and network security (based on the key points given by the teacher)
How does wechat prevent withdrawal come true?
Program counter of JVM runtime data area
February database ranking: how long can Oracle remain the first?
Deploy flask project based on LNMP
SQL tuning notes
Akamai浅谈风控原理与解决方案
Start job: operation returned an invalid status code 'badrequst' or 'forbidden‘
[reverse primary] Unique
沉淀下来的数据库操作类-C#版(SQL Server)