Friday 29 July 2016

Hello World with NodeMcu using Lua

I recently come across a another Prototyping Board named as NodeMCU.
From its Official Website Node MCU is
An open-source firmware and development kit that helps you to prototype your IOT product within a few Lua script lines

It runs on Low Cost ESP8266 SoC from Espressif.. and Open Source NodeMCU firmware. We can Program this module using lua,micropython and c. 

First thing to do after you gets your hands on your nodeMCU hardware is to flash new firmware to it..  there are still people working on it.. so it is best to keep it updated.

To flash firmware you need(I am assuming you have nodeMCU Dev Kit with you not generic esp8266 Module)

1.  cp2102 usb to Serial Bridge Drivers  : Download from https://www.pololu.com/docs/0J7/all
2.  Node MCU firmware :  Go to https://github.com/nodemcu/nodemcu-firmware/releases
and Download the nodemcu_float or nodemcu_int

3. NodeMCU Flasher : Download it from https://github.com/nodemcu/nodemcu-flasher
 
 Download the win32 or win64 depending on your system

4.ESPlorer IDE to Program Node Mcu : download it from  http://esp8266.ru/esplorer/ and make sure you have java installed in your system


step 1: Install the cp2102 Driver
step 2: Connect the your nodeMCU board to your PC and note down the COM port
step 3: open the NodeMCU flasher Downloaded earlier
ans select the nodeMCU COM port under operation Menu

step 4: under the config tab select the downloaded nodeMCU firmware by clicking little gear as shown in the image
step 5: go back to the Operation Menu and Click on the Flash Button.. 
You can see the Progress below or go to the log for Messages..

You can see the green tick mark in the NODEMCU TEAM when it us successfully updated the firmware.

step 6: close the flasher application and remove and reinsert power to nodeMCU

Now.. your nodeMCU is ready to accept commands from you

Simple LED On and Off using lua
there are many loaders available for nodeMCU.. i am using ESPlorer which runs on Java

Open the ESPlorar.jar executable program in previously downloaded package

 
 Select the COM port and click Open You can now see that Lower send Button is Activated..

You can send the commands to the nodeMCU using send followed by Command.

The command used are 
1. gpio.mode(pin,mode) : used to set the mode for GPIO pin

mode can be specified as input or output using gpio.INPUT or gpio.OUTPUT

2.gpio.write(pin,value) : used to send low or high value to the pin

value can be specified as gpio.LOW or gpio.HIGH for low or HIGH values

I will use pin 7 (D7), Connect the Anode to D7 and cathode to ground with help of breadboard 

and send the following commands to the nodeMCU one by one (anything followed by " -- " is Comment )

gpio.mode(7,gpio.OUTPUT)
gpio.write(7,gpio.HIGH) -- LED is ON 
gpio.write(7,gpio.LOW) -- LED is OFF

That's it for Now...

No comments:

Post a Comment