Follow Us
Facebook Twitter Google Plus Linkedin Instagram YouTube

Quick Start Guide for Node MCU Programming in Lua

PREREQUISITES:

  1. Download and Install CP2102 usb to uart driver
  2. Download and Install NodeMCU Flasher
  3. Download and install JAVA(SE version 7 and above)
  4. Download ESPlorer IDE

STEP 1: FLASHING NODEMCU FIRMWARE

Open the NodeMCU Flasher by following the below path

nodemcu-flasher-master>>Win64>>Release>>ESP8266Flasher

Now connect NodeMCU to computer using usb.

Select the appropriate COM Port in ESP8266 Flasher. Now click on Flash Option. This will flash the NodeMCU firmware on NodeMCU board which is already available in Flasher software.

If the flashing does not start try to disconnect NodeMCU from computer and connect again.

STEP 2:  SETTING UP ESPLORER IDE FOR NODEMCU

Open the ESPlorer IDE by clicking on ESPlorer executable jar file

  1. Click on Refresher Button to See the available COM Port
  2. Choose appropriate COM Port
  3. Click on Open Option which will turn close and IDE will be connected with NodeMCU through COM Port
  4. Press Reset button on NodeMCU.

After this you should get Output as shown in below picture.

1

Till this part you have successfully done the Initial setup for NodeMCU lua programming.

STEP 3: RUNNING FIRST LUA PROGRAM ON NODEMCU

Now let’s start with some coding. In this step we will interface an LED with NodeMCU and write a Lua code to blink it.

I have interfaced LED with pin D6 as shown in below figure.

untitled-sketch_bb

Here is the ready code to blink led connected to pin D4.


LED_PIN = 4
val=0
gpio.mode(LED_PIN, gpio.OUTPUT)
tmr.alarm(0, 500, 1, function ()
if val==0 then
gpio.write(LED_PIN, gpio.HIGH)
val=1
else
gpio.write(LED_PIN, gpio.LOW)
val=0
end
end)

Simply copy the code and paste in ESPlorer. Click on save button and save it as init.lua. Then click on Save to ESP button and enjoy the blinking.

Congratulations..! You have successfully run first lua project on NodeMCU.

Note that init.lua is the program which runs as a part of NodeMCU boot process whenever it resets. If you save program with some other name the program will not be executed after reset.

Leave a Reply

Your email address will not be published.Required fields are marked *

Bitnami