Ina219 current meter

This is just a placeholder for my playing with the current meter.
I recently invested (!) in a small device
https://www.aliexpress.com/item/-/32846936171.html
and plan to use it to check battery capacity when running my little esp8266 thingies. I find that the batteries do not last as long as I expected based on capacity and the esp power usage so this is my attempt to see if the current meter agrees with my observation.

Only played with it for a couple of days, and each test takes one day (depleting a 600mAh battery).

For fun I also ran it at full speed, reading the meter as fast as possible to see if it shows what I see on the DSO. Here is an example of the output:

I used the aruino IDE in this case, which ran on a nodemcu, measuring another esp8266 board.
The run managed about 1600 readings a second.

This is the sketch
Simple at this stage, uses the power-up defaults.

3 Likes

Interesting, I’m curious how accurate they are to the lower power levels you’d usually expect to see being drawn from an esp8266 while it’s sleeping, or are you only curious about how much it’s using when it wakes up, and for how long it’s awake for?
(looking at your graph now and seeing that it was only awake for 0.7 of a second, that answers my question. I was only looking at the end of it, and assuming it was a 90-second long power draw test, not a fraction of one)

The current drawn when sleeping is extremely low (under 20uA) and is below what I can sense.
I can replace the burden resistor to measure lower current but this will reduce the maximum from 400mA (the setting used now) which will be exceeded.

If I wanted to verify the sleep mode current I can put the esp to sleep for an extended period (e.g. 1h), with a resistor that allows reading at 1uA resolution.

I will probably buy a few more current sensors for these situations. Last time it took almost 2 months to arrive…

The target under test (esp8266) was running a loop, reading a OW temp sensors and sending a UDP packet to a server, every 2 seconds. I then sleeps until the next loop.

The current sensor (ina219) was attached to a nodemcu (esp8266) that read as fast as possible and printed the time (us resolution) and current. It managed under 600 readings a second.

Activity time was about 650ms, and I plotted one such period. It looks just like what I see on the DSO, just cleaner (fewer readings).

The log of the run looked like this:

90.439 0.00000000
90.440 0.89999998
90.442 3.20000005
90.444 21.10000038
90.446 21.10000038
90.447 21.10000038
90.449 21.10000038
...
90.558 32.20000076
90.560 32.70000076
90.562 15.89999962
90.563 0.60000002
90.565 0.60000002
90.567 0.60000002
90.568 3.50000000
90.570 31.39999962
90.572 31.20000076
90.573 35.09999847
90.575 40.90000153
90.577 72.50000000
90.579 71.90000153
90.580 72.30000305
...
90.898 78.90000153
90.900 79.09999847
90.902 79.00000000
90.903 76.80000305
90.905 77.69999695
90.907 77.80000305
90.909 99.19999695
90.910 189.30000305
90.912 77.30000305
90.914 77.19999695
90.916 77.50000000
...
90.951 79.19999695
90.952 76.50000000
90.954 130.60000610
90.956 259.60000610
90.957 143.00000000
90.959 67.40000153
90.961 223.10000610
90.963 180.39999390
90.965 108.30000305
90.966 79.09999847
90.968 78.69999695
90.970 78.69999695
...
91.059 78.30000305
91.060 78.59999847
91.062 69.19999695
91.064 136.19999695
91.066 259.10000610
91.067 70.40000153
91.069 70.40000153
1 Like

Unrelated but connected. Working on this project (on windows) I was notified by the Arduino IDE that there is an update for the esp8266 platform and I allowed it. Since then I am unable to flash any sketch, the esptool.py fails every time regardless of which nodemcu board I use (I have a few).

Here is an example log attempting to flash the blink sketch:

Sketch uses 257696 bytes (24%) of program storage space. Maximum is 1044464 bytes.
Global variables use 26572 bytes (32%) of dynamic memory, leaving 55348 bytes for local variables. Maximum is 81920 bytes.
C:\Users\eyal\AppData\Local\Arduino15\packages\esp8266\tools\python\3.7.2-post1/python C:\Users\eyal\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2/tools/upload.py --chip esp8266 --port COM5 --baud 115200 --trace version --end --chip esp8266 --port COM5 --baud 115200 --trace write_flash 0x0 C:\Users\eyal\AppData\Local\Temp\arduino_build_395928/Blink.ino.bin --end
esptool.py v2.6
2.6
esptool.py v2.6
Serial port COM5
Connecting...TRACE +0.000 command op=0x08 data len=36 wait_response=1 timeout=0.100 data=
    0707122055555555 5555555555555555 | ... UUUUUUUUUUUU
    5555555555555555 5555555555555555 | UUUUUUUUUUUUUUUU
    55555555                          | UUUU
TRACE +0.000 Write 46 bytes:
    c000082400000000 0007071220555555 | ...$........ UUU
    5555555555555555 5555555555555555 | UUUUUUUUUUUUUUUU
    5555555555555555 5555555555c0     | UUUUUUUUUUUUU.
TRACE +0.111 Timed out waiting for packet header
.TRACE +0.098 command op=0x08 data len=36 wait_response=1 timeout=0.100 data=
    0707122055555555 5555555555555555 | ... UUUUUUUUUUUU
    5555555555555555 5555555555555555 | UUUUUUUUUUUUUUUU
    55555555                          | UUUU
TRACE +0.000 Write 46 bytes:
    c000082400000000 0007071220555555 | ...$........ UUU
    5555555555555555 5555555555555555 | UUUUUUUUUUUUUUUU
    5555555555555555 5555555555c0     | UUUUUUUUUUUUU.
TRACE +0.009 Read 1 bytes: c0
TRACE +0.000 Read 95 bytes:
    0108020007071220 0000c0c001080200 | ....... ........
    070712200000c0c0 0108020007071220 | ... ...........
    0000c0c001080200 070712200000c0c0 | ........... ....
    0108020007071220 0000c0c001080200 | ....... ........
    070712200000c0c0 0108020007071220 | ... ...........
    0000c0c001080200 070712200000c0   | ........... ...
TRACE +0.000 Received full packet: 01080200070712200000
TRACE +0.063 Received full packet: 01080200070712200000
TRACE +0.048 Received full packet: 01080200070712200000
TRACE +0.047 Received full packet: 01080200070712200000
TRACE +0.063 Received full packet: 01080200070712200000
TRACE +0.047 Received full packet: 01080200070712200000
TRACE +0.063 Received full packet: 01080200070712200000
TRACE +0.063 Received full packet: 01080200070712200000
...

followed by what looks like a huge memory dump.

I now use a VM on this laptop, and this raised another interesting issue.
Flashing the ina219 sketch from this VM or from a native linux PC ends up with very different runtime speed. The VM leads to a run that is about 2.5 time slower than the PC. Same sketch, same Arduino, same platform and libraries.

If I flash from the VM I get the same slow performance monitoring from the VM and from the PC. Flashing from the PC gives a fast runtime regardless of where it is observed (the IDE serial monitor).

[later] It now works in windows, no need to the VM. The new board version has an option turned on that floods the screen with upload messages. As ‘File/Preferences’ suggests, options are in preferences.txt, and near the end I changed upload.verbose=true to false.

OK, some more results.
First, I slightly modified the ina219 library to speed it up when possible. I then ran a REPORT_CURRENT mode test where the current was reported 1500-1600 times/s. I noticed that when the WiFi connection was quick, and the whole activity took around 650ms (see image at the top of this thread) there was some current used when the esp was in deep sleep. About 1mA rather than the expected 20uA. Here is what it looked like:

Note the 1mA between about 98.5s and 98.9s, something like 400ms. After some digging into the code I realised that it must be the DS18b20. The esp reads the temperature (from previous cycle) and then kick-starts a read operation, which is speced as 750ms. So the read continues after the esp sleeps. The datasheet says the DS18b20 consumes typically 1mA when active so this matches.

This is something I missed in my energy budget estimates, yet 1mA for 0.4ms is not a lot when a typical cycle averages 70mA for 650ms (less than 1%). It does not explain why I seem to only get about 60% of the capacity of a battery in a typical long run (a few months).

I will now set up a long run, probably using a 1000mAh LiFe battery (so no LDO needed) with a cycle every minute:

  46mAs/minute = 0.012778mAh/m
  1000mAh/0.012778mAh/m = 78260m
  78260m/60m/24h = 54 days

This should be a reasonably realistic long run, though I usually use larger batteries (2400mAh AAs).

I need to power the ina219 for this period, it consumes less 1mA max, and the controller consumes
about 30mA (if I use an esp8266 without WiFi).
I should really try something lighter, maybe an MSP430?
Or simply power it from a UPS (luckily I have a recently decommissioned one)? Surely this canon should subdue this butterfly.

2 Likes

Does anyone have a 1% resistor? Preferably SMT? I want to replace the one on my ina219 board which comes with a 0.1Ohm resistor.

Most of the time it will pass under 80mA, so low wattage, with tiny peaks up to 300mA as can be seen at the top of this thread.