One of the great things about the ESP8266 is that it has pretty fair amount of GPIO pins to work with. You won’t have to juggle or multiplex your IO pins. There are a few things to watch out for so please read the pinout carefully.
Please note that the following pinout reference is for the popular ESP8266 NodeMCU development board with 30 pins.
Not all pins are broken out in all ESP8266 development boards, but each specific pin works the same way regardless of the development board you are using.
ESP8266 Peripherals and I/O
The ESP8266 NodeMCU has total 17 GPIO pins broken out to the pin headers on both sides of the development board. These pins can be assigned to all sorts of peripheral duties, including:
|1 ADC channel||1 channel of 10-bit precision SAR ADC.|
|2 UART interfaces||UART0 can be used for communication. Since UART1 features only data transmit signal (TX), it is usually used for printing log.|
|4 PWM outputs||4 channels of PWM pins for dimming LEDs or controlling motors.|
|2 SPI and 1 I2C interfaces||There are 2 SPI and 1 I2C interfaces to hook up all sorts of sensors and peripherals.|
|I2S interface||1 I2S interface if you want to add sound to your project.|
Thanks to the ESP8266’s pin multiplexing feature (Multiple peripherals multiplexed on a single GPIO pin). Meaning a single GPIO pin can act as PWM/UART/SPI.
You can get extensive information about ESP8266 from the datasheet.
The ESP8266 development board has a total of 30 pins that connect it to the outside world. For simplicity, pins with similar functionality are grouped together. The pinout is as follows:
Let us analyze the ESP8266 pins and their functions one by one in more detail.
ESP8266 GPIO Pins
ESP8266 development board has 17 GPIO pins which can be assigned to various functions programmatically. Each GPIO can be configured to internal pull-up or pull-down, or set to high impedance.
Which ESP8266 GPIOs are safe to use?
Because the ESP8266 has many pins with specific functions, they may not be suitable for your projects. The following table shows which pins are safe to use and which pins require more attention before using them.
- – Your first priority pins. They are perfectly fine to use.
- – Pay attention as their behavior can be unpredictable, mainly during boot. Don’t use them unless you absolutely need to.
- – It is not recommended to use these pins. So avoid them.
|Label||GPIO||Safe to use?||Reason|
|D0||GPIO16||HIGH at boot, used to wake up from deep sleep|
|D3||GPIO0||connected to FLASH button, boot fails if pulled LOW|
|D4||GPIO2||HIGH at boot, boot fails if pulled LOW|
|D8||GPIO15||Required for boot, boot fails if pulled HIGH|
|RX||GPIO3||Rx pin, used for flashing and debugging|
|TX||GPIO1||Tx pin, used for flashing and debugging|
|CLK||GPIO6||Connected to Flash memory|
|SDO||GPIO7||Connected to Flash memory|
|CMD||GPIO11||Connected to Flash memory|
|SD1||GPIO8||Connected to Flash memory|
|SD2||GPIO9||Connected to Flash memory|
|SD3||GPIO10||Connected to Flash memory|
|A0||ADC0||Analog input pin, cannot be configured as output|
For your convenience, here is an image showing which GPIO pins are safe to use.
ESP8266 ADC Pins
The ESP8266 is embedded with a 10-bit precision SAR ADC.
The ADC on the ESP8266 is a 10-bit ADC meaning it has the ability to detect 1024 (210) discrete analog levels. In other words, it will map input voltages between 0 and the operating voltage 3.3V into integer values between 0 and 1024. For example, this yields a resolution between readings of: 3.3 volts / 1024 units or, 0.0032 volts (3.2 mV) per unit.
The following two measurements can be implemented using ADC. However, they cannot be implemented at the same time.
- Measure the power supply voltage of VDD3P3 (Pin3 and Pin4).
- Measure the input voltage of A0.
ESP8266 SPI Pins
ESP8266 features two SPIs (SPI and HSPI) in slave and master modes. These SPIs also support the following general-purpose SPI features:
- 4 timing modes of the SPI format transfer
- Up to 80 MHz and the divided clocks of 80 MHz
- Up to 64-Byte FIFO
Actually you can use any GPIO pins as SPI pins by ‘bitbanging’, but if you end up using ‘hardware SPI’ you will want to use the HSPI pins (GPIO12-15).
Usually standard libraries also use HSPI pins between the two.
ESP8266 I2C Pins
The ESP8266 doesn’t have hardware I2C pins, but it can be done by ‘bitbanging’. It works quite well and the ESP8266 is fast enough to match ‘Arduino level’ speed.
GPIO4 (SDA) and GPIO5 (SCL) are used as I2C pins by default, to make it easier for people using existing Arduino code, libraries and sketches.
However, you can use any other two GPIO pins as I2C pins by calling
wire.begin(SDA, SCL) in the Arduino IDE.
ESP8266 UART Pins
ESP8266 has 2 UART interfaces, i.e. UART0 and UART1, which provide asynchronous communication (RS232 and RS485), and communicate at up to 4.5 Mbps.
- UART0 (TXD0, RXD0, RST0 & CTS0 pins) is used for communication.
- UART1 (TXD1 pin), on the other hand, features only data transmit signal, so it is usually used for printing logs.
TXD0 and RXD0 are serial control and bootloading pins. These are connected via a USB-to-serial converter, so you should be careful when using them as you will also get USB traffic on them.
ESP8266 PWM Pins
In ESP8266 Pulse width modulation (PWM) output can be implemented programmatically on all GPIO pins: GPIO0 to GPIO15.
The PWM signal on the ESP8266 has 10-bit resolution. Also the PWM frequency range is adjustable from 1000 µs to 10000 µs, i.e. between 100 Hz and 1 kHz.
ESP8266 SDIO Pins
The ESP8266 has Secure Digital Input/Output Interface (SDIO) which is used to directly interface the SD card. 4-bit 25 MHz SDIO v1.1 and 4-bit 50 MHz SDIO v2.0 are supported.
ESP8266 Power Pins
The VIN pin can be used to supply power to the ESP8266 when you are not delivering power through USB.
The 3V3 pins are output from the on-board 3.3V regulator, they can supply 500mA peak.
The GND pin is the common ground for all power and logic.
ESP8266 Interrupt Pins
All GPIOs can be configured as interrupts, except GPIO16.
ESP8266 Control Pins
RST is the reset pin for the ESP8266, pulled high by default. When pulled low momentarily it will reset the ESP8266 system. It’s the same as pressing the on-board RST button.
The FLASH pin is used by the ESP8266 to determine when to boot into the bootloader. If the pin is held low during power-up it will start bootloading! It’s the same as pressing the on-board FLASH button.
The EN (sometimes labeled CH_PD or Chip Power Down) pin is used to enable ESP8266. The chip is enabled when pulled HIGH. When pulled LOW the chip works at minimum power.
The WAKE pin is used to wake the ESP8266 from deep sleep, you will need to connect it to the RST pin.