node mcu
node mcu
Over the internet i found that ESP8266 Arduino module, version 01, is sold in two or more
versions, which at first glance seem quite the same. After buying both of them i saw that
there
is a difference in size of the flash memory. You may encounter issues while flashing if you
don’t make the proper settings according to board specifications.
Although the board default has 2 available GPIOs, you can do some workarounds and use
other MCU available pins if you have the proper soldering tools. I managed to use GPIO 16
in
order to wake up the device after DEEP SLEEP mode (explained later in SLEEP MODES).
xxv
4.3.2 Module pin description (pin out)
Pins are arranged in two rows, having 4 on each row. Some models have pin description on
the PCB, which make it simple. On the top row you can find following pins from the left to
the right:
1. GND (Ground from power supply)
2. GPIO2 (Digital I/O programmable)
3. GPIO0 (Digital I/O programmable, also used for BOOT modes)
4. RX – UART Receiving channel
On the bottom (second row) you can find:
1. TX – UART Transmitting channel
2. CH_PD (enable/power down, must be pulled to 3.3v directly or via resistor)
3. REST – reset, must be pulled to 3.3v)
4. VCC -3.3v power supply
Power supply and current consumption
All esp8266 Arduino compatible modules must be powered with DC current from any kind of
source that can deliver stable 3.3V and at least 250mA. Also logic signal is rated at 3.3v and
the RX channel should be protected by a 3.3v divisor step-down. You should be careful when
using this module with Arduino or other boards which supplies 5v, because this module
usually do not come with overpower protection and can be easily destroyed.
The most basic way to use the ESP8266 module is to use serial commands, as the chip is
basically a WiFi/Serial
transceiver. However, this is not convenient. What we recommend is using the very cool
Arduino ESP8266 project,
which is a modified version of the Arduino IDE that you need to install on your computer.
This makes it very
convenient to use the ESP8266 chip as we will be using the well-known Arduino IDE.
Following the below step to
install ESP8266 library to work in Arduino IDE environment.
3.1 Install the Arduino IDE 1.6.4 or greater
Download Arduino IDE from Arduino.cc (1.6.4 or greater) - don't use 1.6.2 or lower version!
You can use your
existing IDE if you have already installed it.
You can also try downloading the ready-to-go package from the ESP8266-Arduino project, if
the proxy is giving you
problems.
3.2 Install the ESP8266 Board Package
Enter http://arduino.esp8266.com/stable/package_esp8266com_index.json into Additional
Board Manager URLs
field in the Arduino v1.6.4+ preferences.
Scroll down to ‘ esp8266 by ESP8266 Community ’ and click “Install” button to install the
ESP8266 library package.
Once installation completed, close and re-open Arduino IDE for ESP8266 library to take
effect.
3.3 Setup ESP8266 Support
When you've restarted Arduino IDE, select ‘Generic ESP8266 Module’ from the ‘Tools’ ->
‘Board:’ dropdown menu.
3.4 Blink Test
https://github.com/nodemcu/nodemcu-devkit/tree/master/Drivers
We'll begin with the simple blink test.
Enter this into the sketch window (and save since you'll have to). Connect a LED as shown in
Figure3-1.
void setup() {
pinMode(5, OUTPUT); // GPIO05, Digital Pin D1
}
void loop() {
digitalWrite(5, HIGH);
delay(900);
digitalWrite(5, LOW);
delay(500);
}
Now you'll need to put the board into bootload mode. You'll have to do this before each
upload. There is no timeout
for bootload mode, so you don't have to rush!
• Hold down the ‘Flash’ button.
• While holding down ‘ Flash’, press the ‘RST’ button.
• Release ‘RST’, then release ‘Flash’
When you release the ‘RST’ button, the blue indication will blink once, this means its ready
to bootload.
The sketch will start immediately - you'll see the LED blinking. Hooray!
3.5 Connecting via WiFi
OK once you've got the LED blinking, let’s go straight to the fun part, connecting to a
webserver. Create a new sketch
with this code:
Don’t forget to update:
const char* ssid = "yourssid";
const char* password = "yourpassword";
to your WiFi access point and password, then upload the same way: get into bootload mode,
then upload code via
IDE.
4. Flashing NodeMCU Firmware on the ESP8266 using Windows
Why flashing your ESP8266 module with NodeMCU?
NodeMCU is a firmware that allows you to program the ESP8266 modules with LUA script.
And you’ll find it very
similar to the way you program your Arduino. With just a few lines of code you can establish
a WiFi connection,
control the ESP8266 GPIOs, turning your ESP8266 into a web server and a lot more.
In this tutorial we are going to use another ESP8266 module with pin header adapter board
which is breadboard
friendly.
Execute the “ESPlorer.jar” file and the ESPlorer IDE should open after a few seconds (the
“ESPlorer.jar” file is what
you need to open every time you want to work with the ESPlorer IDE).
Note: If you’re on Mac OS X or Linux you simply use this command line in your terminal to
run the ESPlorer: sudo
java –jar ESPlorer.jar.
When the ESPlorer first opens, that’s what you should see:
Here’s a rundown of the features the ESPlorer IDE includes:
• Syntax highlighting LUA and Python code.
• Code editor color themes: default, dark, Eclipse, IDEA, Visual Studio.
• Undo/Redo editors features.
• Code Autocomplete (Ctrl+Space).
• Smart send data to ESP8266 (without dumb send with fixed line delay), check correct
answer from ESP8266
after every lines.
• Code snippets.
• Detailed logging.
• And a lot more…
The ESPlorer IDE has a couple of main sections, let’s break it down each one.
In the top left corner you can see all the regular options that you find in any software. Create
a New file, Open a new
file, Save file, Save file as, Undo, Redo, etc.
In the top right corner you have all the options you need to establish a serial communication
(you’re going to learn
how to use them later in this Guide).
5.2 Schematics
To upload code to your ESP8266, you should connect your ESP8266 to your PL2303HX
USB-UART Programming Cable
like the figure below:
The next step is to save your code to your ESP8266!
At the left bottom corner click the button “Save to ESP”.
In your output window, it should start showing exactly which commands are being sent to
your ESP8266 and it should
look similar to the Figure below.
Note: If you want to delete your “init.lua” file, you can do that easily. Simply type
file.remove(“init.lua”) and press
the button “Send” (see Figure above). Or you can type the command file.format() to remove
all the files saved in your
ESP8266. You can type any commands and send them to your ESP8266 through that
window.
After uploading your code to your ESP8266, unplug your ESP8266 from your computer and
power up the ESP8288
module.
6. NodeMCU GPIO for Lua
The GPIO(General Purpose Input/Output) allows us to access to pins of ESP8266 , all the
pins of ESP8266 accessed
using the command GPIO, all the access is based on the I/O index number on the NoddMCU
dev kits, not the internal
GPIO pin, for example, the pin ‘D7’ on the NodeMCU dev kit is mapped to the internal
GPIO pin 13, if you want to
turn ‘High’ or ‘Low’ that particular pin you need to called the pin number ‘7’, not the internal
GPIO of the pin. When
you are programming with generic ESP8266 this confusion will arise which pin needs to be
called during
programming, if you are using NodeMCU devkit, it has come prepared for working with Lua
interpreter which can
easily program by looking the pin names associated on the Lua board. If you are using
generic ESP8266 device or any
other vendor boards please refer to the table below to know which IO index is associated to
the internal GPIO of
ESP8266.
D0 or GPIO16 can be used only as a read and write pin, no other options like PWM/I2C are
supported by
this pin.
In our example in chapter 5 on blinking the blue LED, the blue LED in connected to GPIO2,
it is defined as
Pin4 (D4) in Lua script.
7. Web Resources:
• ESP8266 Lua Nodemcu WIFI Module
• ESP8266 Breadboard Friendly Module
• ESP8266 Remote Serial WIFI Module
• PL2303HX USB-UART Converter Cable
This mod based on the D0 pi Please ref NODE M U is an 266 from E CU" by de cripting lan
266. It uses U was crea egan produc X106 core,w 8266 is a lo d by Shangh Pin confi dule
provide the I/O ind n on the dev fer to the be MCU open so Espressif, a efault refer nguage. It
is s many open ated shortly ction of the widely used ow-cost Wi hai-based Ch Figure 3
guration es access to dex number v kit is map elow GPIO Figure ource IoT pl and hardwa rs
to the f s based on t n source pro y after the e ESP8266. d in IoT app -Fi microch hinese manu
3: NODE M of NODE o the GPIO on the Nod pped to the i pin maps fo e 2: NODE latform. I
are which firmware ra the eLua pr ojects, such ESP8266 c The ESP82 plications hip with fu
ufacturer, E MCU with in E MCU de (General P deMCU dev internal GP or the index MCU
Deve It include is based ather than roject, and b as lua-cjson came out. O 266 is a Wi ull
TCP/IP Espressif Sy nbuilt wifi m evelopme Purpose Inpu v kits, not t IO pin 16. x↔gpio
map elopment bo es firmwa on the ES the dev k built on the n,and spiffs On Decemb i-Fi
SoC int stack and m stems. module nt board ut/Output) the internal pping.
3.2.2 Installation of Node MCU & Coding
Mostly these days devices download and install drivers on their own, automatically.
Windows
doesn’t know how to talk to the USB driver on the Node MCU so it can’t figure out that the
board is a Node MCU and proceed normally.