# NodeMCU

**NodeMCU** 是一款面向乐鑫（Espressif）ESP8266 与 [ESP32](https://www.edgepedia.org/zh/esp32) Wi-Fi 系统级芯片的开源、基于 Lua 的固件，也指最初为运行该固件而打造的一系列开发板。固件以 C 语言实现，其中 ESP8266 版本构建于乐鑫 NON-OS SDK 之上，并使用模块内置闪存上的 SPIFFS 文件系统；目前该项目由社区维护，可运行于任意 ESP 模组之上。<sup>[1](https://www.nodemcu.com/docs/)</sup> 这一名称既指固件项目，也指同一团队作为配套硬件所开发的 ESP8266 开发模块。<sup>[1](https://www.nodemcu.com/docs/)</sup>

| 关键事实 | 详情 |
|---|---|
| 固件 | 面向 ESP8266、ESP8285 与 ESP32 的开源 Lua 运行时，以 C 语言编写，ESP8266 上基于乐鑫 NON-OS SDK，ESP32 上基于 ESP-IDF；MIT 许可<sup>[1](https://www.nodemcu.com/docs/)</sup><sup> • </sup><sup>[2](https://github.com/nodemcu/nodemcu-firmware)</sup>  |
| 语言 | Lua 5.1（基于 eLua）或 Lua 5.3 构建，不含 `debug`、`io`、`os` 及大部分 `math` 模块<sup>[2](https://github.com/nodemcu/nodemcu-firmware)</sup><sup> • </sup><sup>[3](https://github.com/nodemcu/nodemcu-firmware/blob/release/docs/lua-developer-faq.md)</sup>  |
| 历史 | 由 Zeroday 与 Vowstar 内部开发，2014 年末在 GitHub 上首次开源；2015 年中起转为社区开发<sup>[3](https://github.com/nodemcu/nodemcu-firmware/blob/release/docs/lua-developer-faq.md)</sup> |
| Devkit V1.0 | 开源硬件，采用 ESP-12-E 核心，4 MB（32 Mbit）闪存，CP2102 USB 转串口适配器，micro-USB 烧录<sup>[4](https://github.com/nodemcu/nodemcu-devkit-v1.0)</sup> |
| 底层芯片 | ESP8266EX：Tensilica L106 32 位处理器，2.4 GHz 频段 802.11 b/g/n，最高 72.2 Mbps，供电 2.5–3.6 V，QFN32 5 mm × 5 mm 封装<sup>[5](https://documentation.espressif.com/0a-esp8266ex_datasheet_en.html)</sup> |
| 内存 | ESP8266 上有 96 kB 数据 RAM，其中通常约 44 kB 可作为应用程序的堆空间<sup>[6](https://nodemcu.readthedocs.io/en/latest/lfs/)</sup> |
| 功耗模式 | 调制解调器睡眠 15 mA，轻度睡眠 0.9 mA，深度睡眠 20 µA，关断 0.5 µA<sup>[5](https://documentation.espressif.com/0a-esp8266ex_datasheet_en.html)</sup> |
| 芯片状态 | 截至 2025 年 11 月的数据手册 v7.1 版，ESP8266EX 被标记为不推荐用于新设计（NRND），推荐以 ESP8684 作为升级型号<sup>[5](https://documentation.espressif.com/0a-esp8266ex_datasheet_en.html)</sup> |

## 固件与编程模型

NodeMCU 的编程模型是异步、事件驱动的，类似 Node.js，但使用的是 Lua。<sup>[1](https://www.nodemcu.com/docs/)</sup> 这源于底层的乐鑫 SDK：它是非抢占式、事件驱动的——任务以回调形式注册到事件上，SDK 将其排队并逐个运行，且明确规定任何任务若运行超过 15 ms，Wi-Fi 等服务就可能失效。NodeMCU 的库本质上是围绕已注册 Lua 回调的 C 语言封装，因此应用程序必须以事件驱动的风格编写，而不能写成单一的过程式流程。<sup>[3](https://github.com/nodemcu/nodemcu-firmware/blob/release/docs/lua-developer-faq.md)</sup>

**启动与交互。** 固件在启动时初始化 Lua 环境，并从 SPIFFS 文件系统执行模块 `init.lua`，该文件通常负责建立 Wi-Fi 连接并启动应用程序。默认情况下，运行时还会以交互模式监听 UART 0，执行通过串口输入的 Lua 命令，这是在设备上开发和调试应用程序最常见的方式。<sup>[3](https://github.com/nodemcu/nodemcu-firmware/blob/release/docs/lua-developer-faq.md)</sup>

**语言差异。** NodeMCU Lua 基于 eLua——一种针对嵌入式优化的 Lua 5.1 实现，对库模块使用只读表和常量，这种技术称为 Lua Tiny RAM（LTR），在典型构建中可减少约 20–25 kB 的 RAM 占用。标准 `io` 与 `os` 库无法使用，基本由 NodeMCU 的 `node` 与 `file` 库取代；`debug` 与 `math` 被省略以减小运行时占用。<sup>[3](https://github.com/nodemcu/nodemcu-firmware/blob/release/docs/lua-developer-faq.md)</sup> 后来又加入了 Lua 5.3 构建，采用对标准 Lua 源码最小改动的策略，同时保留 NodeMCU 的增强特性，例如直接从闪存 ROM 执行常量 Lua 程序和数据以释放 RAM，并为 ESP8266 与 ESP32 架构提供统一的代码基础。<sup>[7](https://nodemcu.readthedocs.io/en/release/lua53/)</sup>

**模块与构建。** 固件内置 70 多个 C 模块和近 20 个 Lua 模块，并提供带或不带浮点支持的版本，因为纯整数构建占用内存更少。<sup>[2](https://github.com/nodemcu/nodemcu-firmware)</sup> 固件可通过云构建服务、Docker 镜像或专用 Linux 环境构建；由于 ESP8266 的 RAM 有限，应禁用未使用的模块，以避免内存不足导致的崩溃。<sup>[8](https://nodemcu.readthedocs.io/en/dev/build/)</sup>

## 内存管理：SPIFFS 与 LFS

NodeMCU 项目使用 SPIFFS 文件系统在闪存芯片中存储文件。它是一种无子目录的平面文件系统，配置为 4 kB 扇区、8 kB 块、256 字节页；闪存芯片的最后 16 kB 保留给 SDK 存储 Wi-Fi 客户端设置等参数。在 512 kB 和 4 MB 及以上这两种主要闪存容量上，新格式化的文件系统起始于固件末尾之后 64 kB 至 128 kB 处，以便在反复重新烧录后仍能保留。<sup>[9](https://nodemcu.readthedocs.io/en/release/spiffs/)</sup>

**Lua 闪存存储。** 2018 年 7 月，项目加入了 Lua 闪存存储（LFS）支持，使 Lua 代码及其常量数据能够像固件一样直接从闪存运行。<sup>[2](https://github.com/nodemcu/nodemcu-firmware)</sup> 其动机在于 RAM 的不平衡：ESP8266 有 96 kB 数据 RAM，其中约一半被操作系统、栈和驱动占用，通常只剩 44 kB 堆空间，而映射的闪存 ROM 区域可达 960 kB，是前者的二十多倍。<sup>[6](https://nodemcu.readthedocs.io/en/latest/lfs/)</sup> Lua 源码在主机上通过 `luac.cross` 编译器交叉编译，该编译器由固件构建自动生成，也可用于对将在 NodeMCU Lua 下执行的 Lua 源码做语法检查。<sup>[10](https://nodemcu.readthedocs.io/en/dev/compiling/)</sup> 编译后的 LFS 镜像作为普通文件上传到 SPIFFS，再用 `node.LFS.reload("lfs.img")` 加载，之后模块便直接从闪存运行。<sup>[11](https://nodemcu.readthedocs.io/en/release/getting-started/)</sup>

## 硬件：开发板与 ESP8266EX

由 Zeroday 创立的 NodeMCU 公司开发并销售了基于 Lua 固件的 ESP8266 SoC 开发板。<sup>[3](https://github.com/nodemcu/nodemcu-firmware/blob/release/docs/lua-developer-faq.md)</sup> DEVKIT V1.0 是完全开源的硬件，使用 [Altium Designer](https://www.edgepedia.org/zh/altium-designer) 设计，搭载带 4 MB 闪存的 ESP-12-E 核心、CP2102 USB 转串口适配器（只需一根 micro-USB 线即可烧录），设计采用 MIT 许可。<sup>[4](https://github.com/nodemcu/nodemcu-devkit-v1.0)</sup> Arduino 核心文档将 NodeMCU 1.0（ESP-12E 模块）描述为最便宜的全集成 ESP8266 方案之一，在速卖通（AliExpress）上以多种名称销售，售价约 6.50 美元，配有 NCP1117 稳压器、GPIO16 上的蓝色 LED，以及 ADC 输入上的 220k/100k 欧姆分压器。<sup>[12](https://arduino-esp8266.readthedocs.io/_/downloads/en/2.5.1/pdf/)</sup>

**引脚标注。** 板上印制的引脚编号与 ESP8266 的 GPIO 编号并不对应：D0 对应 GPIO16，D1 对应 GPIO5，D2 对应 GPIO4，D3 对应 GPIO0，D4 对应 GPIO2，D5 对应 GPIO14，D6 对应 GPIO12，D7 对应 GPIO13，D8 对应 GPIO15。NodeMCU 固件的 GPIO 模块同样按 I/O 索引而非内部 GPIO 编号寻址引脚，且 D0（GPIO16）仅支持读写，不支持开漏、中断、PWM、I2C 或单总线。<sup>[12](https://arduino-esp8266.readthedocs.io/_/downloads/en/2.5.1/pdf/)</sup><sup> • </sup><sup>[13](https://nodemcu.readthedocs.io/en/dev/modules/gpio/)</sup>

**底层 SoC。** ESP8266EX 集成 Tensilica L106 32 位处理器，2.4 GHz 频段 802.11 b/g/n（HT20）Wi-Fi，最高 72.2 Mbps，支持站点、SoftAP 及混合模式，支持 WPA/WPA2 安全机制，外设包括 UART、SDIO、SPI、I2C、I2S、PWM、红外遥控和 10 位 SAR ADC。工作电压 2.5 V 至 3.6 V，平均电流 80 mA，温度范围 −40 °C 至 125 °C，采用 5 mm × 5 mm 的 32 引脚 QFN 封装。<sup>[5](https://documentation.espressif.com/0a-esp8266ex_datasheet_en.html)</sup> 用户程序必须存放在外部 SPI 闪存中，理论上支持最大 16 MB；禁用空中升级时至少需要 512 kB，启用时至少需要 1 MB。<sup>[5](https://documentation.espressif.com/0a-esp8266ex_datasheet_en.html)</sup>

## Wi-Fi 运行

每个 ESP8266 模组既可作为连接到接入点的站点（station）运行，也可作为最多服务五个站点的软接入点（soft access point）运行，或同时处于两种模式，从而支持网状网络节点。当目标网络的凭据无法预先获知时，软 AP 模式常被用作中间步骤：模组以接入点身份启动，手机或笔记本电脑连接并提供凭据，设备随后切换到站点模式；NodeMCU 的 enduser setup 模块提供了这一功能。<sup>[14](https://nodemcu.readthedocs.io/en/release/modules/wifi/)</sup> 固件的 Wi-Fi 子系统由必须定期运行的后台任务维护，因此任何耗时超过 15 ms 的函数或任务都可能导致其崩溃，除非先挂起 Wi-Fi。<sup>[14](https://nodemcu.readthedocs.io/en/release/modules/wifi/)</sup>

## 项目状态

2015 年中，开发工作从创始公司转交给社区核心小组，后续工作包括在开源的乐鑫 LwIP 之上以原生方式重新实现网络栈、由 Johny Mattsson 主导的 ESP32 移植，以及由 Marcel Stör 主导的完整在线文档。<sup>[3](https://github.com/nodemcu/nodemcu-firmware/blob/release/docs/lua-developer-faq.md)</sup> 人们发现基于 ESP8266 RTOS 的构建无法留出足够的空闲 RAM 来构成可用的基于 RTOS 的 NodeMCU 固件，因此 ESP8266 的 `release` 与 `dev` 分支仍留在 NON-OS SDK 上，而 RAM 显著更大的 `dev-esp32` 分支则使用基于 RTOS 的 ESP-IDF。<sup>[3](https://github.com/nodemcu/nodemcu-firmware/blob/release/docs/lua-developer-faq.md)</sup> 在芯片方面，乐鑫的数据手册 v7.1 于 2025 年 11 月将 ESP8266EX 列为不推荐用于新设计，并将新设计引向 ESP8684。<sup>[5](https://documentation.espressif.com/0a-esp8266ex_datasheet_en.html)</sup>

## References

1. [NodeMCU Documentation](https://www.nodemcu.com/docs/)
2. [nodemcu/nodemcu-firmware, GitHub](https://github.com/nodemcu/nodemcu-firmware)
3. [Lua Developer FAQ, nodemcu-firmware docs](https://github.com/nodemcu/nodemcu-firmware/blob/release/docs/lua-developer-faq.md)
4. [nodemcu/nodemcu-devkit-v1.0, GitHub](https://github.com/nodemcu/nodemcu-devkit-v1.0)
5. [ESP8266EX Datasheet v7.1, Espressif](https://documentation.espressif.com/0a-esp8266ex_datasheet_en.html)
6. [Lua Flash Store (LFS), NodeMCU Documentation](https://nodemcu.readthedocs.io/en/latest/lfs/)
7. [Lua 5.3 Support, NodeMCU Documentation](https://nodemcu.readthedocs.io/en/release/lua53/)
8. [Building the firmware, NodeMCU Documentation](https://nodemcu.readthedocs.io/en/dev/build/)
9. [Internal filesystem (SPIFFS), NodeMCU Documentation](https://nodemcu.readthedocs.io/en/release/spiffs/)
10. [Compiling code, NodeMCU Documentation](https://nodemcu.readthedocs.io/en/dev/compiling/)
11. [Getting started, NodeMCU Documentation](https://nodemcu.readthedocs.io/en/release/getting-started/)
12. [ESP8266 Arduino Core Documentation](https://arduino-esp8266.readthedocs.io/_/downloads/en/2.5.1/pdf/)
13. [GPIO module, NodeMCU Documentation](https://nodemcu.readthedocs.io/en/dev/modules/gpio/)
14. [WiFi module, NodeMCU Documentation](https://nodemcu.readthedocs.io/en/release/modules/wifi/)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 17, 2026; Sep 30, 2026; Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 计算机硬件 › Embedded & soft processors › Embedded systems › Industrial, automotive, and IoT embedded systems

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/nodemcu

English original: https://www.edgepedia.org/nodemcu
