Thursday, January 5, 2017

Node Mcu ESP8266 Quick Start



Node Mcu ESP8266 Quick Start


ESP8266 Quick Start

This page is meant to be a quick introduction to the ESP8266 for those who are confused by all of the information available on the various blogs and forums who just want to try out this exciting board in the shortest possible time. This guide is for Windows users who want to use the NodeMCU environment.
Not counting waiting for hardware to ship to you (1-10 days), you should be able to use your ESP8266 for something useful in less than an hour. Ready?

What do I need to buy?

You will need an ESP8266 development board. There are several ESP8266 boards available, usually numbered ESP-01 through ESP-12. Check the pins of the actual board you order with the information from your source as the rapid development of these products has led to confusion and duplication of board identification numbers.
A 3 volt power supply. The ESP8266 runs on anything from 2.8 to 3.5 volts, so a couple of AA batteries will work. Most of us use a 3.3 volt regulated power source. Maximum current draw is 300 mA, so use a supply that can supply 500 mA to be safe. More is better. A weak or poor quality supply will cause the board to reset unexpectedly and make debugging difficult. The NodeMCU Development Board has a USB to 3.3V power supply on the board.
A USB to serial adapter. This should be a 3.3 volt compatible model. It is possible to level convert if you already have a 5 volt adapter. The NodeMCU Development Board has the USB to serial interface on the board. When you receive your adapter, verify that the actual voltage output is 3.3 volts as some cheap adapters have been found to be mislabelled. Any of the following should work: FTDi,CH340, FT232RL.

What do I need to download?

The ESP8266 board you bought may have one of many different firmware versions on it. Many come with AT firmware for serial communications. Some come with no user firmware at all. I recommend the NodeMCU Lua firmware as a starting point because it gives you an interactive programming language which allows you to experiment and build simple working programs without a lot of effort. If you are not familiar with Lua, you will find that it is not hard to learn, at least for the simple tasks needed to get started.
The tool you will use to flash the NodeMCU firmware on your ESP8266 board is thenodemcu-flasher. It is open source on github. Go to the nodemcu-flasher page and choose Win32 or Win64 depending on your computer system. Click on ESP8266Flasher.exe and then right click on View Raw and Save Link As... to download the application to your PC. Or use the direct links below:
ESP8266Flasher.exe for Win32 

ESP8266Flasher.exe for Win64

What do I have to connect?

The actual connections will depend on the board you have and the USB to serial adapter you are using.
ESP8266 connections
  • Power.
    • +3.3 volts to Vcc
    • ground
  • Communications.
    • TxD on the board to RxD on the adapter
    • RxD on the board to TxD on the adapter
    • Ground
  • Jumpers.
    • Connect Vcc to CH_PD to enable the chip
    • Connect GPI0 to GND to enable flash reprogramming

How do I install NodeMCU on my ESP8266?

Plug the USB to serial adapter into your PC. Most adapters are automatically recognized by Windows 7 and 8. Users of XP or older versions of Windows may need a driver which should be supplied by the manufacturer of the USB adapter. The adapter will appear as a new COM port on your system. Check the Device Manager if necessary.
Run ESP8266Flasher.exe
NodeMcuFlasher
If you only have one COM device, the port will appear automatically. If you have more than one, select the correct one from the drop down menu.
The flasher program comes with default NodeMCU firmware in memory. This is unlikely to be the latest version, but to get started quickly, use the default internal image. Later, you can download the latest firmware, then select the [Config] tab and choose the new .bin file. Select the 0x7C000 default and 0x7E000 blank sections. Uncheck the box for the 0x10000 IROM section.
Click on Flash(E) to start the programming process. If the MAC addresses dont appear within a few seconds, disconnect the power to the board and reconnect it. If it still doesnt work, check your connections. Make sure that the jumper between GND and GPIO0 is there so that the board is in reflash mode.
Reflashing the chip will take a couple of minutes. When the job is done, disconnect power from the board and remove the jumper from GND to GPIO0 to leave reflash mode.
You are now ready to program the ESP8266 for your own application.

How do I communicate with the ESP8266?

The NodeMCU Lua firmware you have just installed communicates with the PC over the serial link. You can use PuTTY, SimpleTerm, or any other terminal program that you like to write Lua programs or enter direct commands to the board. The default speed is 9600 baud, but that can be changed to any other baud rate once you have established communications.

LuaLoader

LuaLoader is a Windows program for uploading files to the ESP8266 and working with the Lua serial interface. As well as being a simple terminal program, it has built in Lua command buttons that make it easy to interact and experiment with the ESP8266 board.
Download: LuaLoader.zip
LuaLoader.exe is a simple Windows application that requires no special installation.

From the Settings menu, select COM Port Settings and choose the appropriate COM port for your USB to serial adapter. Dont change any other setting.
Clicking buttons on LuaLoader sends commands to the board. Power your board and watch for the initial message. After displaying some funny characters (these are firmware reset parameters sent at 74880 baud), you should see the version information of the NodeMCU build:
NodeMCU 0.9.5 build 20150107 powered by Lua 5.1.4
LuaLoader will warn you if a later firmware build is available.
After booting, NodeMCU will attempt to run a file called init.lua in flash memory. Since you havent put it there, it will report an error and show the > prompt. You are now ready to interact with Lua on the ESP8266.
Click the Heap button to display the amount of RAM available. LuaLoader will type the command = node.heap()and the ESP8266 will respond with 23016 or some other value, followed by the > prompt again.

How do I connect to an Access Point?

Enter the SSID and password of your closest access point in the appropriate text box on LuaLoader. Click Set AP. LuaLoader will type the commands to set the WiFi mode and connect. This information is saved in flash memory and will be remembered until changed, even if the board is powered down.
Click the  WiFi button to check the connection status.
Click Get IP to confirm that the ESP8266 is connected to your access point.
Click the Survey button to list the available access points visible to the ESP8266. The SSID, authentication mode, signal strength, MAC address and channel are shown.