**5.1 SD-card communication speed**

**Figure 1** shows the comparison of transfer speed between SD bus in 1-bit and 4-bit mode as well as communication via SPI bus on a SanDisk Ultra 32 GB and a SanDisk Extreme 32 GB in milliseconds.

The SD bus is clearly superior to the SPI bus, but there is only a little difference between the 1-bit and 4-bit modes. In 4-bit mode, the write processes are about 10% and read processes are about 25% faster in comparison to the 1-bit mode. The differences in reading operations between SanDisk Ultra and SanDisk Extreme are neglectable, however, while writing, the SanDisk Extreme 32GB performed the task 20% faster.

#### **5.2 Energy consumption**

### *5.2.1 Comparison of SD communication methods*

To further evaluate the best SD-Card communication method for mobile devices, the results of the current measurements during read and write operations are listed

**Figure 1.** *Read and write speeds of different SD-cards in SD bus 1-bit mode, SD bus 4-bit mode, and SPI bus.* *IoT on an ESP32: Optimization Methods Regarding Battery Life and Write Speed to an SD-Card DOI: http://dx.doi.org/10.5772/intechopen.110752*

below. **Table 8** shows the durations and measured currents of the SPI bus with three different commercially available SD-Card modules as well as SD bus communication (1- and 4-Bit mode) using a wired SD-adapter.

No great difference was observed between the various SD-Card modules in the SPI bus mode, neither in read or write speed nor in current consumption. However, there is a considerable difference among both SD bus protocols: comparing SD bus to SPI during reading, the current consumption is increased by around 13% in 1-bit SD bus mode and by around 15% in 4-bit mode, however, while writing, the current draw is only increased by around 5% in 1-bit mode and by around 8% in 4-bit mode. Generally, reading processes showed a higher power consumption than slower writing processes.

To evaluate whether a faster write speed via the SD bus results in a less overall discharge of the battery (despite its higher current draw) each actual discharge was calculated and is shown in **Figure 2**.

As can be seen, the higher write speed causes less discharge of the battery despite a higher current flow during the operation. Therefore, the SD bus in the 4-bit mode has the lowest overall energy consumption in this scenario.

#### *5.2.2 Comparison of various developer boards*

The first comparison of the developer boards was carried out during a standard test program, the flashing of the built-in LED. **Figure 3** shows the current consumption of the various developer boards during this test program.

In this comparison, the ESP32 modules show the highest power consumption during the LED blink program, with the DFRobot FireBeetle ESP32 performing best among them. As expected, the newer single-core ESP32-S2 of the Adafruit Feather S2 shows a lower power consumption. The lowest power consumption is shown by the non-ESP32 boards, of which the Arduino Nano 33 BLE has the highest power consumption among the non-ESP32 boards. Even though having the same CPU as the Arduino, the nRF52840 MDK had the lowest power consumption. The Adafruit Feather M0 Bluefruit shows a slightly higher power consumption than the nRF52840 MDK despite the efficient ARM Cortex M0+ CPU. The comparison of the developer boards in deep sleep mode is shown in **Figure 4**.


#### **Table 8.**

*Comparison of current consumption during read and write operations on the SD-card of different modules and communication methods.*

**Figure 2.**

*Calculated battery discharge when reading and writing from and to an SD-card with different methods and modules.*

#### **Figure 3.**

*Current measurement of different developer boards during a specific program sequence (LED blink).*

The Adafruit HUZZAH32 (according to **Figure 4**) has the highest power consumption in the sleep state. This is consistent with **Table 2**. Correspondingly, the FireBeetle ESP32 shows a low power usage in the sleep state, only beaten by the Adafruit Feather S2, although the ESP32-S2 processor itself has a higher current requirement in deep sleep (see **Table 3**) and uses a less economical voltage regulator (see **Table 6**).

*IoT on an ESP32: Optimization Methods Regarding Battery Life and Write Speed to an SD-Card DOI: http://dx.doi.org/10.5772/intechopen.110752*

#### **Figure 4.**

*Current measurement of different ESP32 developer boards in deep sleep. The ESP32 and ESP32-S2 boards were used due to their similar deep sleep functionality.*

#### *5.2.3 CPU clock frequency reduction*

Since only the Adafruit Feather S2 among the non-ESP32 developer boards has Wi-Fi connectivity, for the comparison of current consumption at different CPU clock frequencies and operating states, it was compared with the two ESP32 boards. **Figure 5** visualizes the results of the current measurements. The Wi-Fi scan was performed up to a minimum clock frequency of 80 MHz, since the Wi-Fi module of the ESP32 is not supported at a lower clock frequency [3].

**Figure 5** shows that the Adafruit HUZZAH32 consistently has the highest power consumption in different operating states and at reduced CPU clock frequencies, whereas the Adafruit FeatherS2 consistently shows the lowest power consumption in this comparison. It is noticeable that the DFRobot FireBeetle ESP32 only has a slightly higher power requirement than the FeatherS2 in Wi-Fi Scan and at a clock frequency

#### **Figure 5.**

*Measurement of current at different CPU clock frequencies during Wi-Fi network scan and modem sleep of different ESP32 developer board.*


#### **Table 9.**

*Comparison of current consumption and process duration during read and write operations at different CPU clock frequencies in 4-bit and 1-bit SD bus protocol.*

of 80 MHz, as well as a constant approximation of current draw to the Feather S2 in modem sleep with reduced clock frequency.

To evaluate the functionality at reduced CPU clock frequencies in modem sleep, **Table 9** lists the performance when reading from and writing to the SD-Card at different clock frequencies as well as the simultaneously measured current flow. As with the Wi-Fi module, the ESP32 does not seem to support the SD bus protocol at clock frequencies lower than 80 MHz. 60 MHz could still be executed, but lower clock frequencies generated error messages and the data transfer was not executed.

**Table 9** also shows that the current decreases with lower clock frequencies and a lower current requirement in 1-bit mode, the communication speed is also reduced in both manners. At 60 MHz in 4-bit mode, the measurement is comparable to 240 MHz, which indicates that the reduction of the clock frequency below 80 MHz leads to malfunctions. As before, the calculation of the actual battery discharge should provide information about which mode at which clock frequency means the lowest power

#### **Figure 6.**

*Calculated actual battery discharge when reading and writing the SD-card at different CPU clock frequencies.*

*IoT on an ESP32: Optimization Methods Regarding Battery Life and Write Speed to an SD-Card DOI: http://dx.doi.org/10.5772/intechopen.110752*

consumption and therefore longest battery lifetime. **Figure 6** shows the discharge calculated from **Table 9** during the read and write operations of the two modes at the different clock frequencies.

The direct comparison shows that despite the higher current requirement, the 4 bit mode causes less battery discharge than the 1-bit mode due to the faster communication speed. The comparison of the power consumption of the 4-bit mode at different clock frequencies shows only minor differences, of which the best efficiency was observed at a clock frequency of 160 MHz in 4-bit mode.

#### **6. Discussion**

In this section, the results presented above are discussed and possible reasons for controversial results are mentioned.

#### **6.1 SD-card communication speed**

As assumed, the SD bus showed higher data rates than SPI, but the difference was much smaller than expected. Data rates of only 1.45 MB/s in 4-bit mode while reading and 0.59 MB/s while writing were shown, even though the ESP32 supports the high frequency (50 MHz) 4-bit SD bus mode, which according to the datasheet should allow a transfer rate of up to 25 MB/s. Additionally, the 1-bit mode was not 4 times slower than the 4-bit mode. Only a 25% slower transfer rate for reading and 11% slower for writing data was measured. Lower transfer rates than those reported by the data sheets were also measured for the SPI bus, with 0.35 MB/s achieved while reading and 0.26 MB/s while writing, they are slightly less than a quarter of the nominal value of up to 1.6 MB/s. Possible causes for the deviations could be explained by inefficient register allocation of the libraries provided for the ESP32 SD bus interface, which is also shown by the fact that other colleagues could also not achieve higher transfer rates when using the ESP32 [16].

Nevertheless, **Figure 2** shows that the method with the highest transfer rate and thus a shorter transfer duration also causes the lowest battery discharge, which is why the SD-bus in 4-bit mode on the ESP32 is recommended even if its performance potential cannot be achieved. Likewise, the usage of a high-quality SD-Card is also recommended. The data can be transferred at three different CPU clock rates, whereby the differences in discharge turned out to be comparatively small, in this case, the rule faster data transfer equals lower discharge does not seem to apply. In our test, the clock rate of 160 MHz showed the lowest discharge.

#### **6.2 Power consumption**

Measuring the current with a multimeter while operating the microcontroller on a battery is not the most precise method, but sufficient for the extent of the differences between the respective compared developer boards and processes. In terms of energy consumption, it was basically found that the ESP32 has the highest energy consumption consistent with the data sheets, followed by the ESP32-S2, then the Cortex M0+ of the Adafruit Bluefruit M0, and with slightly less consumption of the nRF52840. Although the ESP32 has the highest power consumption, this processor also offers some advantages such as SD bus connectivity and high processor clock frequency for

more computational performance and faster data rates, so further research was done with the ESP32.

Consistent with **Table 2**, in our series of measurements the FireBeetle ESP32 also showed the lowest quiescent current and power consumption in deep sleep among the ESP32 boards. However, the Adafruit Feather ESP32-S2 had an even lower power consumption, although the ESP32-S2 itself has a higher power consumption in deep sleep and a less efficient voltage regulator. The lower power consumption that we observed can be explained by the intelligent circuit layout: all peripheral modules are connected in a second circuit, which is switched off in deep sleep.

The reduction of the clock frequency showed a large effect up to a clock rate of 40 MHz. Below that, only a small reduction in energy consumption was detectable. At 20 MHz the ESP32 had a similar power consumption as the Arduino Nano 33 BLE at 64 MHz. But the Arduino Nano 33 BLE has several peripheral modules like the NINA Bluetooth module and a 9-axis IMU which is responsible for the higher power consumption compared to the nRF52840 MDK which uses the same CPU. Without the peripheral consumers, the Cortex M0+ as well as the nRF52840 showed a significantly lower power requirement than the throttled ESP32.

It could be demonstrated that the choice of a low-power developer board has a great impact on the overall power consumption of the system. If an economical module with low quiescent current is used, the power requirements can be throttled down to almost the level of the more economical microcontrollers such as the Adafruit Feather S2 or the Arduino Nano 33 BLE with still sufficient performance reserve. But if less performance is sufficient and small amounts of data have to be transferred, the Cortex M0+ or the nRF52840 are clearly recommended. As long as fast Wi-Fi data transfer and better performance are required but no fast data storage on SD-Cards is necessary, the ESP32-S2 would be the best choice.

#### **7. Conclusion**

In summary, the combination of high write speed and low power consumption is difficult to reconcile. It is recommended to write to the SD-Card as infrequently as possible and at 160 MHz using an ESP32 in SD bus 4-bit mode. In ordinary program cycles, the ESP32 should be operated in the state with the lowest power consumption. If a Wi-Fi connection is not necessary at any time or there is no stable Wi-Fi connection, the ESP32 should be operated in modem sleep mode and the clock rate should be reduced to the minimum necessary to function, although a reduction below 40 MHz has little effect. Tasks with high computational effort should be performed at the highest possible clock rate to reduce the duration of the increased power consumption. For our application, the FireBeetle ESP32 is best suited and is recommended for comparable applications. If similar computational performance but no high-speed data logging is required, we suggest using the ESP32-S2 instead. If less processing power is sufficient, either the ARM Cortex M0+ with an additional Wi-Fi module for Wi-Fi applications or the nRF52840 for Bluetooth Low Energy applications are the best choices.

#### **Conflict of interest**

The authors declare no conflict of interest.

*IoT on an ESP32: Optimization Methods Regarding Battery Life and Write Speed to an SD-Card DOI: http://dx.doi.org/10.5772/intechopen.110752*
