Sunday 17 January 2016

Blink LED on NodeMcu DevKit ver1.0 / ESP8266 12E, Lua, WIFI, IOT,

Introduction:

Wi-Fi is an essential bit of kit for any Internet of Things (IoT) DIY projects, but our favorite Arduino doesn’t come with Wi-Fi, and adding in a Wi-Fi shield can increase the costs substantially.
Meet the Arduino Killer: ESP8266 (also known as NodeMCU) was originally marketed as a low cost Wi-Fi add-on for Arduino boards, until the hacker community realized you could cut the Arduino out of the equation entirely.



In less than a year, the ESP8266 has rocketed in popularity, and is now so well supported and developed that if you’re currently using Arduino, you need to stand up and take note.
There’s quite a few models of ESP8266 around now, but we recommend this one: ESP-12E (also known as NodeMCU 2.0). This board includes the serial driver needed to program the chip, and has a built-in power regulator, as well as lots of IO pins.This NodeMCU Devkit is available from our eBay Store.

Getting Started with ESP8266-12E:

Using Micro usb to standard usb cable Connect  ESP8266-12E  to your PC. we are using windows 7.

Please wait and allow the windows to install the USB driver as shown below.


NodeMCU is connected to COM5 . This can also be verified from Device Manager.



Method 1: Arduino IDE

This is the easier of the two methods requiring only Arduino IDE

  • Install the latest Arduino from the Arduino website.
  • Start Arduino and open Preferences window.
  • Enter http://arduino.esp8266.com/stable/package_esp8266com_index.json into Additional Board Manager URLs field. You can add multiple URLs, separating them with commas.
  • Open Boards Manager from Tools > Board menu and install esp8266 platform 

Selecting the NodeMCU baord from Tools Menu





Restart Arduino IDE and select blink Example for ESP8266 and upload.



Results:




Method 2: Flashing the Firmware:

This Method Involves flashing the firmware and then uploading the lua code via ESPlorer.

download the latest firmware from the following link

or the direct link

we are using the firmware: nodemcu_float_0.9.6-dev_20150704.bin

Download and run the flasher software from github

we are using the 64 bit version of the flasher.

Select the firmware file by clicking on the gear icon.



Then press the Flash(F) button to start the firmware flash process.




Once finished  press the reset button on the NodeMCU.

Running Blink led program:

Now download and run the ESPlorer IDE from the following link
connect to NodeMCU by pressing the Open button on the top of right panel.


After successful connection  some message and a prompt is displayed.


Now we are ready to upload our first program "Blink.lua" to NodeMCU. Press [Save to ESP] button to upload, the red led on ESP will start flashing with 1 sec interval. Please note 1,000,000 us = 1 sec.

"Blink.lua" code:

              while 1 do
              gpio.write(0,gpio.HIGH)
              tmr.delay(1000000)
              gpio.write(0,gpio.LOW)
              tmr.delay(1000000)

              end



Results:





WIFI Scanner:


Setup:


OLED -> NodeMcu

-SDA     ->   D5
-SCL      ->   D6
-VCC      ->  3.3V
-GND     ->   GND

Code:


wifi.setmode(wifi.STATION) --Set mode to STATION so he chip can receive the SSID broadcast
function init_OLED(sda,scl) --Set up the u8glib lib
     sla = 0x3c
     i2c.setup(0, sda, scl, i2c.SLOW)
     disp = u8g.ssd1306_128x64_i2c(sla)
     disp:setFont(u8g.font_6x10)
     disp:setFontRefHeightExtendedText()
     disp:setDefaultForegroundColor()
     disp:setFontPosTop()
end
init_OLED(5,6) --Run setting up
tmr.alarm(0,3000,1,function() --A timer, which used to run the following program 
    wifi.sta.getap(function(t) 
         disp:firstPage()
         repeat
            lines = 0
            for k,v in pairs(t) do
                disp:drawStr(0,lines * 11,k.." "..v:sub(3,5).."dbi") --Print the data out
                lines = lines + 1
            end
        until disp:nextPage() == false
    end)
end)

Results:





3 comments:

  1. Hello; just doing my first getting started (thanks for the prompt eBay dispatch). I'm stuck with the IDE telling me "Connect to MCU" but not getting any command prompt?

    Still searching but any suggestions. No errors report in log files?

    Matthew

    ReplyDelete
  2. hi, check in windows setting which port NodeMCU is connected to?
    then restart the ESPlorer so that it can detect it.
    I assume you were able to flash the firmware successfuly?
    thnx

    ReplyDelete
    Replies
    1. Yes firmware was successful; I have since managed to connect via putty and get a command prompt at 9600 baud... will need to look into further. It was running Java8.

      Thanks for the quick response though!

      Delete