Sunday 15 July 2018

INTERFACING NODEMCU ESP 8266 with LUA Programming Language

Standard

NodeMCU ESP8266

Image result for lolin nodemcu v3 pinout

Image result for esp8266 architecture

What is ESP8266?

The Chips

The ESP8266 series, or family, of Wi-Fi chips is produced by Espressif Systems, a fabless semiconductor company operating out of Shanghai, China. The ESP8266 series presently includes the ESP8266EX and ESP8285 chips.
ESP8266EX (simply referred to as ESP8266) is a system-on-chip (SoC) which integrates a 32-bit Tensilica microcontroller, standard digital peripheral interfaces, antenna switches, RF balun, power amplifier, low noise receive amplifier, filters and power management modules into a small package. It provides capabilities for 2.4 GHz Wi-Fi (802.11 b/g/n, supporting WPA/WPA2), general-purpose input/output (16 GPIO), Inter-Integrated Circuit (I²C), analog-to-digital conversion (10-bit ADC), Serial Peripheral Interface (SPI), I²S interfaces with DMA (sharing pins with GPIO), UART (on dedicated pins, plus a transmit-only UART can be enabled on GPIO2), and pulse-width modulation (PWM). The processor core, called "L106" by Espressif, is based on Tensilica's Diamond Standard 106Micro 32-bit processor controller core and runs at 80 MHz (or overclocked to 160 MHz). It has a 64 KiB boot ROM, 32 KiB instruction RAM, and 80 KiB user data RAM. (Also, 32  KiB instruction cache RAM and 16 KiB ETS system data RAM.) External flash memory can be accessed through SPI. The silicon chip itself is housed within a 5 mm × 5 mm Quad Flat No-Leads package with 33 connection pads — 8 pads along each side and one large thermal/ground pad in the center.
ESP8285 is a variation of ESP8266 with 1 MiB of embedded flash memory.
Now, if you're looking for something a bit more capable, check out ESP32 — it has more memory, more GPIO, hardware encryption, Bluetooth, and all sorts of other additional bells and whistles.




The MCU Architecture and Pinouts

Image result for esp8266 architecture

PINOUTS:


Image result for esp8266 pinouts

Image result for esp8266 pinouts


Related image


The Modules

Vendors have consequently created a multitude of compact printed circuit board modules based around the ESP8266 chip. Some of these modules have specific identifiers, including monikers such as "ESP-WROOM-02" and and "ESP-01" through "ESP-14"; while other modules might be ill-labeled and merely referred to by a general description — e.g., "ESP8266 Wireless Transceiver." ESP8266-based modules have demonstrated themselves as a capable, low-cost, networkable foundation for facilitating end-point IoT developments. Espressif's official modules are presently ESP-WROOM-02 and ESP-WROOM-S2. The Ai-Thinker modules are succinctly labeled ESP-01 through ESP-14. (Note: many people refer to the Ai-Thinker modules with the unofficial monikers of "ESP8266-01" through "ESP8266-14" for clarity.) See the ESP8266 article on Wikipedia for more information about popular ESP8266 modules.
  • Current models:
    ModelFlash memoryAntennaSize (mm)
    ESP-01S1 MiBPCB trace24.7 × 14.4 × 11
    ESP-01M1 MiBPCB trace18 × 18 × 2.8
    ESP-07S4 MiBI-PEX17 × 16 × 3
    ESP-08S4 MiB(None)17.6 × 16.2 × 3
    ESP-12F4 MiBPCB trace24 × 16 × 3
    ESP-12S4 MiBPCB trace24 × 16 × 3
  • Older models: ESP-01, ESP-7, ESP-08, ESP-09, ESP-10, ESP-11, ESP-12, ESP-12E, and ESP-13.
  • Discontinued models: ESP-02, ESP-03, ESP-04, ESP-05, ESP-06, and ESP-14.
  • Ai-Thinker wiki: ESP8266 section
  • Current models:
    ModelFlash memoryAntennaSize (mm)
    ESP-11 MiBCeramic & I-PEX24.5 × 14 × 3
    ESP-F4 MiBPCB trace24 × 16 × 3
    ESP-M11 MiBI-PEX15 × 12.3 × 3
    ESP-M21 MiBPCB trace20 × 12.3 × 3
    ESP-M31 MiBPCB trace26.8 × 16
    ESP-S4 MiBPCB trace24 × 16 × 3
  • ESP8285 is used in ESP-1, ESP-M1, ESP-M2, and ESP-M3.
  • Discontinued model: ESP-E.

The Development Boards/Modules

ESP8266 based development boards/modules often incorporate a surface-mount PCB module, a on-board USB-to-serial bridge, and breakout to 0.1 inch pitch connections. For example, the NodeMCU Development Kits use Ai-Thinker modules, the Adafruit Feather HUZZAH uses an Ai-Thinker ESP-12S module with a SiLabs CP2104 USB-to-serial bridge chip, and the WEMOS D1 Mini version 2.3 uses an Ai-Thinker ESP-12S module with a WinChipHead CH340G USB-to-serial bridge chip. Other development boards don't use an intermediary module and instead directly incorporate the chip itself on-board — for example, WEMOS D1 Mini Pro uses ESP8266EX and WEMOS D1 Mini Lite uses ESP8285.

Where can I learn more about it?

Forums & Chat

Readings & Resources


Software Platforms, Firmwares & Frameworks


Where can I get it?

Disclaimer: Vendors are listed for informational purposes only. Buyers should use prudence and careful judgement when ordering. Before ordering, read all product descriptions and check vendor ratings when possible. Prices listed below are approximate and do not include shipping costs. Furthermore, prices listed below may be outdated, so be diligent and check for yourself.


EXAMPLES:

Connect to the wireless network
              
print(wifi.sta.getip())
--nil
wifi.setmode(wifi.STATION)
wifi.sta.config("SSID","password")
print(wifi.sta.getip())
--192.168.18.110
              
            
Arduino like IO access
              
pin = 1
gpio.mode(pin,gpio.OUTPUT)
gpio.write(pin,gpio.HIGH)
gpio.mode(pin,gpio.INPUT)
print(gpio.read(pin))

              
            
HTTP Client
              
-- A simple http client
conn=net.createConnection(net.TCP, false) 
conn:on("receive", function(conn, pl) print(pl) end)
conn:connect(80,"121.41.33.127")
conn:send("GET / HTTP/1.1\r\nHost: www.nodemcu.com\r\n"
    .."Connection: keep-alive\r\nAccept: */*\r\n\r\n")

              
            
HTTP Server
              
-- a simple http server
srv=net.createServer(net.TCP) 
srv:listen(80,function(conn) 
    conn:on("receive",function(conn,payload) 
    print(payload) 
    conn:send("

Hello, NodeMcu.

"
) end) end)
PWM
              
function led(r,g,b) 
    pwm.setduty(1,r) 
    pwm.setduty(2,g) 
    pwm.setduty(3,b) 
end
pwm.setup(1,500,512) 
pwm.setup(2,500,512) 
pwm.setup(3,500,512)
pwm.start(1) 
pwm.start(2) 
pwm.start(3)
led(512,0,0) -- red
led(0,0,512) -- blue
              
            
Blinking Led / HELLO WORLD ! in MCU & MPU WORLD
              

lighton=0
tmr.alarm(0,1000,1,function()
if lighton==0 then 
    lighton=1 
    led(512,512,512) 
    -- 512/1024, 50% duty cycle
else 
    lighton=0 
    led(0,0,0) 
end 
end)

              
            
Bootstrap
              
--init.lua will be excuted
file.open("init.lua","w")
file.writeline([[print("Hello World!")]])
file.close()
node.restart()  -- this will restart the module.
              
            
Use timer to repeat
              
tmr.alarm(1,5000,1,function() print("alarm 1") end)
tmr.alarm(0,1000,1,function() print("alarm 0") end)
tmr.alarm(2,2000,1,function() print("alarm 2") end)
-- after sometime
tmr.stop(0)
              
            
A pure lua telnet server
              
-- a simple telnet server
s=net.createServer(net.TCP,180) 
s:listen(2323,function(c) 
    function s_output(str) 
      if(c~=nil) 
        then c:send(str) 
      end 
    end 
    node.output(s_output, 0)   
    -- re-direct output to function s_ouput.
    c:on("receive",function(c,l) 
      node.input(l)           
      --like pcall(loadstring(l)), support multiple separate lines
    end) 
    c:on("disconnection",function(c) 
      node.output(nil)        
      --unregist redirect output function, output goes to serial
    end) 
    print("Welcome to NodeMcu world.")
end)

              
            
Interfacing with sensor
              
-- read temperature with DS18B20
t=require("ds18b20")
t.setup(9)
addrs=t.addrs()
-- Total DS18B20 numbers, assume it is 2
print(table.getn(addrs))
-- The first DS18B20
print(t.read(addrs[1],t.C))
print(t.read(addrs[1],t.F))
print(t.read(addrs[1],t.K))
-- The second DS18B20
print(t.read(addrs[2],t.C))
print(t.read(addrs[2],t.F))
print(t.read(addrs[2],t.K))
-- Just read
print(t.read())
-- Just read as centigrade
print(t.read(nil,t.C))
-- Don't forget to release it after use
t = nil
ds18b20 = nil
package.loaded["ds18b20"]=nil
              
            
Source: https://cdn-images-1.medium.com/max/1388/1*_WSqG1NE4ofI_dM6eSOfuA.png
Source:https://www.google.co.in/search?q=esp8266+architecture&safe=strict&source=lnms&tbm=isch&sa=X&ved=0ahUKEwiU8rPHvaHcAhWDfysKHQ3kBwQQ_AUICigB&biw=1692&bih=873#imgrc=RP97KzgNsCC2-M:
Source: http://nodemcu.com/

3 comments:

  1. It is truly a well-researched content and excellent wording. about PCB Clone Service. I got so engaged in this material that I couldn’t wait to read. I am impressed with your work and skill. Thanks.

    ReplyDelete
  2. Amazingly helpful which you have shared here. I am impressed by the details and also it is a significant article for us. Continue imparting this sort of info, Thank you.vlsi training institutes in bangalore

    ReplyDelete
  3. You have done good work by publishing this article here.consulting firms I found this article too much informative, and also it is beneficial to enhance our knowledge. Grateful to you for sharing an article like this.

    ReplyDelete