martedì 10 ottobre 2017

Testing of the ESP8266–01 WiFi module






The ESP8266–01 is the first WiFi module of the ESP family from Espressif Systems.
It is a small and inexpensive WiFi transceiver that can be used in several different projects based on Arduino, Raspberry Pi or other applications.















Its specs are incredible for such a tiny module
  • 802.11 b/g/n protocol
  • Wi-Fi 2.4 GHz, support WPA/WPA2
  • Super small module size (11.5mm x 11.5mm)
  • Integrated 10-bit ADC
  • Integrated TCP/IP protocol stack (ipv4 only at the moment)
  • Deep sleep power <10uA, Power down leakage current < 5uA
  • Integrated low power 32-bit MCU
  • SDIO 2.0, SPI, UART, I2C
  • Standby power consumption of < 1.0mW (DTIM3)







Testing the module

As the world is more and more interconnected it is crucial to allow your projects communicating with the rest of the network and the cloud.
As an example 5 years ago a typical hobbyist temperature logger would have used a SD card to store the temperature reads over time. Today a modern temperature logger does not ship with local storage but it leverages any cloud service to store and visualize the temperature reads.









Over the year I have tried several different options to provide my projects with a communication channel. I have tried several type of RF 433Mhz module, infrared links, bluetooth transceiver and the good wireless Nrf24L01 modules. Each of this technology has its own pro and cons and I have achieved different level of satisfaction, but I am honest: none of them has been good and reliable as the great ESP8266–01 WiFi module.
The ESP8266–01 adds to my projects 802.11 b/g/n WiFi connectivity and allows me to control them over the Internet using standard technologies and applications on mobile phone.
In this article I describe my first testing of the module by properly wiring and interconnecting it to my home WLAN.






BoM
Below the components and material that is needed to test the module
  • 1x ESP8266–01 WiFi module







  • 1x Breadboard







  • 1x PL2302HX USB to TTL converter or any other USB to TTL converter







  • 1x AA battery holder (I have reused one from an old RC car) and 2x AA battery







  • 8x rainbow wire male-female








Wiring

I wire the module as depicted in the below figure













Power

The ESP8266–01 modules, according to its specifications, should be powered with a DC stable source at 3.3V.
Note:I really suggest to power it with a very stable 3.3V DC power source as the module is quite sensible to current fluctuation and it might be subject to auto-reset problem
In my very first test I have tried to power the module from an Arduino Uno but it was not providing enough Amps therefore I have switched to AA batteries
In the above schema the batteries must be wired in the following way:
  • blue wire (+) is the positive from batteries
  • black wire (-) is the negative or ground from batteries

Serial Interconnection

I use a USB to TTL converter which I have in my toolbox (PL2302HX ). This module provides 3.3V power but also in this case the current it is not enough to properly power the ESP module.
Note: you can use any other USB to TTL converter, they all work in the same way
Wire and connect the USB to TTL module in the following way:
  • black wire [1] to ground
  • purple wire [1] to RX pin
  • grey wire [1] to TX pin







EPS8266–01 wiring

The ESP8266–01 module which I am using has the following pin-out (different module ESP8266-X might have different pin-out)









I wire the module in the following way:
  • blue wire [1] to VCC pin
  • blue wire [2] to CH_PD pin (boot mode — for correct behavior of the ESP8266 module this pin must always be set to logical level 1/ON)
  • purple wire [2] to TX pin








  • grey wire [2] to RX pin
  • black wire [2] to GND pin






Once I have wired the modules following the above color schema, it is trivial to connect the wires on the breadboard. I connect the wires by couple of colors (black with black, purple with purple, …)

In short: all the black wires go to ground, all the blue wires go to VCC, then purple with purple (USB RX — Wifi TX) and grey with grey (USB TX — Wifi RX)
Below a picture of the wiring as described above













ESP8266–01 Test

ESP8266 Wifi Access Point

Now I just need to power on the ESP module by connecting the two wires from the battery holder to the breadboard as depicted above.
If everything goes well I will only see a blue led shortly blinking. Don’t worry this is correct, under the hood many things are happening.
I now verify on my PC (assuming Windows here) the available wireles lan








Surprisingly I can see a new WLAN I have never seen before (AI-THINKER_FE9961 — the SSID of your ESP8266 module might be different than mine). This is the first sign that I have correctly interconnected and powered the ESP8266–01 module.
By default the ESP8266 module is configured to behave as a WLAN Access Point so it is broadcasting is default SSID.

ESP8266 Wifi Client

In this article I am not particularly interested in the AP mode so I try now to configure the module as WiFi client and to test its behavior.
I need a terminal emulator (like the good old hyperterminal, minicom, ..). I have at handy the Arduino IDE which includes a simple and easy to use terminal monitor so I am using it.
Now I insert the USB to TTL module into an available USB port on my PC. In my case the USB to TTL module is configured by Windows as COM6 (in your case the COM number might be different but the procedure described here is exactly the same)
Now a quick check that the COM6 serial port is correctly configured for communication with ESP8266 module
I go to







here I can see the COM6 port, I right-click and select properties and then select the Hardware tab







Then again select properties and then Port Settings tab
Now I configure the COM port as depicted below






Now I run the Arduino IDE and I select the serial port in order to match the COM6







Now I open the serial monitor (Ctrl + Shift + M) and I check that the baud rate and the end of line characters are configured as in the below picture







Now I can reset the ESP8266 module by unplugging and plugging back the power wires on the breadboard.
If everything goes well, the ESP8266 module should start to print characters on the serial monitor and should print the world ready and then wait for user commands






The default ESP8266 firmware implements the standard Hayes commands (this is the old protocol used by analog modems before the Internet) also known as AT commands






A complete guide to the AT commands is available here
Now I perform a basic check by sending the AT command (Test AT startup ) through the serial monitor.
The correct and expected answer from the module is OK. If this is the case everything works properly and I can continue. If not I need to review the above steps to verify I have not missed anything.
The AT commands can be sent to the ESP8266 module through the terminal emulator. In the Arduino IDE serial monitor I just type the command in the top input text and press enter on the keyboard.







Out of curiosity I check the firmware version by sending the AT+GMR command (View Version Info). My module is running v 0.9.5 of the firmware (your version of the firmware might be different).





ESP modes

It is now time to change the working mode of the module and switch from AP mode to client mode. I use the AT+CWMODE command(Wifi mode)
In order to switch to client mode (station mode) I need to provide the 1 parameter (see picture below)







The ESP8266 answer with OK and this means that the module has correctly switched to station/client mode.
Now I check which are the available AP through the AT+CWLAP command (List available APs)
The ESP8266 module can see all the WLAN which are seen by my PC.This is a good confirmation that the module is properly working.
Now I check which is the assigned IP to the module (I am not expecting any real IP as the module didn’t yet joined any network). I use the AT+CIFSRcommand (Get local IP address)








The assigned IP is 0.0.0.0 which means that no IP is assigned to the module. I can also see the modules MAC address.
Just few commands ago I have switched the module to station mode so a reset is needed to complete such change of configuration. I use the AT+RSTcommand(reset module)








After the reset I instruct the ESP8266 to join my WLAN through the AT+CWJAP command(Connect to AP), by specifying the SSID and the password.








The ESP confirms me (OK) that it has successfully join the specified WLAN.
Now I check again the assigne IP address.







I can see that a valid IP address has been assigned by my router to the ESP module.

TCP/IP test

Ok, now the ESP8266 is part of my WLAN so I can verify the TCP/IP communication
From my PC I ping the ESP8266’s IP address







As expected it is reachable. This is good :)





ESP8266 as TCP client

To test the ESP8266 as a TCP client I use a Linux virtual machine and I run the simplest possible TCP server by using the great nc(netcat) command








Now my Linux VM is waiting for a TCP connection on port 9090
It is now time to instruct the ESP8266 module to open a TCP session toward the simple Linux server and send some data
I set a single TCP connection through the AT+CIPMUX command (Enable multiple connections or not). The 0 (zero) parameter stands for single connection








Now I create the TCP connection to the Linux server through the AT+CIPSTART command (Establish TCP connection or register UDP port and start connection). This commands requires the following parameters:
  • connection type (TCP)
  • server’s address (192.168.1.2)
  • server’s port (9090)
After the execution of such command the ESP8266 module replies with CONNECT and OK meaning that the TCP connection to the specified IP address and port has been successfully established.
Now I send some simple data to the server over the established TCP connection. I use the AT+CIPSEND command (Send data) and I specify the string’s length (hello ESP8266 = 13 byte). If you are sending a different string you should change the length parameter accordingly.
When the ESP answers with OK I can type the string “hello ESP8266” and press enter.
The module reply with SEND OK telling me that the data has correctly been sent over the TCP connection.
Now I terminate the TCP connection with the AT+CIPCLOSE command (Close TCP or UDP connection).
As always ESP confirm the correct execution of the command by replying OK.
Now I check on server side (Linux VM) and I can see on the terminal that the “hello ESP8266” string has been received and printed on screen.
I can also see that the TCP connection has been closed (nc has quit and server is back at command prompt).








I personally find this simple test very exciting. A small and inexpensive chip and module as ESP8266 is implementing a full TCP/IP stack and it is working. :)

ESP8266 as TCP server

Now I perform the opposite test by configuring the ESP module as TCP server and the Linux VM as TCP client. I use the AT+CIPMUX command with 1 as parameter to accept multiple TCP connection








Now I configure the TCP server with the command AT+CIPSERVER(Configure as server) and I pass the following parameters:
  • 1 (create server)
  • 9090 listening port
Now from the Linux console I send a simple string to the ESP server on 192.168.1.13 port 9090







The ESP TCP server, once received the string data print it on serial monitor telling me that the communication has been successful.








Conclusions

I have verified that the ESP8266–01 module properly works as WiFi Access Point, as WiFi and TCP client and as TCP server able to accept incoming sessions.
As mentioned at the beginning of the article, I have now the confirmation that the ESP8266–01 is the best module I have used so far. I can now easily add WiFi communication to my Arduino and DIY projects.