If you are used to program usual computer or smartphone apps, web applications or comparable software, you are probably used to try things out until they start to work. When dealing with hardware dependent programming, this might become already a bit risky, because you could make an irrevocable error that prevents you from undoing that failure again, although the hardware is possibly still intact. Then, you are forced to switch to a lower level to remedy the defect for example. But if you are planning and assembling some hardware, you must not make any mistakes or you might destroy your new ICs or get a set of useless PCBs. So, the planning process has to be done very carefully.
A good start is to have a clear overview over the capabilities of the hardware that should be used. In general one needs to know what peripherals should be used to find a microcontroller that meets the requirements. In this case, the microprocessor ESP8266EX is chosen mainly due to its unbeatable price and its integrated Wi-Fi. The fact that it is capable to meet our requirements is anticipated, you will get an idea of how to find a processor for your requirements anyway. You can find more details for the reasons choosing this device in the master’s thesis in the download section.
ESP8266EX Microcontroller Unit
The ESP8266EX is a bit complicated in gathering all the needed data because Espressif Systems, the manufacturer of the chip, keeps itself covered or omits a lot of documentation. This is bothersome on the one hand, but helps to reflect on the important things.
ESP8266EX Pin Layout1
You will find the information that the chip “integrates an enhanced version of Tensilica’s L106 Diamond series 32 bit processor” that is running normally at a speed of 80 MHz. Cadence, that is the new name of the Tensilica processors manufacturer, declares them as “based on an industry-standard architecture” and “smaller than the ARM7 or Cortex-M3 cores” based on the chosen manufacturing process. Absolute values for the provided memory are hard to find. The chip possibly includes 64 KB of instruction RAM, 96 KB of data RAM and 64 KB of ROM. Around 50 KB of these are accessible in heap and data section when ESP8266EX is working in Wi-Fi station mode and is connected to the router. The ROM is not programmable, therefore, user programs must be stored in an external SPI flash memory that can have a size up to 16 MB (128 Mbit). These values are not very high, but an acceptable base to work with.
Another important information are the number of GPIOs and the available interfaces. The ESP8266EX has 17 GPIO’s that are multiplexed with other functions like PWM, SDIO, SPI, UART or I2S.
For a complete list, you can see the table below, that is mainly taken from the ESP8266EX datasheet1. The pin description is fitted a bit to the applications that are really used.
Battery Power Supply
We will use a Nitecore NL1473 rechargeable Li-Ion battery as a power supply to enable mobile usage of the board. It has the size of a usual AA battery and a nominal voltage of 3.7 V. The special thing about this battery are the “integrated battery overcharge / discharge protection circuits”. With these, we don’t need to care about overcharge / discharge protection in our application.
Nitecore NL147 Li-Ion Battery 3
As the battery voltage fluctuates between 4.2 V at full charge and about 3.4 V at full discharge, but the ESP8266EX is only tolerant to voltages of 3.0 to 3.6 V, a voltage regulator is required.
Texas Instruments TPS737 LDO Regulator 4
Serial Flash Memory
As it is stated in the datasheet, the “ESP8266EX uses external SPI flash to store user programs, and supports up to 16 Mbytes memory capacity theoretically”1.
The ESP8266EX supports different types of serial flash memories, but there is no further information in the datasheet. You can use serial flash memories that support “Standard, Dual or Quad SPI” modes. We will use the Winbond W25Q128FV (16 MB) in order to have the maximum possible memory size.
The W25Q128FV is connected to the pins 18 to 23 which serve as SPI clock, MISO (master in slave out), MOSI (master out slave in), hold, write protect and chip select 0. Hold and write protect are misused as additional data lines in the “Quad SPI” mode (which is the fastest SPI mode available). The other two chip select pins should not be used for connecting other SPI slaves to avoid a misbehavior / performance loss of the flash memory.
Winbond W25Q128 Pin Configuration 5
The actual connection is straight-forward, simply connect them as shown in the following table.
LIOT_ESP8266_ENV Pin Assignment for W25Q128
A USB-to-serial converter is needed in order to be able to flash a firmware to the serial flash memory. The most popular one is FTDIs FT232R, which is very customizable and has a price of about 4.00 USD. But also Silicon Labs’ CP2102 with a price of about 2.50 USD is very reliable and widely used. We will use the CP2102 as it is sufficient for our needs.
CP2102 Connection Diagram 6
The connection diagram may look very complicated, mainly due the different options that are displayed. But basically it has only to be connected to the USB connector as shown on the left side. On the right side - for this moment - we are only interested in the TXD and RXD pins.
TXD stands for transmit, RXD stands for receive. Also the ESP8266EX has these TXD and RXD pins, both for UART0 and UART1, but we will use the default UART0 interface. If you want to connect the CP2102 with the ESP8266EX, you have to cross the pins. This means that TXD of the CP2102 has to be connected to the RXD of the ESP8266EX (pin 25) and RXD of the CP2102 has to be connected to the TXD of the ESP8266EX (pin 26).
In UART mode, the TXD pin of UART0 switches to pin 14, but we will not use the UART while in UART mode.
So, the following connections can be taken to the assignment table:
LIOT_ESP8266_ENV Pin Assignment for UART
Boot Mode Selection
Although the information can be found in the internet, that the ESP8266EX has three boot modes7 - one for flash programming (UART mode), one for booting from SPI flash memory (flash mode) and one for booting from SD card (SDIO mode) - this has never been confirmed by Espressif. Confusingly, Espressif never explicitly published a table for the “strapping pins” of the ESP8266EX that are used to determine the boot mode at start-up.
ESP8266EX Boot Modes 7
As the third - SDIO mode - does not seem to work, we will only use the other two boot modes. For these, MTDO always has to be low at startup (reset) and GPIO2 has to be low. Thus, we will connect a pull-down resistor to MTDO and a pull-up resistor to GPIO2 later.
There are two possibilities to set the state of GPIO0 and to trigger a reset. On the one hand, this could be done by pressing two buttons. Then, first the GPIO0 button has to be held down while the reset button is pressed to enter the UART mode. On the other hand, the DTR (data terminal ready) and RTS (read to send) lines of the USB-to-serial converter can be misused to set the right boot mode. The NodeMCU devkit project8 developed the following circuit that does this.
NodeMCU Devkit Auto Program Circuit 9
We will use both, the buttons and the auto program circuit.
I/O Port Expander
So, only the four GPIO’s 0, 2, 4 and 5 remain for free decisions. Two pins will be needed for the use of software-I2C and thus connect the I2C slaves. Furthermore, a possibility to receive interrupts from the slave devices port expander, nine-axis sensor and environmental sensor is needed as well as the possibility to reset the port expander. The signaler needs a PWM signal and for all three LED’s it would also be nice to be able to use PWM. This would normally require ~10 more GPIO pins.
868 MHz Transceiver
The other SPI interface - HSPI - is provided by the GPIO’s from 12 to 15 which serve as MISO, MOSI, clock and chip select (in this order again). Regrettably, there are no other chip select pins for HSPI so that only one devices can be connected, which will be the sub-1GHz RF transceiver CC1101. In order to avoid interference and to be able to communicate with the transceiver durably, these GPIO pins should not connected differently. Moreover, the use of a pull down resistor on chip select is recommended to avoid floating states. This can be done as there is only one slave device.
Inertial Measurement Unit
LIOT_ESP8266_ENV Pin Assignment 10