NodeMCU is an open-source Lua based firmware and development board specially targeted for IoT based Applications. It includes firmware that runs on the ESP8266 Wi-Fi SoC from Espressif Systems, and hardware which is based on the ESP-12 module.
Pin Category | Name | Description |
---|---|---|
Power | Micro-USB, 3.3V, GND, Vin | Micro-USB: NodeMCU can be powered through the USB port 3.3V: Regulated 3.3V can be supplied to this pin to power the board GND: Ground pins Vin: External Power Supply |
Control Pins | EN, RST | The pin and the button resets the microcontroller |
Analog Pin | A0 | Used to measure analog voltage in the range of 0-3.3V |
GPIO Pins | GPIO1 to GPIO16 | NodeMCU has 16 general purpose input-output pins on its board |
SPI Pins | SD1, CMD, SD0, CLK | NodeMCU has four pins available for SPI communication. |
UART Pins | TXD0, RXD0, TXD2, RXD2 | NodeMCU has two UART interfaces, UART0 (RXD0 & TXD0) and UART1 (RXD1 & TXD1). UART1 is used to upload the firmware/program. |
I2C Pins | NodeMCU has I2C functionality support but due to the internal functionality of these pins, you have to find which pin is I2C. |
One important thing to notice about ESP8266 is that the GPIO number doesn’t match the label on the board silkscreen. For example, D0 corresponds to GPIO16 and D1 corresponds to GPIO5.
The following table shows the correspondence between the labels on the silkscreen and the GPIO number as well as what pins are the best to use in your projects, and which ones you need to be cautious.
The pins highlighted in green are OK to use. The ones highlighted in yellow are OK to use, but you need to pay attention because they may have unexpected behavior mainly at boot. The pins highlighted in red are not recommended to use as inputs or outputs.
您无需对GPIO0引脚进行额外操作,因为NodeMCU的内置电路可以确保GPIO0引脚在工作时连接高电平而在上传程序时连接低电平。
因此请不要使用GPIO15引脚来读取开关状态或进行I²C通讯。
以上所描述的是针对ESP8266芯片的引脚。
ESP8266有2个硬件串行端口(UART)。
串行端口0(UART0)使用GPIO1和GPIO3引脚。其中GPIO1引脚是TX0,GPIO3是RX0。
串行端口1(UART1)使用GPIO2和GPIO8引脚。其中GPIO2引脚是TX1,GPIO8是RX1。请注意,由于GPIO8被用于连接闪存芯片,串行端口1只能使用GPIO2来向外发送串行数据。
ESP8266只有软件模拟的I²C端口,没有硬件I²C端口。也就是说我们可以使用任意的两个GPIO引脚通过软件模拟来实现I²C通讯。ESP8266的数据表(datasheet)中,GPIO2标注为SDA,GPIO14标注为SCL。
ESP8266的SPI端口情况如下:
GPIO14 — CLK
GPIO12 — MISO
GPIO13 — MOSI
GPIO 15 — CS(SS)
GPIO | 功能 | 状态 | 限制 |
---|---|---|---|
0 | 引导模式选择 | 3.3V | 无Hi-Z |
1 | TX0 | – | 串口通讯过程中不能使用 |
2 | 引导模式选择 TX1 | 3.3V | 启动时不能接地 启动时发送调试信息 |
3 | RX0 | – | 串口通讯过程中不能使用 |
4 | SDA (I²C) | – | – |
5 | SCL (I²C) | – | – |
6 – 11 | 连接闪存 | x | 不可用 |
12 | MISO (SPI) | – | – |
13 | MOSI (SPI) | – | – |
14 | SCK (SPI) | – | – |
15 | SS (SPI) | 0V | 上拉电阻不可用 |
16 | 睡眠唤醒 | – | 无上拉电阻,仅有下拉电阻 连接 RST 引脚实现睡眠唤醒 |