NodeMCU: upgrading firmware and experimenting LUA

As you might already know, I’ve just placed three Arduino MEGAs around my new house and I’m using them to –among other things– turn on/off the lights of the whole house.

I still have to “enter” the new house so… I’m currently “configuring” the “light-switching” system (associating LIGHTs with related Push-Buttons).

After several”upgrades” of the Arduino sketches, I decided to simplify the “update” process, putting in place an “OTA infrastructure”. Basically, I decided to upload the new versions of the sketches, wirelessly (WiFi),  with some ESP8266.

I already bought three NodeMCU boards. Three of this:

As you can see, they are labeled “LoLin NodeMCU v3” and actually, they are not a simple ESP8266, but instead a real “ESP8266 Development Boards”, as they include an USB connection as well as the necessary power regulator (USB is 5V while ESP8266 requires 3.3V). Also, the board expose the ESP8266 PINs in a so-called breadboard-friendly manner.

My first attempt to get “life” from the USB cable were not much succesful so I decided NOT to trust the provided bootloader/firmware and to start flashing my desired firmware, EspLink.

After a preliminary quick look at the official page I decided to double-check my ESP8266 really had 4MB of flash. To do so, as well as to re-flash my ESP8266, I needed the official esptool:

verzulli@iMac-Chiara:~$ sudo pip install esptool
Downloading/unpacking esptool
  Downloading esptool-1.3.tar.gz
  Running egg_info for package esptool
Requirement already satisfied (use --upgrade to upgrade): pyserial>=2.5 in /usr/lib/python2.7/dist-packages (from esptool)
Installing collected packages: esptool
  Running install for esptool
    changing mode of build/scripts-2.7/ from 644 to 755
    changing mode of /usr/local/bin/ to 755
Successfully installed esptool
Cleaning up...
verzulli@iMac-Chiara:~$ version v1.3

esptool need to be pointed to the serial device interfacing the ESP. To check how my Linux box recognize the FTDI chip of my development board, I just connected the board and, a couple of second later, just fired a dmesg:

root@iMac-Chiara:~#  dmesg
[123258.958360] usb 2-1.4: new full-speed USB device number 11 using ehci-pci
[123259.051119] usb 2-1.4: New USB device found, idVendor=1a86, idProduct=7523
[123259.051127] usb 2-1.4: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[123259.051131] usb 2-1.4: Product: USB2.0-Serial
[123259.051517] ch341 2-1.4:1.0: ch341-uart converter detected
[123259.053139] usb 2-1.4: ch341-uart converter now attached to ttyUSB0

As you can see, the board have been recognized as TTYUSB0. Great.

So, finally, to check the flash data, was as simple as:

verzulli@iMac-Chiara:~$ --port /dev/ttyUSB0 flash_id v1.3
Manufacturer: ef
Device: 4016

So my “Device” is recognized as “4016” and, based on the source, it’s:

#define AMIC_A25LQ032  0x4016

exactly the same as the one in the official doc. It has 32Mbit of storage, aka: 4MB.

At this point, everything is ready for flashing. I decided to try the pyflasher tool, as it seems quite stable and used among the community, and also with a nice development speed.

So, finally, I simply needed a firmware to flash. Even tough I already choosed Esplink I decided to test also the latest version of NodeMCU.

I was initially worried by the fact that the official page does not provide a binary firmware ready to be flashed… BUT… I was IMPRESSED by the fact that there’s a sort of “official” build-service by which you can simply “ask” for your firmware and… they will build it for you, as you need, based on your own preference! Simply AMAZING! So I checked the module I plan to test:

and submitted the request. A couple of minutes later…. guess what?

Uau! My custom firmware, built for me, in few minutes! Really impressive! Again!

As you can see, the mail mentioned TWO firmwares, and not one. Why?Because –as stated in the official page— “…Firmware available with or without floating point support (integer-only uses less memory)….“.

As I should have enough flash memory and as I want to be open to perform floating point operations…. I choosed the “float” one. I downloaded it:

verzulli@iMac-Chiara:/tmp$ wget
100%[======================================================================>] 432.304      185KB/s   in 2,3s   

2017-04-01 22:25:27 (185 KB/s) - "nodemcu-master-11-modules-2017-04-01-19-58-33-float.bin" salvato [432304/432304]


and, finally, everything is ready for flashing.

I launched the nodemcu-pyflasher tools, pointed it to the right tty interface and firmware image and clicked the “Flash NodeMCU”. One minute later, I got this:

So, hopefully, I should have a brand-new NodeMCU board.

After launching minicom, pointing it to /dev/ttyUSB0 and configuring the terminal 115200/8/n/1, I got:


Good news! The message: “lua: cannot open init.lua” is ok as there is no lua script, currently, to launch at boot (init.lua). So we don’t care. About the “garbage” we see on the first line, I think it’s some sort of messages that the ESP dump on the console, right at boot, at a speed different than the 115200 we are operating. Hence, we don’t care as well.

After the all of this, I finally choosed to turn on the integrated LED. A quick search revealed that the PIN number to use is 4 and hence:

> gpio.mode(4, gpio.OUTPUT)

is needed, at first, to declare the PIN as an output one.

Than, a simple:

> gpio.write(4,gpio.LOW)

turned the LED “ON”:

Also, a simple:

> gpio.write(4,gpio.HIGH)

turned it “OFF”.

So, in the end, IT WORKED!!!! We have a perfectly running NodeMCU development board based on ESP8266-12E.

Now it’s time to switch to ESP-Link but…. this is a topic for another POST 🙂

HTH and… feel free to comment!

Leave a Reply

Your email address will not be published. Required fields are marked *