ESP8266 WIFI module
I just got a ESP8266 WIFI module I ordered a few weeks ago. This is the pinout:
Just a quick warning: It seems that the inputs are not 5V tolerant, so be careful and do not connect the module to Arduino or USB serial adapter running at 5V or you may fry it. You must use 5V to 3.3V level converter if you want to connect it to 5V.
I suggest trying it out with USB to TTL converter first – you send commands from the PC and then advancing onto microcontroller.
I first tried to connect with it by just connecting GND to ground, VCC to 3.3V from Arduino UNO with 100uF capacitor added between GND and 3.3V and UTXD to RXD and URXD to TXD of CP2102 USB to serial converter (similiar to this but using external usb serial converter). I just couldn’t get it working, but after some searching around the internet I found out that there are actually two flavours of this board around (take a look here). Mine also needed to have CH_PD connected to 3.3V. The last link also says that GPIO0 needs to be connected to GND, however just for testing it doesn’t seem to be needed.
When CH_PD is connected to 3.3V the module boots up. The red led will stay on, the blue will blink on bootup. The module will send some garbage data at the serial connection and then a \r\n ready\r\n. My module works at 115200 baud.
If you got the “ready” message you can send a test command “AT\r\n” or maybe “AT+RST\r\n” to see the module responding. Each command should end with \r\n (0x13 0x10) characters (in RealTerm you should check the CR and LF checkboxes and use Send ASCII button to send the command in the box). When the module receives the command the blue led will flash. The AT+RST command will reset the module. The AT command won’t do anything but the module will respond with OK.
Following are some more complicated commands, if you want more in depth knowledge of what they actually do and how to use them you should check out the following manuals: 😉
You can check the working mode by command AT+CWMODE? and set it by command AT+CWMODE=3 (mode 3 STA+AP for example). The module may need a restart to get into the desired mode. In mode 1 and 3 you can use the command AT+CWLAP to check for the available access points and their RSSI data.
You can connect the module to access point by AT+CWJAP=”id”,”password” command. The password should be actual password not a passphrase, if you look at the settings of your router, you should proabably see them both. The AT+CWJAP? command won’t tell you anything about connection status, but AT+CIFSR will (Error if no connection, IP otherwise). You can quit the AP by AT+CWQAP.
When in mode 3 STA+AP the module can be connected to another access point and a PC can be connected to it, however the forwarding doesn’t seem to work so the PC can only access the module and not the external network (the module doesn’t seem to work as a router). When connected with PC to the module, you can check the PC and module IP by running the ipconfig command. My module has IP of 192.168.4.1 and PC from 192.168.4.101 on.
When you have PC connected to the module you can try the server and client connections to the module.
For connecting to the server on the PC you can use the AT+CIPSTART command. You can quickly set up a terminal running as a server on PC by using RealTerm. Type server:9999 in port field and click open. Windows may ask you for permission to let the program access the internet. For connecting to server either single connection mode (AT+CIPMUX=0) or multiconnection mode (AT+CIPMUX=1) can be used. Here only multiconnection mode will be demonstrated as it is more useful. In single connection mode just omit the connection id number in CIPSEND command. The PC should be connected to the module WIFI and the server should be set up on PC. Now you can switch to multiconnection mode and then open a connection to PC (AT+CIPSTART=4,”TCP”,”192.168.4.100″,9999). When the connection is estabilished you can try sending some data from PC via the socket. The data will be received using +IPD command. You can also try sending some data from the module using AT+CIPSEND=4,5 command (4 is the id of connection and 5 is the number of bytes to send). You should enter 5 bytes of data after you receive the > character from the module. The data should show up in the receiving terminal.
For the server mode on module to work multiconnection mode has to be enabled. This can be done by command AT+CIPMUX=1. To open a server on a specifed port a command AT+CIPSERVER=1,8888 Here the 1 means open server port and 8888 is the port number. After you configure the server port on the module you can use RealTerm to connect to it. If you type 192.168.4.1:8888 into the port and click Open button you will connect to the module (WIFI to the module must be estabilished). When the PC connects to the module, the module will output “Link”. Any characters typed into the terminal or sent by Send command will be received by the module by +IPD command. You may use AT+CIPSEND command to reply to the connecting terminal.
So that’s it for now. Note that this test has been done on close range and for now only on direct connection (wifi pc to module), I have not yet tested a connection via router or to the internet. However the module seems to connect to my router which is ca. 20m away in another building (some android devices have issues with getting a connection) so the range doesn’t seem to be too bad. One thing that would also have to be checked is if the MAC addresses of the modules are unique and fixed.