Nodemcu入门|初学者指南

在这个tutorial, we will learn about NodeMCU, ESP-12E Module, layout of the NodeMCU board, a brief pinout and how to program NodeMCU with Arduino IDE. This is a complete beginner’s guide to Getting Started with NodeMCU ESP-12E Board. So, let get started.

Getting-Started-with-NodeMCU
NodeMCU (ESP-12E) Board

ESP8266的简短回顾

The impact of ESP8266 on hobbyist and DIY community, particularly in the development of IoT (Internet of Things) related application is absolutely overwhelming. The ESP8266 SoC is a cheap Wi-Fi Microcontroller with full TCP/IP Stack developed by Espressif Systems.

This is not the first time I am talking about ESP8266 Wi-Fi Module. In fact, I already created a series of projects using the vanilla version of the ESP8266 i.e., the ESP-01 Module.

有关启动ESP8266的更多信息,其销钉,固件和其他项目,请查看此“15 Best ESP8266 Projects for Beginners”。

带回ESP8266的原因是Nodemcu。即使我在Nodemcu及其项目中参加了聚会,但我想创建另一组项目,从Nodemcu教程开始,随着越来越多的人购买该董事会。

What is NodeMCU?

从技术上讲,NodeMCU是使用C编程语言,Espressif non-OS SDK和LUA脚本语言开发的ESP8266的固件。

传统上,我们为Arduino,STM32,8051等等,在C或C ++中,并使用一组工具对其进行编译并生成二进制文件。然后将此二进制文件上传到微控制器的闪存中,并执行。

Nodemcu有很大的不同。您可以将NodeMCU固件视为LUA脚本的解释器。因此,如果您的ESP8266装有NodeMCU固件,则可以简单地在LUA中编写应用程序并将其发送到ESP8266。

nodemcu固件将解释字节码并执行命令。没有编译,没有二进制文件等。只需编写脚本并运行它。

开发NodeMCU固件的团队还为ESP-12E模块开发了一个名为Nodemcu Devkit的突破板。因此,我们中的许多人实际上正在使用称为NodeMCU的板,并使用Arduino IDE,而不是LUA脚本编程。

重要的提示:ESP8266上只能存在一个固件。它可以在命令固件,nodemcu固件或基于Arduino的代码上进行。一旦上传Arduino草图,Nodemcu固件就会删除。如果您想使用LUA脚本和NodeMCU,则必须刷新NodeMCU固件。

ESP-01 vs. NodeMCU (ESP-12E)

As mentioned earlier, the NodeMCU Devkit is actually a Breakout Board for the ESP-12E Module. The ESP-01 is the vanilla version of the ESP8266 Wi-Fi SoC made by Ai–Thinker, a third part module manufacturer for ESP8266.

ESP8266 Arduino图像2
ESP-01模块的PINOUT

In fact, the modules produced by Ai–Thinker are one of the widely used in other ESP8266 boards. Some of the modules from Ai–Thinker are ESP-01, ESP-02, ESP-03, and so on up to ESP-14.

笔记:All modules are based on the same ESP8266 Wi-Fi Chip. The main difference is the availability of GPIO Pins. For example, the ESP-01 Module has only 2 GPIO Pins whereas the ESP-12E Module has 17 GPIO Pins, ADC Pin, SPI Pins etc.

Out of all these modules, the ESP-12E is quite popular. Using this module as the main board, the NodeMCU team developed the NodeMCU Devkit, which is often simply called as the NodeMCU Board.

ESP-12E模块
ESP-12E Module with edge castellations

如果您还记得Getting Started with ESP8266” tutorial, we had to go through a lot of trouble in order to program the ESP-01 Module. It needs an USB touart模块,一些以在编程模式之间切换的按钮(GPIO 0必须连接到GND)和正常操作模式(GPIO 0可以保持浮动或可以将高高拉到3.3V)。

Nodemcu板简化了所有这些。首先,由于它基于ESP-12E模块,因此有很多GPIO引脚。其次,有一个板载3.3V调节器(请记住,ESP8266EX SOC在3.3V上工作,而不是5V)。

关于NodeMCU的另一个美丽之处在于,它将板上USB包括在UART控制器上,UART控制器是CP2102 IC。关于此CP2102 IC的一个有趣的事情是,ESP8266 SOC的GPIO 0和RST引脚由CP2102 IC的DTR(Data Terminal Ready Ready)和RTS(Data Terminal Ready)和RTS(请求发送)引脚控制。

因此,每当您尝试上传Arduino IDE的所有草图时,CP2102 IC都会自动选择编程模式并重置板。编程完成后,它将将ESP8266配置为正常运行模式。美丽的。

Nodemcu的官方GitHub页面是这里

Layout of NodeMCU ESP-12E Breakout Board

The following image shows the layout of NodeMCU Board, a breakout board based on ESP-12E Module. The ESP-12E Module consists of edge castellations, making it easy to solder on to a PCB.

板上的nodemcu-parts
Layout of NodeMCU Board

如您在图像中所看到的那样,NodeMCU板由30个引脚组成(每侧15个),一个带有PCB天线的ESP-12E模块,CP2102 USB从硅实验室到UART桥梁控制器,两个按钮(一个是重置和一个重置)另一个是Flash),一种用于电源和上传的微型USB连接器,一个3.3V调节器,一些被动和主动组件以及两个LED。

Yes. The NodeMCU has two on-board LEDs. The first LED comes with the ESP-12E Module and is connected to GPIO 2 of ESP8266 SoC. The second LED is on the break-out board (near the CP2102 IC) and is connected to GPIO 16.

板上的nodemcu
Nodemcu上的两个机载LED

注意:两个LED均为活跃,这意味着,当引脚较低时,LED亮起,当引脚较高时,LED均为关闭。

引脚

我将简要介绍Nodemcu ESP-12E突破板的简短插图。在另一个教程中,我将讨论Nodemcu板,ESP-12E模块,引脚描述和其他重要功能的完整引脚。

The following image shows the pinout of NodeMCU Board.

NodeMCU-Pinout-2
NodeMCU引出线

如何使用Arduino IDE对NodeMcu进行编程?

The Getting Started with NodeMCU is not complete until you upload the Blinky Sketch using Arduino IDE. So, let us proceed with configuring Arduino IDE. If you worked on ESP-01 Module or other ESP8266 based boards, the you probably completed the initial setup in Arduino IDE.

Preparing Arduino IDE

But none the less, let me explain the steps once again. Open the Arduino IDE (if Arduino IDE is not installed, well, install it first) and go to文件 - >首选项

有一个称为“其他董事会经理URL:”的部分。将以下URL粘贴在此旁边的字段中。

http://arduino.esp8266.com/stable/package_esp8266com_index.json

如果要添加多个URL,则只需通过逗号将它们分开。

Arduino-IDE-NodeMCU-1
在Arduino首选项中添加URL

What this does is it allows Arduino IDE to look for additional boards from the internet. So, make sure your system is connected to internet. Now, go to工具 - >董事会 - >董事会经理。。。选项。

使用顶部的搜索字段,搜索“ESP8266”。You will get a result as “esp8266 by ESP8266 Community”. Select this and click on install. It will download all the tools, libraries, boards etc.

Arduino-IDE-NodeMCU-2
Search and Install ESP8266

安装ESP8266板后,您可以开始为新的Nodemcu板编写代码。首先,将Micro-USB电缆连接到NodeMCU,然后将电缆的另一侧插入到计算机上。

现在,再次去工具 - >董事会 - > ESP8266板in the Arduino IDE and select “Nodemcu 1.0 ESP-12E模块”。

Arduino-IDE-NodeMCU-3
在Arduino董事会中选择Nodemcu

如果单击IDE中的工具选项,则所有相关选项将更改,并且特定于ESP8266 NodeMCU。除端口外,将所有设置留在其默认设置中。选择适合USB到UART控制器的合适端口。在Windows中,您可以从“设备管理器”获得此信息。

Arduino-IDE-NodeMCU-5
nodemcu的选项

Testing with Blinky Sketch

As I mentioned earlier, the NodeMCU has two on-board LEDs connected to GPIO 2 and GPIO 16 respectively. So, in this example Blinky Sketch for NodeMCU, I will blink both the LEDs alternatively.

The code for Blinking LEDs on NodeMCU is given below.

单击“上传”按钮后,Arduino IDE将调用一些ESP8266相关工具来编译代码并生成二进制文件。

Arduino-IDE-NodeMCU-4
将眨眼草图上传到Nodemcu

以下是输出的简短视频片段。

nodemcu led闪烁

结论

Nodemcu入门的完整初学者指南。Nodemcu是ESP8266 SOC的出色版本,因为它具有您所需的所有铃铛和哨子以构建完整的系统。在即将到来的教程中,我将使用该NodeMCU董事会实施更多的初学者以及高级项目。因此,请继续关注。

4个回应

  1. Hi, thanks for your detailed explanation, very easy to follow. All worked as you explained except for the last step of setting the port. The port is greyed out so I can set it to the correct value. Any suggestion on how to correct ? thanks

发表评论

您的电子邮件地址不会被公开。

Electronicshub图标
<\/i>","library":""}}" data-widget_type="nav-menu.default">
Baidu