9. Overview Of NodeMCU/ESP8266
Introduction
of ESP8266
NodeMCU is an open source LUA based firmware developed for ESP8266 wifi chip. By exploring
functionality with ESP8266 chip, NodeMCU firmware comes with ESP8266
Development board/kit i.e. NodeMCU Development board.
ESP8266 is Wi-Fi enabled system on chip (SoC)
module developed by Espressif system. It is mostly used for development of IoT
(Internet of Things) embedded applications.
ESP8266 comes with capabilities of
- 2.4 GHz Wi-Fi (802.11 b/g/n, supporting
WPA/WPA2),
- general-purpose input/output (16 GPIO),
- Inter-Integrated Circuit (I²C) serial
communication protocol,
- analog-to-digital conversion (10-bit
ADC)
- Serial Peripheral Interface (SPI) serial
communication protocol,
- I²S (Inter-IC Sound) interfaces with
DMA(Direct Memory Access) (sharing pins with GPIO),
- UART (on dedicated pins, plus a
transmit-only UART can be enabled on GPIO2), and
- pulse-width modulation (PWM).
It employs a
32-bit RISC CPU based on the Tensilica Xtensa L106 running at 80 MHz (or
overclocked to 160 MHz). It has a 64 KB boot ROM, 64 KB instruction
RAM and 96 KB data RAM. External flash memory can be accessed through SPI.
ESP8266 module
is low cost standalone wireless transceiver that can be used for end-point IoT
developments.
To communicate
with the ESP8266 module, microcontroller needs to use set of AT commands.
Microcontroller communicates with ESP8266-01 module using UART having specified
Baud rate.
There are many
third-party manufacturers that produce different modules based on this chip.
So, the module comes with different pin availability options like,
- ESP-01 comes with 8 pins (2 GPIO pins) –
PCB trace antenna. (shown in above figure)
- ESP-02 comes with 8 pins, (3 GPIO pins)
– U-FL antenna connector.
- ESP-03 comes with 14 pins, (7 GPIO pins)
– Ceramic antenna.
- ESP-04 comes with 14 pins, (7 GPIO pins)
– No ant.
etc.
For example,
below figure shows ESP-01 module pins
ESP8266-01 Module Pin Description
ESP8266-01 Module Pins
- 3V3: - 3.3 V Power Pin.
- GND: - Ground Pin.
- RST: - Active Low Reset Pin.
- EN: - Active High Enable Pin.
- TX: - Serial Transmit Pin of UART.
- RX: - Serial Receive Pin of UART.
- GPIO0 & GPIO2: - General Purpose I/O Pins. These pins decide what mode (boot or normal) the module starts up in. It also decides whether the TX/RX pins are used for Programming the module or for serial I/O purpose.
ESP8266 AT Command Set
Function
|
AT Commands
|
Response
|
Working
|
AT
|
OK
|
Restart
|
AT+RST
|
OK
.......
Ready
|
Firmware Version
|
AT+GMR
|
<AT version info> information about AT version
<SDK version info> information about SDK version
<compile time> time of the bin was compiled
OK
|
List Access Point
|
AT+CWLAP
|
+CWLAP:<ecn>,<ssid>,<rssi>,<mac>,<ch>,<freq
offset>
OK
|
Query Joined Access Point
|
AT+CWJAP?
|
+CWJAP:<ssid>,<bssid>,<channel>,<rssi>
OK
|
Join Access Point
|
AT+CWJAP=”SSID”,”Password”
|
WIFI CONNECTED
WIFI GOT IP
OK
|
Quit Access Point
|
AT+CWQAP
|
OK
WIFI DISCONNECTED
|
Get IP Address
|
AT+CIFSR
(Assuming AT+CWMODE=3)
|
+CIFSR:APIP,<IP address>
+CIFSR:APMAC,<mac address>
+CIFSR:STAIP,<IP address>
+CIFSR:STAMAC,<mac address>
OK
|
Query WiFi Mode
|
AT+CWMODE?
|
+CWMODE:<mode>
|
Set WiFi Mode
|
AT+CWMODE=<mode>
Mode: -
1 = STA (station)
2 = AP (Access Point)
3 = BOTH i.e. STA & AP
|
OK
|
Query TCP/UDP Connection
|
AT+CIPMUX?
|
+CIPMUX:<mode>
|
Set TCP/UDP Connection
|
AT+CIPMUX=<mode>
Mode: -
0 = Single Connection
1 = Multiple Connection
|
OK
|
TCP/IP Connection status
|
AT+CIPSTATUS
|
STATUS:<status>
Possible statuses are
2: Got IP
3: Connected
4: Disconnected
|
Query TCP transmission mode
|
AT+CIPMODE?
|
+CIPMODE:<mode>
|
Set TCP transmission mode
|
AT+CIPMODE=<mode>
Mode: -
0 = Normal mode
1 = Transparent mode
|
OK
|
Set up TCP/UDP connection
|
(CIPMUX=0) AT+CIPSTART = <type>,<addr>,<port>
(CIPMUX=1) AT+CIPSTART= <id>,<type>,<addr>,
<port>
Example (CIPMUX=0):
AT+CIPSTART="TCP","192.168.101.110",80
|
CONNECT
OK
|
Send Data
|
(CIPMUX=0) AT+CIPSEND=<data length>
(CIPMUX=1) AT+CIPSEND=<id>,<data length>
|
OK
>
(Note: write your data after > and enter it to send it will return
status like.)
Recv <data length> bytes
SEND OK
(after we receive response from server if any for default auto receive
mode)
(CIPMUX=0): + IPD, <length>: <data>
(CIPMUX=1): + IPD, <id>, <length>: <data>
|
Close TCP/UDP Connection
|
AT+CIPCLOSE
|
CLOSED
OK
|
NodeMCU
Development Kit/Board
NodeMCU
Development Kit/Board consist of ESP8266 wifi chip. ESP8266 chip has GPIO pins,
serial communication protocol, etc. features on it.
ESP8266 is
a low-cost Wi-Fi chip developed by Espressif Systems with TCP/IP
protocol.
The features of ESP8266 are extracted on NodeMCU Development board.
NodeMCU (LUA based firmware)
with Development board/kit that consist of ESP8266 (wifi enabled chip) chip
combines NodeMCU Development board which make it stand-alone device in IoT
applications.
Let’s see 1st version of NodeMCU Dev Kit and its pinout as shown in
below images.
NodeMCU Development Board
v0.9 (Version1)
NodeMCU Dev Kit v0.9(V1)
Pinouts
2nd version of NodeMCU Dev Kit and its Pinout as
shown in below images.
Amica NodeMCU Dev Kit
v1.0(Version2)
NodeMCU Dev Kit v1.0(V2)
Pinouts
NodeMCU Dev Kit v1.0 pin
descriptions
GPIO (General Purpose Input
Output) Pins:
NodeMCU has
general purpose input output pins on its board as shown in above pinout
diagram. We can make it digital high/low and control things like LED or switch
on it. Also, we can generate PWM signal on these GPIO pins.
ADC
(Analog to Digital Converter) channel (A0):
NodeMCU has one
ADC channel/pin on its board.
SPI
(Serial Peripheral Interface) Pins:
NodeMCU based
ESP8266 has Hardware SPI (HSPI) with four pins available for SPI communication.
It also has SPI pins for Quad-SPI communication. With this SPI interface, we
can connect any SPI enabled device with NodeMCU and make communication possible
with it.
I2C (Inter-Integrated
Circuit) Pins:
NodeMCU has I2C
functionality support on ESP8266 GPIO pins. Due to internal functionality on
ESP-12E we cannot use all its GPIOs for I2C functionality. So, do tests before
using any GPIO for I2C applications.
UART
(Universal Asynchronous Receiver Transmitter) Pins:
NodeMCU based
ESP8266 has two UART interfaces, UART0 and UART1. Since UART0 (RXD0 & TXD0)
is used to upload firmware/codes to board, we can’t use them in applications
while uploading firmware/codes.
How to start with NodeMCU?
NodeMCU
Development board is featured with wifi capability, analog pin, digital pins
and serial communication protocols.
To get start with
using NodeMCU for IoT applications first we need to know about how to
write/download NodeMCU firmware in NodeMCU Development Boards. And before that
where this NodeMCU firmware will get as per our requirement.
There is online
NodeMCU custom builds available using which we can easily get our custom
NodeMCU firmware as per our requirement.
How to write codes for NodeMCU?
After setting up
ESP8266 with Node-MCU firmware, let’s see the IDE (Integrated Development
Environment) required for development of NodeMCU.
NodeMCU with ESPlorer IDE
Lua scripts are generally
used to code the NodeMCU. Lua is an open source, lightweight, embeddable
scripting language built on top of C programming language.
NodeMCU
with Arduino IDE
Here is another
way of developing NodeMCU with a well-known IDE i.e. Arduino IDE. We can also
develop applications on NodeMCU using Arduino development environment. This
makes easy for Arduino developers than learning new language and IDE for
NodeMCU.
Difference in using ESPlorer and
Arduino IDE
Well, there is a
programming language difference we can say while developing application for
NodeMCU using ESPlorer IDE and Arduino IDE.
We need to code
in C\C++ programming language if we are using Arduino IDE for developing
NodeMCU applications and Lua language if we are using ESPlorer IDE.
Basically,
NodeMCU is Lua Interpreter, so it can understand Lua script easily. When we
write Lua scripts for NodeMCU and send/upload it to NodeMCU, then they will get
executes sequentially. It will not build binary firmware file of code for
NodeMCU to write. It will send Lua script as it is to NodeMCU to get execute.
In Arduino IDE
when we write and compile code, ESP8266 toolchain in background creates binary
firmware file of code we wrote. And when we upload it to NodeMCU then it will
flash all NodeMCU firmware with newly generated binary firmware code. In fact,
it writes the complete firmware.
That’s the reason
why NodeMCU not accept further Lua scripts/code after it is getting flashed by
Arduino IDE. After getting flashed by Arduino sketch/code it will be no more
Lua interpreter and we got error if we try to upload Lua scripts. To again
start with Lua script, we need to flash it with NodeMCU firmware.
Since Arduino IDE
compile and upload/writes complete firmware, it takes more time than ESPlorer
IDE.
Comments
Post a Comment