Run NodeMCU on ESP8266 LoLin V3
BSD-3-CLAUSE License
These are my notes for flashing and programming the LoLin V3 ESP8266 ESP-12E CH340G WIFI Network Development Board. This may work on other ESP8266 based boards as well. This is for Linux only and specifically on Ubuntu 18.04 x84-64. I suspect it will work on other Linux distributions.
I bought 5 on ebay with shipping they were about $3.59 US each. They come from China at that price, so you are going to wait a few weeks to reach the US. Search EBay for "NodeMcu Lua ESP8266 ESP-12E" The LoLin ones I bought came with 4 MB flash. This particular board is too wide for a standard breadboard, but you can attach 2 mini breadboards together.
You want to make sure Ubuntu discovers your device. I just plugged it in without any additional drivers and it showed up. I used a standard micro USB cable to connect to PC.
lsusb
Bus 006 Device 002: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter
This will bring your device up to the latest NodeMCU release. I used the dev branch with floating point. I had to use master branch to get u8g module working, so build to suite your needs.
sudo usermod -a -G dialout username
(Use a non-root username)sudo -H pip install esptool
esptool.py chip_id
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Uploading stub...
Running stub...
Stub running...
Chip ID: 0x00000000
Hard resetting via RTS pin...
esptool.py flash_id
Detected flash size: 4MB
esptool.py erase_flash
esptool.py write_flash --flash_mode dio 0x00000 nodemcu-dev-7-modules-2018-03-10-17-09-58-float.bin
I had an instance where my code was supposed to put the NodeMCU in deep sleep, but crashed instead. Since I used a init.lua I was unable to flash, erase flash, etc. A lot of the solutions you'll find out there do not work. The only thing that worked for me was to:
I'm using ESPlorer, but Arduino IDE could probably be used as well.
cd ~/ESPlorer
java -jar "ESPlorer.jar"
Communication with MCU..Got answer! Communication with MCU established.
AutoDetect firmware...
Can't autodetect firmware, because proper answer not received (may be unknown firmware).
Please, reset module or continue.
NodeMCU custom build by frightanic.com
branch: dev
commit: 5c8af3c452574448d471e271231b36ac3fff6b1b
SSL: false
modules: file,gpio,net,node,tmr,uart,wifi
build built on: 2018-03-10 17:08
powered by Lua 5.1.4 on SDK 2.1.0(116b762)
lua: cannot open init.lua
>
Let's try a simple function to list WIFI APs.
function listap(t) -- (SSID : Authmode, RSSI, BSSID, Channel)
print("\n"..string.format("%32s","SSID").."\tBSSID\t\t\t\t RSSI\t\tAUTHMODE\tCHANNEL")
for ssid,v in pairs(t) do
local authmode, rssi, bssid, channel = string.match(v, "([^,]+),([^,]+),([^,]+),([^,]+)")
print(string.format("%32s",ssid).."\t"..bssid.."\t "..rssi.."\t\t"..authmode.."\t\t\t"..channel)
end
end
wifi.sta.getap(listap)
> wifi.sta.getap(listap)
>
SSID BSSID RSSI AUTHMODE CHANNEL
test e7:98:f1:45:36:b8 -47 3 3
SXE465TF 21:e7:1a:88:9b:c5 -65 3 11
xyz1 49:e1:1c:52:65:c6 -64 4 11
This uses a init.lua and blink.lua script to flash an LED on boot. Change pin number in blink.lua as needed. Just create files in ESPlorer (blink.lua first) and click on Run. init.lua sets up wifi to use a static address and runs blink.lua.