Saturday, May 28, 2016

ESP8266 ESP-01 testing - Part 2

Today we are going to learn how to communicate with the ESP8266 module through the serial (UART) connection using AT commands. 

In the previous post we learned how to connect the ESP8266 to a computer and test the serial and WIFI connection. If you need help hooking up your ESP8266 module take a look here: ESP8266 ESP-01 testing - Part 1

AT commands

Serial communication with the ESP8266 is done using AT commands. If you are not familiar with AT commands, they are instructions used to control modems. The ESP8266 is controlled the same way as a modem or GPS module. An instruction (or command) request is sent to the device to perform an action that once evaluated is executed (or not) and a "response" is given in return. The ESP8266 accepts many AT commands but today we are only going to use some of the most common ones. A full list of ESP8266 AT commands is provided at the end of this post.

The board used in this tutorial uses the stock firmware version .9.0.2 (00180008902) from AI-Tinker.com. Different firmware versions may behave differently. The AT commands list has also been updated since these boards where launched. If you are using a board with older firmware version and/or older AT commands version, newer AT commands will not be recognized! Like with firmware, the ESP8266 board AT list can be updated.

Let's get started!


Test AT startup


The first command we are going to send to the ESP8266 board is simply AT. It's used to test the startup function of our ESP8266 module. In RealTerm:
  1. Click the Send tab.
  2. Type AT in the first textbox.
  3. Check the  +CR and +LF.
  4. Press the Send ASCII button.

The ESP8266 board should respond with an OK message. This tells us the command was received and the serial communication is ready and working.

ESP8266 AT command

View version information


Now lets find out what is the firmware version of our ESP8266 board. Send the AT+GMR command.


This board uses firmware version .9.0.2 (00180008902). This is an old firmware version.

Note: the version information displayed depends on the firmware running on the board. Newer firmware versions display the firmware version and the AT commands version.
 

Change baud rate


Lets change the ESP8266 baud rate, or the speed of the serial communication. Let's try 115200 baud. Type AT+CIOBAUD=155200 and press the Send ASCII button. The ESP8266 should output the following text which confirms the new baud rate was accepted:

ESP8266 baud rate AT+CIOBAUD command

Notes:
Newer boards accept two sets of serial parameters: AT+UART_DEF (default params, saved on the board memory) and AT+UART_CUR (current params, not saved).

Now the ESP8266 serial interface is running at 115200 baud. Since we changed the baud rate in the ESP8266 module we must also change the baud rate in RealTerm to 155200!

ESP8266 baud rate AT+CIOBAUD command

The new baud rate was set and stored in the ESP8266 memory. From now on, every time the board is started or restarted it will default to 115200 baud rate. 

We can also ask our ESP8266 module what the baud rate is. To do this we send the command AT+CIOBAUD?  

ESP8266 baud rate AT+CIOBAUD? command

Other AT commands you might want to test:

AT+RST – Restart module;
AT+RESTORE – Factory reset.


Wi-Fi related AT commands


Before trying out WiFi commands we should get familiar with the different WiFi modes. As we know, the ESP8266 supports three modes: station mode, softAP (virtual access point) mode and station mode + softAP mode. In station mode the ESP8266 works as a network device and can connect to an existing wireless network (router). In softAP mode the ESP8266 behaves as a wireless router and can be connected to by network devices.When operating in both modes (softAP + station mode), the ESP8266 can act as network repeater.

Set WiFi mode


The default ESP8266 WiFi mode is softAP (2). To know what mode your ESP8266 module is in, send the command AT+CWMODE?

According to what WiFi mode the ESP8266 is on it will respond with 1 : station mode, 2 : softAP mode or 3 : softAP + station mode.


To set to a particular WiFi mode send AT+CWMODE=X, where X is the mode you want to set.

To use the next WiFi commands the ESP8266 must be in mode 1 or mode 3, so change to station mode (mode 1), sending  AT+CWMODE=1.

ESP8266 set WiFi mode AT+CWMODE command

Note:
AT+CWMODE will not be recognized by boards with firmware from Espressif, use AT+CWMODE_CUR or AT+CWMODE_DEF instead.

Get list of available WiFi access points in our location


Type and send the command AT+CWLAP. The  ESP8266 will scan the WiFi frequency range and list all the access points in range. Each line item consists of the security level of the AP, network name, signal strength, MAC address and WiFi channel.

ESP8266 get list of WiFi AP's AT+CWLAP command

Security Modes:
0 Open
1 WEP
2 WPA_PSK
3 WPA2_PSK
4 WPA_WPA2_PSK

Note:
If the you get an AT+CWLAP ERROR set the ESP8266 to station mode or softAP + station mode.

Join access point


To join an access point we can use the command AT+CWJAP="SSID","Password".SSID is the

ESP8266 join AP AT+CWJAP command

After a few seconds the ESP8266 should respond with OK if successful or FAIL if unsuccessful. After the board joins an access point, it will store that AP SSID and password and automatically join that access point every time the board starts up! To stop this, simply disconnect from the AP before powering of the board.

Note:
This command has been deprecated. If your board uses firmware from Espressif use AT+CWJAP_CUR or AT+CWJAP_DEF instead. See the Espressif ESP8266 AT commands list for details.

Disconnect from AP


To disconnect our ESP8266 from an access point simply send the AT+CWQAP command.


Documentation and tools:
Download RealTerm here.
Download AI-Thinker AT commands list here (unofficial).
Download Espressif ESP8266 AT commands list here.

Buy the Parts:
Buy the ESP8266 Wi-Fi from Banggood
Buy the ESP8266 Wi-Fi from Dealextreme
Buy the USB to Serial Adapter from Banggood
Buy the USB to Serial Adapter from Dealextreme

NEXT: ESP8266 firmware update
PREVIOUS: ESP8266 ESP-01 testing - Part 1

Saturday, May 21, 2016

ESP8266 ESP-01 testing - Part 1

In this post I'm going to test the ESP8266 ESP-01 WIFI module. I will demonstrate how to perform simple tests of the WIFI signal and serial communications with the module. This enables you to quickly check if  a board is good or faulty.

The previous post was and introduction to the ESP8266 WIFI modules family. If you missed it, you can read it here: ESP8266 WIFI modules.

Let's get started!


The ESP8266 ESP-01:

ESP8266 ESP-01 WIFI module

This module has inbuilt pcb antenna, 2 GPIO ports and pin header for external connections. Signal range is up to 400 meters (in open range). The board measures 14.3mm x 24.8mm. Prices start at around 2 USD for a ESP-01 with 4Mbit RAM memory (8Mbit RAM is also available).

The ESP-01 module used for testing is made by AI-Thinker.com, but the testing procedures are identical for boards from other vendors.

Testing the ESP8266:

When you buy one of these WIFI marvels you will want to perform a quick test to see if you received a good working device. 

Testing the WIFI

The simplest test is to power the module and check if its WIFI signal is detected. 
Connect the ESP-01 to a 3.3 Volts power source (GND and VCC pins). The module draws up to 170 mA when transmitting, so any power source capable of 170 mA will do the job.

ESP8266 pinout

 
WARNING: The ESP8266 power supply (Vcc) requires 3.0v to 3.6v. Never connect it to 5 Volts! 



ESP8266 WIFI connection test

After a few seconds your ESP8266 module should be listed as ESP_XXXXXX.

Testing the serial connection

Now we are going to test the wired serial communication between the ESP8266 and your computer. To do this we need to to connect the ESP8266 ESP-01 to a computer using the serial connection (UART) and a USB to serial adapter.

USB to TTL RS232 serial adapter
Connect the USB to serial adapter to the computer and check that it is recognized by the O.S. If you are connecting the adapter to the computer for the first time, you may need to install drivers. After the adapter connects successfully, disconnect it from the computer.

Checking USB to serial adapter COM port in Device Manager

Since the ESP-01 board communicates using 3.3 volt logic levels and not the more common 5V most adapters use, we will also be using a logic level converter. If your serial to USB adapter supports 3.3v logic level then you do not need the level converter (or level shifter). Do not confuse UART logic level voltage with power supply voltage!

4bit level converter board


Connect the USB to serial adapter, level adapter and ESP8266 module as follows:

ESP8266 USB to serial adapter level converter test connections

Most USB to serial adapters either have a jumper to set the power supply line (VCC) to 5V or 3.3V or have separate 5V and 3.3V VCC pins. Some level converters also have a 5V to 3.3V voltage converter. You can set the power to 3.3V in USB to serial adapter and connect it to the ESP8266 module or, you can connect the 5V Vcc output from the serial to USB adapter to the 5V Vcc of the level converter and connect the 3.3V output of the level converter board to the VCC pin of the ESP8266.

Please note that it IS possible to successfully connect the ESP-01 to the serial to USB adapter without the level converter/shifter, but doing so may cause unreliable operation or damage the ESP8266 board!

And this is how it may look after the connections are made. The small breadboard is not essential but, since we need to connect the ESP8266 CH_PD pin to a high logic level (3.3V), it is very handy.

ESP8266 serial test connections


To "talk" to the module we can use several serial communication / terminal programs or even the Arduino IDE. I will demonstrate using RealTerm. Realterm is free and can be downloaded from sourceforge.

After installing RealTerm, double check the boards connections and connect the serial to USB adapter to your computer. The red led (power) on the ESP8266 board should light up. The blue led should blink briefly. If the leds don't light up, unplug the USB to serial adapter from the computer immediately and check the connections again.

In the RealTerm Port tab, check if the correct port is selected. You can check this in the O.S. device manager COM ports. Make sure that byte size, parity and flow control are the same as the following image.


Disconnect and reconnect the CH_PD connection, preferably in the breadboard. Some readable text, like vendor name and firmware version should be displayed. 


If only garbled text is displayed it means RealTerm is not communicating correctly with the module. This probably caused by a speed mismatch. Select a different baud rate, press the Change button and disconnect and reconnect the CH_PD again. Repeat this until some legible text is displayed. Most modules seem to come with a default baud rate of 9600, so you may want to try 9600 baud first. 



That's it for now! Next time we will learn how to send commands to the ESP8266 module and, amongst other things, change the baud rate (speed) of our board. 

Documentation and tools:
Download RealTerm here.
Download ESP8266 datasheet here.
Further ESP8266 information, documentation and tools available on the Espressif Systems site
List of ESP8266 modules and specifications of  ESP8266 modules from AI-Thinker (not full list) can be downloaded here.

Buy the Parts:
Buy the ESP8266 Wi-Fi from Banggood
Buy the ESP8266 Wi-Fi from Dealextreme
Buy the USB to Serial Adapter from Banggood
Buy the USB to Serial Adapter from Dealextreme

NEXT: ESP8266 ESP-01 testing - Part 2
PREVIOUS: ESP8266 WiFi modules

Wednesday, May 18, 2016

ESP8266 WiFi modules

The ESP8266 Wi-Fi modules are tiny low-cost boards comprising a Wi-Fi radio transceiver, a 32 bit micro-controller and flash memory. They are programmable and can be connected to computing devices (Arduino and others) or used as standalone devices.

At the heart of the modules is the ESP8266EX chip which integrates an enhanced version of Tensilica’s L106 Diamond series 32-bit RISC processor. The MCU runs between 80-160Mhz, has low power consumption and two power saving modes. It is a complete and self-contained WiFi networking solution, can work as an Wi-Fi adapter or integrated with external sensors and other application specific devices through its GPIO's.

The ESP8266 is available in several configurations, with more or less memory, more or less I/O (GPIO) ports, different antennas, with or without shielding and with or without connection header. Most of these modules are named ESP-01 to ESP-14. The smallest is just 10x10mm!

Target applications for the ESP8266 are mobile devices, wearable electronics and the Internet-of-Things (IoT): home appliances, home automation, smart plug and lights, IP cameras, baby monitors, sensor networks, etc.

ESP8266 ESP-01 ESP-02 ESP-03 ESP-04 ESP-05 ESP-06 ESP-07 ESP-08 ESP-09 ESP-10 ESP-11

Recently (April 2016) AI-Thinker has released the ESP 32 series, ESP 85 series (ESP8285) and ESP-S series of WIFI modules.

MAIN FEATURES:
WiFi 2.4Ghz;
802.11 b/g/n protocol;
Wi-Fi modes: station/softAP/SoftAP+station;
Support STA/AP/STA+AP operation modes;
Integrated TCP/IP protocol stack;
Security: WPA/WPA2;
Encryption: WEP/TKIP/AES;
Low power consumption 32-bit MCU;
10-bit ADC;
UART serial connection;
Power supply: 3.3 Volts

The ESP8266 is designed by Espressif Systems, a fabless semiconductor company from Shangai, China. Initially modules where made by AI-Thinker but now they are available from other vendors also. They can be bought from dealextreme, banggood, ebay and may other places.

Documentation and tools:
Download ESP8266 datasheet here.
Further ESP8266 information, documentation and tools available on the Espressif Systems site
List of ESP8266 modules and specifications of  ESP8266 modules from AI-Thinker (not full list) can be downloaded here.

NEXT: ESP8266 ESP-01 testing - Part 1

Saturday, May 7, 2016

Welcome to the maker corner!

Hi, welcome to the Maker Corner!

In the Maker Corner I will be sharing my passion of electronics, computers and programming with you. I like all things electronic and I love to tinker with equipments and devices in order to improve or customize them. I am also an Arduino fan and will be sharing some projects and reviewing electronic modules and sensors.

I hope you enjoy the Maker Corner blog!