Tag Archive: ESP8266


The ESP8266 by itself hosts a 32 bit Microcontroller on it & you can now program your ESP using Arduino IDE. Best part is that NO Arduino board is required.You can upload your code from Arduino IDE , as if you were upgrading the Firmware on ESP.

You can pretty much write any code  for an Arduino and run it on the ESP8266. Of course there is a limit to the I/O on some of the modules, but the Flash on the ESP-12E (Black) module is 4MB and the RAM is 80kB! Add to that the 80MHz 32-bit processor and you have a pretty impressive little cute Arduino.

A sample Blink example program on the ESP8266 turns out to be around 225kB, but that includes the core code.So it’s advisable to use an ESP8266 with more FLASH Memory.Generally the BLACK ones are with higher memory than the Blue ones.The new ESP12E has a Flash of whooping 4MB !!  The Arduino UNO has just 32k Flash & Mega 256k.

esp_blue_black

 

esp12e_bl_black

 

Program uploading is done at 115,200 Baud, the default for the module. But It still takes a while to upload a sketch to the module , unlike a regular Arduino.

To begin, you must install the ESP8266 board files in the Arduino IDE.

That is easy enough to do. Make sure that your Arduino IDE is latest

Open the Arduino preferences from File  —> Preferences

Image 1

 

Add the following URL to the “Additional Boards Manager URLs” seen at the bottom of Preferences Window

http://arduino.esp8266.com/stable/package_esp8266com_index.json

Image 2

 

Click OK to close the Preferences Window.

Click on TOOLS –. BOARDS—> BOARDS MANAGER

Image 4

When the Boards Manager opens, scroll to the bottom. You should see the esp8266 entry.

Select the latest version & then click on INSTALL button.

Image5

It takes a while to download & install .

 

Image 6

Once installation is over , close the IDE & start again,

Under Tools –> Boards you can now see a new list of ESP8266 Modules.

Image 7

Its time to test some example code.

While using the ESP module make sure that

Power source is 3.3v DC

CH_PD & RESET pins pulled HIGH through resistor.

You can use a development board available at

http://www.alselectro.com/wifi-esp8266-esp-12-demo-board.html

Image26

An LED is connected to GPIO4 through a resistor.

Image 22

An USB-TTL board is used to connect ESP with USB port of PC.

Rx of USB-TTL board goes to Tx of ESP board

Tx of USB-TTL goes to Rx (3.3v level) of ESP board

GND is made common.

5v of USB-TTL is connected to Vcc of ESP board.As the ESP board has a built in 3.3v regulator we can connect to 5v safely.

Connect the GPIO0 pin to GND.

IMG_20161107_080700

 

Open the Arduino IDE & select the COM port allotted to the USB-TTL board.

Other settings are done under Tools tab as seen in screenshot below :

Image23

From File —> Examples —> ESP8266 select the BLINK sketch.

As we’ve connected an LED at GPIO4 pin , change the pinMode & digitalWrite pin to 4.

Ensure that GPIO0 is connected to GND & click on UPLOAD button.

It takes a while to compile & then uploading starts.

Image25

Once the Uploading is done the LED connected at pin 4 , starts blinking.

Remember to upload another sketch, you need to ground GPIO0 and push the reset switch. The ESP8266 will be put in UPLOAD mode.

When the upload is done, the sketch will start running. If you reset with GPIO0 still grounded, the sketch will not start running because the ESP8266 will be in PROGRAMMING mode. To exit programming mode, remove the ground from GPIO0.

WATCH THIS VIDEO :

 

 

In the next post we shall see how to use the built in WIFI library in your code.

cooltext753793315   cooltext753790696

ESP8266 WIFI Module comes with an inbuilt firmware which supports serial interface and can be controlled using AT commands. Even though we can use this module to offer WiFi functionality from another micro controller ,this module is not just a simple serial to WiFi transceiver .

It is comprised of  a 32Bit processor ( 80MHz) ,  512KB SPI FLASH , 64KB SRAM ,96KB DRAM , GPIO Pins & WIFI Transceiver.

In this post I shall walk you through how to upgrade new Firmware on to the ESP module.This procedure can also be followed in case  esp8266 stopped working , or giving out some random garbage data.

Before starting upgrading I downloaded following 2 files .

http://tinyurl.com/pohvwfh

http://www.alselectro.com/files/esp8266_flasher_simple.zip

1. ESP SIMPLE FLASHER – FLASH DOWNLOAD TOOL

2. FIRMWARE latest BIN file  version 9.5.0

image2

I used a  USB – TTL converter between my ESP-01 board & PC. As the ESP device requires 200ma current which cannot be sourced from USB-TTL module , I used a separate power source 5v/1Amp adaptor followed by a 3.3v regulator ( 1117 3.3v).

Please note that while I used a separate power source for ESP module , the operation was smooth.

I connected the ESP module with USB-TTL board as per following wiring diagram :

Image 2

CH-PD is CHIP ENABLE which is directly connected to +3.3v

RST is pulled HIGH through a 2k2 resistor.A press switch is connected to GND , so that when it is pressed RST pin is grounded.

TX of ESP is connected to RX of USB-TTL module

RX is connected to TX .

Vcc is connected to +3.3v of the external Regular. GND is made common for all , i.e GND of ESP ,USB-TTL & that of 1117 regulator are ALL MADE COMMON.

GPIO0 pin is connected to GND to upload firmware.

After uploading firmware , this GPIO0 connection must be removed from GND.

The USB-TTL converter I used is built on Silicon Labs CP2102 chip which is highly reliable one.The other type available in the market is built on Prolific chip (Chinese one , not original) , which has got some issues with driver installation .

I connected the USB-TTL board to my PC & from the Device Manager I noted the Port allotted .

COM port COM9 is allotted.

Image 4

Next , I browsed to the folder where I’ve already downloaded the 2 required files , one is the simple flasher & the other one is the latest firmware to be uploaded.

On double clicking the esp8266_flasher .exe file , I got this Downloader window open

image3

I clicked on the BIN button & browsed to the location of the folder to select firmware.bin file.

Before clicking the DOWNLOAD button I changed the COM port number , where USB-TTL is connected to PC.

The default address 0x000000  is automatically displayed after COM port

image4

First time when I clicked the Download button I got “Failed to connect”   error.

This was because I’ve connected GPIO0 to GND after the power to ESP board is ON.

GPIO0 pin must be at GND level when the power is initially provided to the ESP module.

image5

Second time when I clicked on the Download button , Writing started  but abruptly failed .

image6

You can see the “Failed to write to target Flash” message in the screenshot below .

image7

After repeated trials I finally found that , connecting 100uf capacitor between Vcc & Gnd

solved the problem.

image8

Finally I hit the Download button and waited for the flashing process to complete. The STATUS BLUE LED blinked fast while the uploading was going on.

“ Failed to leave Flash mode “ message after 99% writing ,does not affect the flashing process in any way and can be ignored.

After the firmware flashing, ESP8266 module settings changed. The default baud rate now is 9600 & can be modified using AT+CIOBAUD command.

It is even possible to cloud update ESP8266 Wi-Fi module firmware using AT+CIUPDATE command.But I suggest you not to try this cloud update , as it’s got some issues.

Now I removed GPIO0 pin from GND & pressed RESET switch & then closed the Flasher application.

I opened the terminal software Putty & selected Serial COM Port 9 & baud rate 9600.

Image 5

I typed in AT command & got an OK response from the ESP module.

AT+GMR returned the upgraded firmware version 9.5.

Image 6

Watch this support Video :

cooltext753793315     cooltext753790696

After struggling for nearly a week with MTS dongle , finally I found an excellent solution to enable PORT FORWARDING.

HUAWEI POWER FI  E8221 model dongle  is the solution I found.This dongle accepts any data SIM for internet connectivity & we can create a WIFI HOTSPOT with this dongle to connect max. of 10 devices.

Further it has got a VIRTUAL SERVER setting tab in the configuration , thus enabling Port forwarding.

There is no need of an external Router like TP-LINK (which I used with MTS , as seen in my previous post).

1

I’ve inserted a BSNL DATA SIM into the HUAWEI dongle for Internet connection.

The DEFAULT GATEWAY IP address while using Huawei is 192.168.8.1

This can also be found by opening CMD in Windows search bar & then typing the command IPCONFIG /ALL

Typing this Gateway address in the browser , you get the HUAWEI CONFIGURATION window.Here the service provider (for me BSNL ) name is displayed with connection status.

Image 1

Click on CONNECTION SETTINGS seen below the “Connected” status.

On left pane , under SECURITY tab select the VIRTUAL SERVER.

Before clicking the ADD button under VIRTUAL SERVER LIST , we’ve to configure the ESP module & start a SERVER on port 333.

Image 2

The ESP 8266 module is connected to PC through USB-TTL board & the COM port allotted in my PC is COM 48 .

I’m using PUTTY terminal software to communicate with this COM port.

Following is the screen shot on which you can see the AT commands used to connect ESP with HUAWEI on WIFI , & starting a server on port 333.

The selection of port is random.You can select any port within 65536 , except the standard ports like 80 (HTTP) ,  21 (FTP), 23 (TELNET) ,etc..

AT+CWLAP   – to list the surrounding Access Points near ESP module

AT+CWJAP=”ssid”,”password”   – to join the AP using the SSID name & its password.

AT+CIPMUX=1   — to enable Multiple connections before starting server

AT+CIPSERVER=1,333   –  to start a server on port 333

AT+CIFSR  –  displays the IP address . STAIP is the IP address we need to port forward.

Image 3

After starting the server on ESP8266 , we need to port forward under the HUAWEI configuration.

Click on the ADD button , seen under VIRTUAL SERVER LIST.

Fill in details as below :

Name  : ESP

WAN Port : 333

LAN IP   : 192.168.8.100

LAN Port  ; 333

Protocol : TCP

Status  : ON

Finally click on APPLY.

Image 4

Needless to say , you’ve to apply an INBOUND RULE on Windows Firewall settings to allow this port 333 . (check the previous post on how to do this).

The external world can contact this ESP only through the EXTERNAL IP address.To know the IP , just type in WHAT IS MY IP on Google .In my case it is 117.252.205.55

To confirm that the PORT 33 is open & listening , visit the online tool www.yougetsignal.com

You need to test this on the PC where you’ve connected the ESP module.

The external IP will be automatically displayed.You just  type in the port no. to verify.

Following screen shot shows that my port 333 is open

Image 6

Now we’re all set to contact ESP from outside World.

From a distant PC with different Internet connection , open a PUTTY terminal.

Select RAW as Connection type & type in the IP 117.252.205.55  & port no. as 333.

Following screen shot shows the PUTTY terminal which I’ve opened on a different PC with a different IP.

Image 5

On clicking OPEN button , the ESP Terminal at the other end will respond with

0,CONNECT

This means a connection established on channel 0.

Image 8

Now type in some characters on the distant PC terminal.

newip2

The ESP terminal responds with

+IPD,0,21:characters received

which indicates , it has received 21 characters on channel 0.

The screen shots with HUAWEI symbol (IP 117.252.205.55 ) is that of TERMINAL where ESP module is connected & the screen shot of distant PC is shown with the IP address 180.215.121.135

Image 9

To send characters from ESP , use the AT command :

AT+CIPSEND=0,15

This indicates that you want to send 15 characters on channel 0.

The ESP will respond with a > symbol & waits till you type 15 characters.

Image 10

The distant PC now receives the 15 characters you typed inside ESP terminal.

newip3

Hence a two communication is established with ESP Terminal & a PC from anywhere in the world.This opens the door for INTERNET OF THINGS where you can control the devices connected to ESP from anywhere in the World.

WATCH THIS VIDEO :

cooltext753793315    cooltext753790696

In the previous post we’ve seen the ways to control the ESP8266 WIFI module from anywhere in the world.The key to success depends on the PORT FORWARDING , where we route the contact on particular port to the local IP address of the WIFI module.

Nowadays USB dongles are used widely for internet access .This post will help you troubleshoot PORT FORWARDING.

Following is the SETUP diagram .

TPLINK ROUTER is on the top of the NETWORK. An MTS USB dongle is plugged to TPLINK Router (model TL-MR 3420 with 3G/4G support).

A Laptop is connected to TPLINK Router on Ethernet using RJ45 cable.

A USB to TTL board is connected to PC on which the ESP 8266 module is wired.

The ESP module is linked to TPLINK Router on WIFI using the AT Command AT+CWJAP=”SSID”,”password”

 

ip8

On switching ON the ROUTER , it assigns LOCAL IP address to the modules connected to it either on RJ45 (wired) or on WIFI.

In our set up the LAPTOP which is connected by wire is assigned 192.168.0.100

& the ESP module which is connected on WIFI is assigned 192.168.0.101.

Note that the allotment of address is on first come basis.When you power off & on the Router again , this allotment may vary.

You can RESERVE the address by selecting the DHCP tab of TPLINK configuration.Here select

Address Reservation & then feed in the MAC address of the devices you’ve connected to the Router.

To know the MAC address you can use the ADVANCED IP SCANNER TOOL.

Download & install the tool. Start the scanner to know the IP address & MAC address of the devices connected .

ip12

STEP 1:

Confirm that you’ve Internet access after plugging  the USB dongle to the TPLINK Router .You need to login the TPLINK configuration with address 192.168.0.1 & enter the QUICK SETUP for this process.

STEP 2 :

Start the SERVER on ESP module

ip2

 

 

STEP 3 :OPEN PORT SCANNER

To confirm that the port we’ve started server ( here port no. 333) is OPEN , we use a  port scanner tool .

Advanced Port Scanner is a small, fast, robust and easy-to-use port scanner for Win32 platform. It uses a multithread technique, so on fast machines you can scan ports very fast.

Also, it contains descriptions for common ports, and can perform scans on predefined port ranges.

Download it & install.

http://download.cnet.com/Advanced-Port-Scanner/3001-18508_4-98269.html?hlndr=1&part=dl-73294

Open Port scanner & under Select port range enter 100 to 500 . As we’ve to check port 333 , we enter the range below 500 .Click on SCAN .

IP4

 

The PORT SCANNER displays the result regarding status of PORTs of your PC as well as the module connected to PC.

Here we can confirm that port 333 is OPEN on IP 192.168.0.101 (ESP module).

 ip5

 

STEP 4 : SET UP FORWARDING RULE on TPLINK CONFIGURATION

On TPLINK configuration window , under FORWARDING select the tab VIRTUAL SERVERS.

Click on ADD NEW.. & enter the Service & Internal port as 333 .

IP Address as 192.168.0.101 , which is the local IP allotted by Router to ESP module.

Select Protocol as TCP & then SAVE the settings.

 

IP9

 

IP 10

 

STEP 5 : WINDOWS FIREWALL SETTINGS

Open Windows Firewall Advanced settings & click on INBOUND RULES.

SET the rule to allow communication on port 333.

IP11

 

Now you are set to check the condition of PORT 333 externally.

For this we make use of an online tool www.canyouseeme.org

On opening the site your external IP will be automatically displayed.Enter the port number to check.

Click on CHECK PORT.

ip 13

Unless you see SUCCESS on this test , you can’t contact your ESP module from external world.

If you get ERROR , open the TPLINK configuration & click on STATUS.

Note IP Address displayed under 3G/4G.

From another computer with a different internet connection try to PING this IP address.

Open CMD & type in PING x.x.x.x

ip1

 

If the PING result is OK , you can be sure that the ESP module can be contacted from outside world.

If the PING result is TIMED OUT , you can’t communicate with ESP.

The   STATUS tab in my case , as shown in above screen shot , indicates an IP address starting 100.86.x.x

Generally following IP address ranges are PRIVATE IP ADDRESS RANGES :

10.x.x.x

172.16.x.x

192.168.x.x

These are reserved by IANA for private Intranets & NOT ROUTABLE TO INTERNET.

Private addresses are not reachable on the Internet. Therefore, Internet traffic from a host that has a private address must either send its requests to an Application layer gateway (such as a proxy server), which has a valid public address, or have its private address translated into a valid public address by a network address translator (NAT) before it is sent on the Internet.

In my case , the MTS ISP provider hide the PUBLIC IP address.

The MTS dongle does not support VIRTUAL SERVER settings , which means PORT FORWARDING IS NOT POSSIBLE with MTS.

What I couldn’t understand was , while writing my previous blog ,it worked sometimes.While MTS customer support was contacted repeatedly , they finally accepted that port forwarding is blocked by them.

After sleepless nights I’ve found a solution….. Read on my next post ….

 

cooltext753793315    cooltext753790696

In the previous post we’ve seen how to initiate ESP module & use AT commands.In this post TCP CLIENT mode operation is explained.

ESP8266 WIFI module has 3 modes of operation.

ST  – Station mode in which ESP acts as a device & connects to an existing Access point.

AP – Access Point mode where the ESP itself acts as AP & other devices like Mobile can connect to it.

Both – ST & AP both mode is allowed in ESP.The mode of operation is set by the AT command

AT+CWMODE = 1 for ST mode , 2 for AP mode & 3 for both.

As we’re testing ESP on STation mode , issue the command

AT+CWMODE=1

Image 7

To communicate with a webpage , we need to start a server with ESP module.You need to set multiple connections using command

AT+CIPMUX=1

This initiates the server for a Webserver.

Next we start the server at HTTP port 80 using command ,

AT+CIPSERVER=1,80

Image 8

To close the server the command is AT+CIPSERVER=0 followed by a Reset AT+RST

To get the STATION IP address ,

AT+CIFSR

The module returns the Station IP address , 192.168.1.3 .

If the CWMODE is set to 3 , you’ll get 2 IP address , one for AP & another for Station mode.We need the station IP address for Client mode operation.

Open your web browser & type in the address 192.168.1.3

The browser sends a HTTP GET request which is displayed on the putty window where ESP module is connected.The host IP address & the user agent (your web browser name) are displayed.

After you get OK  type in the command

AT+CIPSEND=0,30

This command is to send 30 characters through channel 0 .Use the channel number which is displayed as CONNECT while a request is received from the browser.

Image10

Now you get a  >  symbol , after which you’ve to type in 30 characters.

The module will wait till you type in 30 characters & finally displays SEND OK.

You’ve to type characters within the Timeout limit.Otherwise the link will be closed.

Image11

Now the characters are sent to the Web browser.

But the browser is still waiting for the channel to be closed.

Type in AT+CIPCLOSE=0

Here use the channel number ( 0) where the connection was established .

Image12

Once the channel is closed , you get the characters displayed on the browser.

HTML tags can be used to send characters

AT+CIPSEND=0,30

>

HELLO WORLD !!!!!

The above one displays characters using HTML tag type Heading 1.

Image 121

To close the server the command is AT+CIPSERVER=0 followed by a Reset AT+RST

For testing 2 way communication , open another instance of PUTTY .

Select connection type as TELNET & Port 80.

Type in the host address , which you get by AT+CIFSR command in ESP window.

Click on open.

Image 122

Type some characters inside TELNET window .You get these inside ESP window

+IPD,0,17:HELLO….

0 is the channel of communication & 17 is the number of characters received.

Image123

From within ESP window type AT+CIPSEND=0,20

ESP will wait till you type 20 characters.

On TELNET window the characters are received.

Image124

Watch this support video :

ESP WIFI Modules available at :

cooltext753793315  cooltext753790696

ESP8266 is an UART to WiFi module,  a really cheap and easy way to connect any small microcontroller platform (for example Arduino) wirelessly to Internet.

The ESP8266 is now one of the leading platforms for the Internet of Things. It’s super cheap, and super easy to work with.

This is a serial module with a built-in TCP/IP stack, so you can use it standalone

You can use AT commands to connect with WiFi networks and open TCP connections without need to have TCP/IP stack running in your own microcontroller: You can simply connect any microcontroller to ESP module and start pushing data up to internet.

esp1

There are several module designs called ESP-x where x is 1 to 12, so far.

I am using the ESP-1 module. The new firmware  is set at 9600 baud. provides the same 2×4 connector, Tx,Rx , RST, CH_DP(chip enable), and two GPIOs, GPIO0 and GPIO2.

ESP8266_pinout

 

ESP8266 is 3.3v device & cannot tolerate 5v levels.

Make sure you pullup the CH_DP and the RST line. I used  3k3 resistor to pull up  RST to +Vcc.

CH_PD is directly connected to +3.3v .Unless you connect CH_PD to Vcc , you won’t get any response from the module. The firmware boots up only on this connection.

So far it seems you can leave the GPIOs floating. For upgrading the firmware , however , the GPIO0 must be grounded.

The current consumption of the module is  80mA at idle state &  it can draw as much as 300mA during operation.

  1. Vcc: 3.3V, up to 300 mA
  2. GND: Ground
  3. Tx: UART Tx of the module, to be connected to the  Rx of the microcontroller
  4. Rx: UART Rx of the module, to be connected to the  Tx of the microcontroller
  5. RST: Reset/Restart, pull to GND to restart
  6. CH_PD: Chip enable, used for flash boot .
  7. GPIO0: pulled low for update mode
  8. GPIO2: not sure yet???

setup1

 

I used a USB to TTL converter for connectivity between PC & WIFI module.The converter has 3.3v output which is used to power the WiFi module. It has also a +5v supply out.

Care has to be taken with power supply as the unit is to be powered at 3.3V and using 5V will probably kill it.

For ease of connections I’ve used a Breadboard.The connection details are as below :

WIFI Module       USB-TTL

Vcc     —  3.3v

Gnd      — Gnd

Tx        — Rx

Rx        — Tx

CH_PD   — connected to 3.3v to enable chip firmware boot.

RST        —  connected to 3.3v through 3k3 resistor

CH_PD pin acts as an enable signal, without it the board is mute and deaf. If CH_PD is not pulled HIGH , you won’t get any response from the module.

Once you connect this last pin to VCC (remember 3.3V) the module is brought to life, and after some garbage in the serial port you can read the word “ready”. Once you get there things will start to get interesting.

The USB-TTL converter I used required a driver “Prolific 2303” to be installed.After installing the driver , I got the port allotment under device manager while the converter is connected to a USB port of PC.

Image 1

A serial Terminal software PuTty  is used to communicate with the port where USB-TTL converter is connected.

Open PuTty & select Serial .Feed in the port number seen under Device manager (here it’s COM41) & speed as 9600 (Baud Rate).

 

Image 2

Click on OPEN button to see the Terminal black window.

Try to type in AT .If you do not get any response , just momentarily connect the RST pin of module with GND.

You get some garbage data initially & then the address of the vendor “www.ai-thinker.com”

followed by the firmware version & then “ready”

 

Image 3

 

Now type in AT .The module will respond with OK. If not ,close the Putty window & again open it & proceed with above steps.

AT+GMR will return the current firmware version.

 

Image 4

 

Generally , you can inquire the module with AT command followed by question mark ?

or you can assign a value  , by using equal to = , after the AT command.

All AT commands must end with a “\r\n” – a carriage return & a New Line.

For detailed list of AT commands visit :

http://room-15.github.io/blog/2015/03/26/esp8266-at-command-reference/

 

AT+CIOBAUD? will return the Baud Rate the module is working with.

AT+CWMODE? returns the Mode of operation of the module.

CWMODE returns an integer designating the mode of operation either 1, 2, or 3.
1 = Station mode (client)
2 = AP mode (host)
3 = AP + Station mode (Yes, ESP8266 has a dual mode!)

 

Image 5

 

But the magic starts once you try AT+CWLAP command, that will provide you a list of available wifi access points in the area.

The command AT+CWLAP will list access points in range. This was very encouraging, not only is my access point (MBLAZE..) on the list, but the ESP can see at least as many access points as my laptop can .

The APs are listed as  +CWLAP: ecn,ssid,rssi,mac

The Parameter are

ecn:  0 OPEN  , 1 WEP , 2 WPA_PSK , 3 WPA2_PSK , 4 WPA_WPA2_PSK
ssid: string, SSID of Access Point
rssi: signal strength
mac: string, MAC address

In the above screen shot you can see my AP “MBLAZE..” is WPA2_PSK  (3) password protected.You can see some other APs which are open  & not protected with password .They are listed with ecn 0.

 

Next you want the board to join a certain access point (most of us want the board to act as a STA or WIFI client that will connect to an access point). That behavior is selected with the AT+CWMODE=1. You will need to reset your board after making this selection.

To connect to your home/office access point you issue the command AT+CWJAP=”yourSSID”,”yourWifiPassword”

The good news is that from now, every time you power the board it will try to connect to the same wifi network. You can see if it was successful by checking your router’s DHCP client list.

Even if the power is removed , the ESP module will remember the joined AP .

You can make it forget by issuing the QUIT command AT+CWQAP

 

Image 6

 

Alternatively you can check your module IP address with command AT+CIFSR. Once you know your board’s IP address you can try pinging it from your computer.

In the upcoming posts we shall investigate the module in TCP client and server modes.

 

For availability of these modules contact :

cooltext753793315   cooltext753790696