在上一篇文章《串口转 Wi-Fi 模块 ESP8266-01》里,LT 初步接触了 ESP8266-01,不过由于ESP-01 还得借助一个 Arduino 来提供 3.3V 电源以及串口连接,诸多不便,索性还是买了 NodeMCU 开发版。这次开始 LT 粗心大意了,入手的这个板子正面 Lua 管脚标识印刷得不好,下边一行都是重叠的,看官如果要买来用 Lua 的话,要注意一下。
Github : https://github.com/nodemcu/nodemcu-devkit-v1.0
一、NodeMCU 管脚图
下图是此板的管脚图
关于几个特别引脚的说明:
- GPIO02 (D4) 接蓝色 LED 的的负极,位置在 ESP-12 模块上。
- GPIO16 (D0) 接蓝色 LED 的的负极,位置在 RST 按钮旁边。
二、MicroPython 固件
尽管这块板子的正面 Lua 管脚标识印刷不好,但是背面印的却是 ESP8266的管脚标识,这个是出乎意料的!
LT 决定干脆刷了 MicroPython 固件来用这块板子,让它作为专门的用途。刷固件使用 esptool.py,参见 http://www.micropython.org/download#esp8266
可将下面命令存为批处理调用,注意要根据实际情况来设置 –port com5 和 –flash_mode dio 以及 esp8266-20170612-v1.9.1.bin:
esptool.py --port com5 erase_flash esptool.py --port com5 --baud 460800 write_flash --flash_mode dio --flash_size=detect 0 esp8266-20170612-v1.9.1.bin
执行后,软件会自动 rst 和进入 flash 状态,过程输出状态如下:
D:\Firmware>esptool.py --port com5 erase_flash esptool.py v2.0.1 Connecting.... Detecting chip type... ESP8266 Chip is ESP8266 Uploading stub... Running stub... Stub running... Erasing flash (this may take a while)... Chip erase completed successfully in 2.4s Hard resetting... D:\Firmware>esptool.py --port com5 --baud 460800 write_flash --flash_mode dio --flash_size=detect 0 esp8266-20170612-v1.9.1.bin esptool.py v2.0.1 Connecting.... Detecting chip type... ESP8266 Chip is ESP8266 Uploading stub... Running stub... Stub running... Changing baud rate to 460800 Changed. Configuring flash size... Auto-detected Flash size: 4MB Flash params set to 0x0240 Compressed 598432 bytes to 390605... Wrote 598432 bytes (390605 compressed) at 0x00000000 in 8.8 seconds (effective 542.7 kbit/s)... Hash of data verified. Leaving... Hard resetting...
开发环境可使用 uPyLoader https://github.com/BetaRavener/uPyLoader/releases 软件可以实现上传、下载以及编辑py文件,同时也具有终端界面可供交互。
三、Lua 固件
后来 LT 又买了一块 -_-! ,这次这块板子正面印刷的 Lua 管脚标识很清楚
但是背面没有印 ESP8266 的管脚标识,于是 LT 决定这块就使用默认的 Lua 固件。
根据板子背面的提示,串口速率设为9600,串口打开后,串口终端不断收到
Please run file.remove("user.lua") before first use. Please run file.remove("user.lua") before first use. Please run file.remove("user.lua") before first use. Please run file.remove("user.lua") before first use. Please run file.remove("user.lua") before first use. Please run file.remove("user.lua") before first use. Please run file.remove("user.lua") before first use.
可以在串口终端里输入下面语句移除
file.remove("user.lua") node.restart()
开发环境可使用 ESPlorer https://esp8266.ru/esplorer/
可以新建一个 init.lua 来闪烁 D4上接的LED
lighton=0 pin=4 gpio.mode(pin,gpio.OUTPUT) tmr.alarm(1,2000,1,function() if lighton==0 then lighton=1 gpio.write(pin,gpio.HIGH) else lighton=0 gpio.write(pin,gpio.LOW) end end)
可以看到 lua 对 GPIO02 的定义是 4,这点与 MicroPython 的定义为 2 是不一样的。