-->
اعلان

Getting Started with ESP8266 NodeMcu v3 Lua with WiFi

Getting Started with ESP8266 NodeMcu v3 Lua with WiFi

    Getting Started with ESP8266 NodeMcu v3 Lua with WiFi

    NodeMcu is an ESP8266 based platform for creating various Internet of Things (IoT) devices. The module can send and receive information to a local network or to the Internet using Wi-Fi. An inexpensive module is often used to create smart home systems or Arduino robots that are remotely controlled. In this article we will look at the description of the board, the difference of versions and pinout of the latest version of the Esp8266 NodeMcu v3 module We also briefly consider the language of Lua, in which you need to write programs for NodeMcu.



    Description ESP8266 NodeMcu v3



    Technical characteristics of the module:
    • Supports Wi-Fi protocol 802.11 b / g / n;
    • Supported Wi-Fi modes - access point, client;
    • Input voltage 3.7V - 20 V;
    • Operating voltage 3V-3.6V;
    • Maximum current 220mA;
    • Built-in TCP / IP stack;
    • Operating temperature range from -40 ° C to 125 ° C;
    • 80 MHz, 32-bit processor;
    • Wake up time and send packets 22ms;
    • Built-in TR switch and PLL;
    • Availability of power amplifiers, regulators, power management systems.
    There are several generations of NodeMcu boards - V1 (version 0.9), V2 (version 1.0) and V3 (version 1.0). Designations V1, V2, V3 are used when selling in online stores. There is often confusion in the boards - for example, V3 is externally identical to V2. Also, all the boards work on the open-source principle, so any company can produce them. But Amica, DOIT and LoLin / Wemos are currently producing NodeMcu boards.

    Differences from other modifications

    Generation boards V1 and V2 are easy to distinguish - they have a different size. Also, the second generation is equipped with an improved modification of the ESP-12 chip and 4 MB of flash memory. The first version, outdated, is made in the form of a bright yellow platform. It is inconvenient to use it, since it covers 10 outputs of the breadboard. The second generation motherboard is made with the correction of this flaw - it has become narrower, the outputs are well suited to the board contacts. V3 cards look nothing different from V2, they have a more reliable USB output. The V3 is manufactured by LoLin, from the differences from the previous one, it can be noted that one of the two reserved outputs is used for additional ground, and the second for USB power supply. Also, the board has a larger size than previous types.


    Where to buy modules NodeMCU and ESP8266

    There are many fairly inexpensive modifications of motherboards based on the ESP8266 available today.


    Power Module NodeMcu

    You can apply power to the module in several ways:
    • Serve 5-18 V through the contact Vin;
    • 5V via USB connector or VUSB contact;
    • 3.3V via pin 3V.

    Advantages of NodeMcu v3

    • The presence of a UART-USB interface with a micro USB connector makes it easy to connect the board to the computer.
    • 4 MB flash memory available.
    • Ability to update the firmware via USB.
    • Ability to create scripts on the LUA and save them in the file system.

    Disadvantages of the NodeMcu module

    The main disadvantage is the ability to execute only LUA scripts located in RAM. This type of memory is small, the volume is only 20 KB, so writing large scripts causes a number of difficulties. First of all, the whole algorithm will have to be divided into linear blocks. These blocks must be recorded in separate system files. All these modules are executed using the dofile statement.
    When writing, you need to follow the rule - when exchanging data between modules, you need to use global variables, and when calculating inside modules - local ones. It is also important to call the collectgarbage (garbage collector) function at the end of each written script.

    Pinout NodeMcu v3

    The V3 module has 11 general-purpose I / O pins. In addition, some of the findings have additional features:
    • D1-D10 - conclusions with pulse width modulation;
    • D1, D2– outputs for I²C / TWI interface;
    • D5 – D8 - outputs for the SPI interface;
    • D9, D10 - UART;
    • A0 - input from the ADC.

    onnecting NodeMCU to computer

    To start working with NodeMcu you need to connect the board to the computer. The first step is to install the CP2102 driver and open the Arduino IDE. Then you need to find in the "File" - "Settings" and in the "additional links for the card manager" window insert the link http://arduino.esp8266.com/versions/2.3.0/package_esp8266com_index.json .
    After that, in the menu “documents” - “board” “board manager” select “esp8266” and install the latest version. After the done actions in the menu "tools" - "board" you need to find NodeMCU.
    After all the necessary data has been installed and copied, you can start working.

    An example of connecting the LED to the NodeMCU

    The schematic diagram of the connection is shown in the figure.
    The final layout of the layout is as follows:
    The board itself is powered by 3.3 V, so you need to use a resistor to connect the LED. In this example, for a red LED, a 65 Ohm resistor is taken.
    A photodiode is connected to the board in a similar way:
    The NodeMCU board can also be used for IR control. To control, you need a remote control with an IR receiver and the platform itself. The infrared receiver is connected according to the scheme below:
    Firmware for esp8266 NodeMcu


    The platform is loaded with the standard Node MCU firmware, which has a built-in Lua interpreter. With the help of Lua commands you can perform the following actions:
    • Connect to a Wi-Fi access point;
    • Work as a Wi-Fi access point;
    • Switch to deep sleep mode to reduce energy consumption;
    • Turning on or off the LED output GPIO16;
    • Perform various operations with files in flash memory;
    • Search for open Wi-Fi network, connect to it;
    • Output MAC address;
    • Manage user timers.
    For programming NodeMCU, you can use the Arduino IDE or the SDK - ESPlorer software development kit. This complex has a number of differences:
    • It can work on many different platforms;
    • It has support for several open files;
    • Allows you to highlight the Lua language code;
    • The ability to send smart files;
    • Ability to support multiple types of firmware at the same time.
    To ensure correct and stable operation, you need to update the firmware to the latest version. There are several ways to upgrade - cloud service, Docker Image and compiling on Linux. Each of these methods has its own advantages and disadvantages. The simplest and most understandable is the first method.

    Collecting firmware in the cloud service

    Cloud service has a simple and convenient interface. Work begins by entering an email. Next, you will be asked to choose the type of firmware - stable firmware or tested. The first is used to train and create a large number of objects, so it is recommended to choose it. The next step is to connect the necessary modules. By default, several basic items are already recorded, the rest should be included only as needed. Then select additional options. Among them, there is support for FatFS to read the sd card or enable debug mode.
    After the start of the assembly will receive a letter in the mail, indicating the start of the launch process. After some time, the second letter will come - you will be asked to choose the version of float (fractional numbers) or integer (integers).
    After clicking on the link, you will need to download the bin file and place it in Resources - Binaries. There will be located the nodemcu_integer_0.9.5_20150318.bin file to be deleted. As a result, the contents of the folder will look like this.

    Node Mcu Firmware Update

    For proper and stable operation of the board, it is necessary to overwrite esp_init_data_default.bin. You can download it on the official website. The desired file must be placed again in the system for the NodeMCU Flasher firmware along the path Resources - Binaries, after removing the old file from it.
    Then you can connect NodeMCU and proceed with the update. First you need to change the settings - in the NodeMCU Flasher in the Config tab, you need to select the file of the assembled firmware instead of INTERNAL: // NODEMCU.
    Leave the rest unchanged, go to Operations and click Flash. As soon as the firmware is finished, you need to go to Config again and specify the path esp_init_data_default.bin in the first line. It also additionally indicates the address where to move this file. For the NodeMCU module, select the address 0x3FC000. After that, you need to return to Operations again and click Flash.
    After that, you need to reformat the entire file system of the board. To do this, you need to run ESPlorer, be sure to set the exchange rate 115200 and restart NodeMCU. After all the above actions, there will be a new firmware version. The debug board is completely reflashed and ready to go.

    Lua language brief

    Lua has a simple syntax and powerful data description constructs that are based on arrays and extensible semantics. This powerful programming language is used to create software that extends various games. Unlike other languages, Lua has more flexible and more powerful constructs.

    LED flashing on Lua

    You can consider the simplest scheme - flashing LED. This example will help you learn how to work with GPIO contacts. The LED must be connected as shown in the diagram.
    Then you need to write the following sketch to the left ESPlorer window:


    pin_number = 1
    gpio.mode (pin_number, gpio.OUTPUT) // set the operating mode to exit
    gpio.write (pin_number, gpio.HIGH) // high level setting
    gpio.write (pin_number, gpio.LOW) // set low
    gpio.serout (1, gpio.HIGH, {+990000.990000}, 10, 1) // set the flashing of the LED 10 times
    After you need to save the script with the name init.lua. Immediately after that, the automatic loading of the written code to the debug board and its execution will begin. If the operation is successful, the debug board will flash with a LED.
    It is important to note that the board independently executes the script, the connection to the computer is only needed for power supply.

    Unknown
    @Posted by
    writer and blogger, founder of AZ Tronics .

    Post a Comment