Friday, 14 April 2017

Just starting with NodeMCU

I have just received a couple of NodeMCU's which I plan to use for some security devices.

These are tiny circuit boards about 50mm long x 25mm wide. The chip is a computer processor with WiFi built in attached to a board with pins on for easy development of a prototype. They are designed to be low cost for use as Internet of Things (IoT) processors. UK stock cost me a massive £8 each but from China they are less than £3 each, including shipping!

They are used by the same people that like to make small gadgets using the tiny Raspberry Pi computer and the Arduino processor boards.

Before the NodeMCU's arrived I'd been searching the Internet to find out how to get started. The trouble is that it gets confusing. There is lots of outdated information, the NodeMCU is also referred to as ESP8266, there are multiple development environments and so on.

This is a list of what has confused me and the conclusions I have made, so far.

NodeMCU or ESP8266
The ESP8266 is the processor which has built in Wifi. This is used as an add-on board for Arduino as well as a stand alone product called NodeMCU.

This uses the ESP8266 wifi enabled processor and includes a serial to USB adapter on board.
It is that latter bit that is significant. You don't need any extra hardware to get going with the NodeMCU. Just power.
As far as I can tell the NodeMCU includes a firmware implementation of the LUA environment. Not just the hardware.
If you use one of the other development environments LUA will be replaced and so arguably it is no longer a NodeMCU board! Very confusing.
I will refer to NodeMCU meaning the hardware in the configuration expected by the NodeMCU implementation of the ESP8266.

There are several different manufacturers but as far as I can tell there are only minor differences between them and the pin outs are the same. There is a smaller and larger board. I prefer the pin outs on the larger board.

The boards I received are branded 'Amica.'

How to power the NodeMCU
The simplest is to just use the USB port. Plug in a USB power adapter or a cable from the USB port of a PC.
The preferred method for a wired in power source is to use the Vin pin. This connects to a voltage regulator on the board so you can connect any DC power source between +5V and +10V. The regulator can handle up to 800mA which is enough for most small circuits.
There are also several 3.3V pins which, as far as I understand, are in and out so they provide 3.3V for external devices or can be used with a regulated power supply or to plug batteries in to. The ESP8266 chip will apparently work with anything between 2.8V and 3.5V, so 2x AA batteries should do it. I have not tested this yet.
There's some more detailed explanations on the following page:

Development environments

This is where it gets even more confusing.

NodeMCU firmware
The firmware is the programme running on the ESP8266 processor. You can change that firmware. Exactly what that is and how you change it depends on what development environment you use:
- LUA comes as standard.
- Python needs to be built and deployed to the NodeMCU.
- Arduino IDE compiles the code and installs it as part of the upload process to the NodeMCU.

- The standard for a NodeMCU is LUA.
This is a high level language needing very few skills to get going with.
It's disadvantage is that it uses up a lot of the in-built memory for the interpreter!
Despite it being the original environment, I ruled this out fairly early on and have not tried it:

- Python
There is a whole community developing this:
I've not looked in great detail at this but it looks like a fully implemented solution with some good features. I've done some Python programming before but I'm not a fan of the lax structure of the Python language. Others however do like it and it is very popular.

- Arduino IDE
This is the one I have started to use. It uses C++ syntax and libraries and appears to be the most common choice. The code is complied before being uploaded to the ESP8266 so uses the least amount of memory.
You need the Arduino IDE:
Then add the extension for the IDE to support ESP8266 based boards. This is available as a package that is easy to install. You just include this one line in the Arduino IDE preferences:

See the following tutorial:

The instruction imply that the ESP8266 boards install automatically. They do not. They get added to the Board Manager and you need to browse the list in Board Manager, select the ESP8266 based boards and hit install.

Once that is installed you need to select the NodeMCU board from the list of boards.

Finally before being able to upload your programme to the NodeMCU you need to find out what COM port your NodeMCU appears as on your computer. The COM port is assigned when you plug in the NodeMCU to the USB port.

Serial USB Connection
The back of my board says to use a CP2102 driver at only 9,600 baud. The default in the Arduino IDE is much faster at 115,200 baud which worked fine for me.

I had installed the Arduino IDE prior to connecting the NodeMCU. The Arduino IDE also installs some serial drivers. I don't know where the driver came from but when I plugged in the board to the PC USB port it installed a CP210x driver and displayed the COM port it was assigned to. In my case COM 4 but that will depending on which USB port it is connected to and what else uses COM ports on the machine.

You can lookup the COM ports used in Device Manager or watch the driver install, which shows the COM port.
I'm using Windows 10 but this was similar in Windows 7 and 8.1.

Don't get misled by the references to an FTDI cable or serial adapter that you might come across in other articles. That adapter cable is not necessary for a NodeMCU. The serial to USB is built in, that is what the CP2102 chip does. The adapter cable is only needed for the add-on shield type boards typically used with Arduino's that do not include that extra chip.

Hello World
When learning a programming language the first thing you typically do is to display 'Hello World' on the screen. Something easy to do that checks that all the basics are working. The electronics equivalent of that, in this context, is to blink an LED.

I copied in the sketch, as the code is referred to, pressed the button in the Arduino IDE to upload it to the NodeMCU and waited for a minute or two as it compiled and uploaded. It worked perfectly.


Useful sites:

ESP8266 using Arduino IDE, code library documentation:

Arduino language reference:
Arduino standard and add-on libraries. Not directly useful for ESP8266 but might be handy:


I found out by accident that the Vin pin will also supply the output voltage from the USB port. I don't know how reliable this is but it powered the 5V ultrasonic sensor I was using.


I purchased the same make NodeMCU from two different suppliers:
UK for speed - - alictronix
China for very low cost - - worldchips
Both suppliers have been very good and I would re-order from them.


No comments :