ESP8266 - Manna of IOT
24 Mar 2015 | by fuhoESP8266 is a wireless SOC (System On a Chip) manufactured by Espressif Systems. It is extremely integrated and requires few external components to run. If used in any of it’s modularized form, number of external component can go down to zero (that is if you can figure out how to power it from thin air) ;)
The chip comes in a module in many shapes and forms (so far I have counted 12), but all of them use the same SOC at it’s core, you can learn on any of them. The modules will differ in number of GPIOs (General Purpose Inputs / Outputs), antennas (PCB trace antenna, ceramic SMT antenna, mini antenna connector, pin or any combination of the above), flash memory size.
I will be describing ESP-01 (the very first version I got). If you don’t have one yet, you can find them for ~$3 / piece or less on AliExpress or eBay, I believe that you, the esteemed reader, can find the seller easily yourself. As of now I only have two ESP-01 modules, but I have a lot more (ESP-12 and ESP-07) coming my way straight from Shenzen.
Features
- SDIO 1.1/2.0, SPI, UART
- 32-pin QFN package
- Integrated RF switch, balun, 24dBm PA, DCXO, and PMU
- Integrated RISC processor, on-chip memory and external memory interfaces
- Integrated MAC/baseband processors
- Quality of Service management
- I2S interface for high fidelity audio applications
- On-chip low-dropout linear regulators for all internal supplies
- Proprietary spurious-free clock generation architecture
- Integrated WEP, TKIP, AES, and WAPI engines
Specifications
- 802.11 b/g/n
- Wi-Fi Direct (P2P), soft-AP
- Integrated TCP/IP protocol stack
- Integrated TR switch, LNA, power amplifier and matching network
- Integrated PLLs, regulators, DCXO and power management units
- +19.5dBm output power in 802.11b mode
- Integrated low power 32-bit CPU could be used as application processor
- STBC, 1×1 MIMO, 2×1 MIMO
- A-MPDU & A-MSDU aggregation & 0.4ms guard interval
- Wake up and transmit packets in < 2ms
- Standby power consumption of < 1.0mW (DTIM3)
- Power down leakage current of <10uA
TL;DR; If this doesn’t make much sense to you, don’t worry, it’s good, buy it now.
ESP-01
Pins have a standard spacing of 2.54mm and as you can see are not very breadboard friendly (they will short if you just plug it in a standard breadboards), so you will either have to de-solder the header, use use female to male jumper wires (you can never have enough of those) or use testing clips.
Pins Explained
1 - GND |
3 - GPIO2 |
5 - GPIO0 |
7 - URxD |
---|---|---|---|
2 - UTxD |
4 - CH_PD |
6 - Reset |
8 - Vcc |
- Ground
- Serial mode TX (Data to be transmitted over the comms link)
- General Purpose Input Output 2
- Chip select (High = On, Low = Off)
- General Purpose Input Output 0
- Reset (Pull to Low for Reset)
- Serial mode RX (Data that has been received from the comms link)
- Power, 3.3 V - DC
Serial modem mode
When you receive your ESP8266 (in a module form) it will most likely come pre-configured as a serial modem. This is the simplest mode, hence the default. You will be sending commands to the modem over serial protocol and it will obey.
Why should I ever use this mode
If you’re like me, you will want to get started with the module as soon as possible and this is the default and arguably the simplest way of interfacing the ESP8266. Or you already use an Arduino and all you want is to connect it to the Interweb.
Alright! Let’s get started then!
You will need a serial port, couple wires and I was going to say a power supply, (I decided to check if the external 3.3V power is really necessary and it turns out that my USB-to-Serial adapter’s 3.3V regulator supplies enough power for basic functionality. You will find mixed messages on the Internet, some say you need an external 3.3 power, some say you don’t. I started with a lab power supply and have now disconnected it. If anything changes I will let you know.) Two things to take from this, make sure your serial port’s Vcc is supplying 3.3V and not 5V and I forgot the other thing.
So it looks like all you need is a USB to RS232 adapter, you might even have one lying around, or an old PC with serial port or newish ThinkPad ;) If you don’t, eBay is your friend, they can be had for literally less than a dollar, including delivery.
Alright then, wiring it up should be obvious, let’s get to it.
Wiring
- Connect
3.3V
andGround
from your USB-to-Serial to the ESP-01. - Cross-connect the serial port, that is serial
TX
to espRX
and vice versa. - Set
CH-PD
to high (Connect it to to 3.3V) - Now rest after all this work
Communicating with the module for the first time
Module wired, serial dongle in your hand, plug the serial converter to an empty USB port. Start a serial console program of your choice (You might already have Putty if you’re on Windows, if you’Re on linux you don’t need my help), find your serial port, set baud rate to 115200baud, 8bit data length, no parity and 1 stop bit. Connect (if your software allows you to choose a line end characters choose CR,LF)
Serial settings
- Baud rate: 115200
- Data: 8bits
- Parity: None
- Stop Bit: 1
Moment of truth! Send AT
and you shall receive OK
, that was easy!
###Next time! We will compile a list of all known AT commands you can use with the ESP8266 module as it comes configured from factory.` We will connect to our wireless network as a client, run our WiFi access point and maybe even send some data from the module to the Internet.
PS: One of many advantages of external power supply
Should you still decide to run the module from an external supply, you will be able to see an interesting dump as soon as the module it powers up. You are very likely to miss this data if you power it up from the serial adapter.