Main Content

ESP8266: Monitoring Power Consumption

In this post I’m going to show you how you can monitor the power consumption of your battery driven (ESP8266/ ESP32) device. Measuring the power consumption over a full activity/ sleep cycle is the precondition to optimize your code for a longer battery runtime. Only with a reliable tool you can decide which code changes lead to less consumption. In a later post we’ll look at some tweaks we can apply to the code to get a few more days out of the battery.

As a long time professional Java developer I’m used to write applications that run on servers with lots of resources: RAM, disk space and energy consumption are rarely a limiting factor for the software we write. Developing software for embedded devices is a totally different story: memory both for flash and heap is very limited. And if you want to run your device from battery every second you are staying online counts towards the total energy bill of your battery. In our big server applications we usually say that you should first write reliable and readable code. If your application is not fast enough or consumes too much memory you start tuning the hot spots of your code until you get the desired results. Of course, it’s really hard to turn a bad decision in your architecture into a fast performing application. I would say that these rules are also true for embedded devices: first write reliable and readable code, then start tuning. And avoid costly dead ends which are later hard to fix.

In my opinion you can’t tune a system if you don’t have reliable measurements before and after you change any factor. So how do you collect this information in an embedded device? That of course depends on what aspect you would like to improve: memory, battery runtime, connection speed, etc. In this post I’m interested in prolonging the battery life of the ESPaper. Measuring the energy consumption of a device that consumes a few uA when it sleeps and a few hundred mA when it is awake is a special challenge: your regular multimeter might have a hard time measuring these two ranges. And we want to measure the summed up consumption over one sleep/wake cycle, not just the current drawn by the device at this very moment. You can do such a measurement with expensive tools like oscilloscopes. But if absolute consumption is not so important and you are rather interested in whether your changes have a positive or negative impact then the following setup will be the right tool for you.”

Link to article