We continue with the SoC ESP8266 to discuss some of the hardware details of the ESP8266 and the ESP12E (in the previous entry we saw their pinout and that they are essentially equivalent), and their differences compared to an Arduino board.
The first thing to highlight is that the ESP8266 lacks many hardware functions included in Atmel processors. Alongside WiFi management, the SoC has to divide its resources among all these functions. Although it is faster than an Arduino, it is a workload overload, which in some applications can pose a problem.
The next thing to highlight is that, as we saw in the introduction entry, the ESP8266 lacks internal Flash memory. The memory where we store the program is included in the module, but outside the SoC, and they communicate with each other via SPI. This means there are modules with different amounts of memory, and we will not be able to use the GPIO pins that communicate with the memory (we will see this next).
Power Supply
The power supply of the ESP8266 is 3.3V; supplying a voltage higher than 3.6V will destroy the SoC. Although many development boards include voltage regulators to allow powering the board at 5V, or from USB.
Regarding whether the other pins of the ESP8266 are 5V tolerant, there has been much debate. According to the Datasheet (which changed according to versions), it was not very clear, but it was understood that they were not. However, currently, statements from Espressif and user experiments allow us to say that the GPIO pins of the ESP8266 are indeed 5V tolerant when functioning as a digital input..
The maximum current that digital pins can provide or absorb is 12mA. In comparison, most Arduino models can supply 20-40mA.
Regarding the analog-to-digital converter (ADC), the maximum voltage they can register is 0-1V. Supplying more than 1V to the ADC will damage it. However, some development boards include dividers to extend the range to 0-3.3V. You will need to check each board for the ADC measurement range.
The pin CHIP_EN controls the power on or off of the SoC, being on when it is HIGH
. The pin EXT_RSTB controls the Reset of the ESP8266, activating when it is LOW
.
Boot
The ESP8266 has 3 boot modes:
- UART Bootloader, to upload a program via UART to the flash memory.
- Boot Sketch, executes the last uploaded program in the flash memory.
- SDIO, which is not used when programming with Arduino.
To boot in one mode or another, the pins GPIO15, GPIO0, and GPIO2 must be properly configured according to the following table:
Mode | GPIO15 | GPIO0 | GPIO2 |
---|---|---|---|
Uart Bootloader | 0V | 0V | 3.3V |
Normal Boot | 0V | 3.3V | 3.3V |
SDIO | 3.3V | x | x |
In most development boards, there will be systems that manage the state of these pins for us. However, whether we want to use the ESP8266 (or ESP12E) independently or in the case of a development board, we must keep the following in mind:
- GPIO15 is always pulled down, so we cannot use its Pull-Up resistor.
- GPIO0 is set to
HIGH
during operation. - GPIO2 cannot be set to
LOW
during boot.
Connectivity
Digital Inputs and Outputs (GPIO)
The ESP8266 has 17 I/O pins (GPIO, General Purpose Input/Output pins). These can act as outputs providing voltage of 0V or 3.3V (LOW
and HIGH
). Acting as inputs, they can recognize a voltage of 0V or 3.3V supplied to the GPIO.
When acting as outputs, the maximum current that each GPIO can provide (or absorb) is 12mA.
As inputs, as previously mentioned, we can currently say that they are 5V tolerant (although I do not take responsibility if you damage your board), so using an input to measure a voltage of up to 5.8V should not damage it.
Regarding internal Pull resistors, like Arduino, pins GPIO0 to GPIO15 have Pull-Up resistors. Meanwhile, GPIO16 has a Pull-Down resistor.
Additionally, of the 17 GPIO we cannot use them all. In fact, we can use quite a few, which is another significant limitation compared to Arduino.
More information about which pins are usable on the ESP8266 in the entry Which pins can I use on an ESP8266
Analog Outputs (PWM)
Unlike Arduino, the ESP8266 does not have hardware PWM, instead, it has to emulate it through software. This has the advantage that we can use PWM on all GPIOs, but it also means a computational load for the ESP8266. The default frequency is 1kHz but can be changed.
Analog Inputs (ADC)
The ESP8266 has a 10-bit resolution ADC. The ADC has its own pin, independent of the GPIO. The input range of the ADC is 0-1V; attempting to measure a voltage greater than 1V will damage the ADC. However, we have already seen that many boards have dividers that extend the range to measure from 0-3.3V.
Communication
Serial (UART)
The ESP8266 has 2 UARTs by hardware:
- UART0 on pins 1 and 3 (TX0 and RX0).
- UART1 on pins 2 and 8 (TX1 and RX1).
However, pin 8 is used to connect to the flash memory, so in practice, UART1 can only use pin TX1 (it can only send, not receive).
On the other hand, UART0 also has access from pins 15 and 13 (RTS0 and CTS0).
I2C Bus
The ESP8266 does not have hardware for I2C, so it has to emulate it through software. This means that we can use I2C with almost any GPIO pin, but again it imposes a load on the processor.
By default, the library uses GPIO4 and GPIO5 (SDA and SCL). The maximum speed is 450kHz.
SPI Bus
The ESP8266 has 2 SPI by hardware, but one is used to connect to the flash memory. Therefore, the ESP8266 has 1 SPI available (HSPI) that can act as both Master and Slave.
The pins used are GPIO14 (CLK), GPIO12 (MISO), GPIO13 (MOSI), and GPIO15 (SS).