ESP8266 have been the latest hits in the electronics hobbyist world. Probably the next great thing after Arduino. Imagine having a 32bits MCU with built in WiFi and bunch of digital IO, and an A/D converter too, at US$3 only? Why not!
If you need more info on ESP8266, just head here:
In short, ESP8266 came loaded with the simple modem like AT firmware. You can connect the ESP8266 to an arduino nano and connect to the internet.
Using this configuration, I created an internet clock with daylight saving incorporated. But that will be a separate post altogether, and I will do it later.
From the diagram above, you may ask why the 3.3V ESP8266 is connected directly to the Arduino Nano's IO without any level converter, as the Arduino Nano is a 5V device? Well, the ESP8266 is robust enough to handle that, so I just skip the level converter or even the resistors. And just to let everyone know, I did accidentally connected the ESP8266 to 5V power supply and it seem to survive that!
The ESP8266 came with a non industry standard 2mm pitch, thus making it difficult to use it on breadboard as is. So here is what I did:
For the ESP-03/12 that came with the 2mm pitch pin, I used 28pin IC socket, solder copper wires into the socket (like to top picture) and then solder the wires to the module. As for the ESP-01, I use SIL header with long pins, bent the pins as per the above picture and it is ready to be used on the breadboard.
If you notice, I also solder on the 3.3V regulator and capacitor onto the socket also. Having 3.3V regulator right on the module really solve my problem of having voltage drop on the whiteboard.
OK, now on the software. As mentioned above, the module came with AT firmware, but the module can also be re-flash with your own firmware. One of the most popular alternative firmware is the NodeMCU LUA interpreter. By having this interpreter, this module literally can operate on its own without external MCU like the ATMEGA328 on the Arduino. So we can use it just like the Arduino, except with built in WiFi.
To know about the NodeMCU firmware, please go here:
To interact with the ESP8266 LUA intepreter, we need to use the serial port via USB serial converter.
And again, I just hook up the USB serial converter directly to the ESP8266 without any level converter. So far so good. And you may ask, can the the ESP8266 LUA scripts be interacted wirelessly? That was exactly the question I had before. I looked around the internet but could not find a readily available tutorial on how to accomplish that. So that is why I am writing this blog now, to share my experience to make the ESP8266 remotely programmable, free from the USB serial converter. You can now install this little module somewhere remote (but within your wireless network), and upload/execute the LUA code wirelessly.
OK, here is the step:
1.Install NodeMCU into ESP8266 using NodeMCU flasher (if you haven't done so).
2.Download “Lua Uploader” by Hari Wiguna or the "ESPlorer" by 4refr0nt (thanks guys!)
3.Install "init.lua" into ESP8266 using USB serial port to ESP8266 (Edit your SSID and password before uploading into ESP8266). Or you can just use your own "init.lua" that will connect you to the network and execute a telnet program upon ESP8266 start-up.
SSID = "xxxxxxx"
APPWD = "yyyyyyy"
CMDFILE = "telnet.lua" -- File that is executed after connection
-- Some control variables
wifiTrys = 0 -- Counter of trys to connect to wifi
NUMWIFITRYS = 200 -- Maximum number of WIFI Testings while waiting for connection
-- Change the code of this function that it calls your code.
print("Connected to WIFI!")
print("IP Address: " .. wifi.sta.getip())
-- Call our command file every minute.
tmr.alarm(0, 10000, 1, function() dofile(CMDFILE) end )
if ( wifiTrys > NUMWIFITRYS ) then
print("Sorry. Not able to connect")
ipAddr = wifi.sta.getip()
if ( ( ipAddr ~= nil ) and ( ipAddr ~= "0.0.0.0" ) )then
-- lauch() -- Cannot call directly the function from here the timer... NodeMcu crashes...
tmr.alarm( 1 , 500 , 0 , launch )
-- Reset alarm again
tmr.alarm( 0 , 2500 , 0 , checkWIFI)
print("Checking WIFI..." .. wifiTrys)
wifiTrys = wifiTrys + 1
print("-- Starting up! ")
-- Lets see if we are already connected by getting the IP
ipAddr = wifi.sta.getip()
if ( ( ipAddr == nil ) or ( ipAddr == "0.0.0.0" ) ) then
-- We aren't connected, so let's connect
wifi.setmode( wifi.STATION )
wifi.sta.config( SSID , APPWD)
print("Waiting for connection")
tmr.alarm( 0 , 2500 , 0 , checkWIFI ) -- Call checkWIFI 2.5S in the future.
-- We are connected, so just run the launch code.
-- Drop through here to let NodeMcu run
4. Install “telnet.lua” into ESP8266 using USB serial port to ESP8266. This is the program that actually echo ESP8266 UART input/output to the TCP port 8080 (and the ESP8266 UART still work).
print("====Wicon, a LUA console over wifi.==========")
print("Author: firstname.lastname@example.org. copyright&GPL V2.")
print("Last modified 2014-11-19. V0.2")
print("Wicon Server starting ......")
print("Wifi AP connected. Wicon IP:")
print("Wifi console connected.")
if (conn~=nil) then
conn:on("receive", function(conn, pl)
if (conn==nil) then
print("conn is nil.")
print("Wicon Server running at :8080")
print("===Now,Using xcon_tcp logon and input LUA.====")
tmr.alarm(0, 1000, 1, function()
if wifi.sta.getip()=="0.0.0.0" then
print("Connect AP, Waiting...")
Or you can download this "telnet.lua" from https://github.com/nodemcu/nodemcu-firmware/blob/master/examples/telnet.lua
Thanks to Openthings for this code.
5. Download and install Etherlogic virtual serial port www.etherlogic.com
This is the window program that actually created a virtual COM port on your window PC where the LUA loader will talk to as if it is a local COM port.
6. Setup virtual serial port for “Connector” and “Bridge”. You can use any unused COM port name that is not currently assigned to any local ports on your PC.
Below is how to create the "connector" COM1
And below is where the TCP client connection is made. You need to find out your ESP8266's IP address for below step (use wifi.sta.getip() ).
192.168.0.105 is my ESP8266 IP address, and 8080 is the port specified in the "telnet.lua".
7. Start the virtual serial port emulation (and now you can disconnect the USB serial port from the ESP if you want to).
8. Fire-up your favorite LUA loader and select the emulated serial port (ie COM1 as below):
If you want to use the other LUA loader like the ESPlorer, make sure that you select the "Dumb" mode.
That's it! Now you can start using the ESP8266 with the LUA console without any wire attached.
This workaround will be temporary measure until we have someone created a LUA loader that can talk directly to the TCP port.