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:
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).
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.