Arduino Nano + INA219 = cheap current scope

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
martinus
Normal user
Posts: 129
Joined: 15 Feb 2020, 16:57

Arduino Nano + INA219 = cheap current scope

#1 Post by martinus » 24 Jun 2020, 16:40

In order to checkout current consumption of the ESP doorsensor mod (using ESPNOW and controlling a servo on batteries) i decided to hookup an INA219 module to an old Arduino Nano module and used the Arduino IDE serial plotter to show exact current measures from boot till shut-down:
ESPNOW_Current.png
ESPNOW_Current.png (36.39 KiB) Viewed 33945 times
This will really aid in verifying changes to the code for further optimization.
As the plotter only shows the last 500 points, i used a timescale of 2 ms/point. so the 500 at the right end means 1000 milliseconds.
The graph shows the 90 mA during normal operation, the high peaks around 350 mA and the radio-off moments that use around 20 mA.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Arduino Nano + INA219 = cheap current scope

#2 Post by grovkillen » 24 Jun 2020, 17:25

Wow, looks really good!!
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Arduino Nano + INA219 = cheap current scope

#3 Post by TD-er » 25 Jun 2020, 11:58

What range have you set for the current?
And are you measuring the current in front of a linear voltage regulator?

User avatar
dynamicdave
Normal user
Posts: 257
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: Arduino Nano + INA219 = cheap current scope

#4 Post by dynamicdave » 25 Jun 2020, 14:50

What a great use for a INA219 - I might try that out with a spare Wemos D1 Mini as the current scope.

martinus
Normal user
Posts: 129
Joined: 15 Feb 2020, 16:57

Re: Arduino Nano + INA219 = cheap current scope

#5 Post by martinus » 25 Jun 2020, 15:30

TD-er wrote: 25 Jun 2020, 11:58 What range have you set for the current?
And are you measuring the current in front of a linear voltage regulator?
The range is set to 400 mA. Measuring the entire setup, so the modded doorsensor with the Arduino Pro Mini and the servo. The INA sensor is between the batteries and the Vbat connection of the doorsensor. It uses a step-up boost converter to provide the ESP and Servo with a constant 3.3 volts.
The Pro Mini is directly powered on VBat as well as the 'tuya' MCU.

I could adapt the lab setup to actually measure the current into the ESP module, but i'm actually only interested in the total current consumption as this will predict possible battery life.

This sample also shows the (slight) servo motion in action:
ESPNOW_Current2.png
ESPNOW_Current2.png (46.24 KiB) Viewed 33903 times
Looks like the start peak current when the servo starts to move is beyond the scale of 400 mA.

martinus
Normal user
Posts: 129
Joined: 15 Feb 2020, 16:57

Re: Arduino Nano + INA219 = cheap current scope

#6 Post by martinus » 26 Jun 2020, 15:45

Almost forgot that the Arduino Nano has digital inputs to mimic a cheap logic analyzer and the Arduino Serial plotter can do multiple lines in the chart.

So i used GPIO-0 on the ESP to toggle at some given points in the rules engine and hooked up to an input on the Nano.
Gives more info on what happens at certain moments:
ESPNOW_Current3.png
ESPNOW_Current3.png (52.88 KiB) Viewed 33850 times
It looks like the sleep command does not do anything to reduce current. This needs some further checking.
Also notice that gpio-0 seems to produce 'noise' during bootloader stage.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Arduino Nano + INA219 = cheap current scope

#7 Post by TD-er » 26 Jun 2020, 22:39

About the pin behavior during boot, see: http://rabbithole.wwwdotorg.org/2017/03 ... -gpio.html
Link is also mentioned here: https://espeasy.readthedocs.io/en/lates ... on-esp8266 ;)

And about the power consumption of the ESP.
https://www.youtube.com/watch?v=n_A_8Y4xNx8
That video describes how you can reduce the deep sleep consumption even more, which is probably more important then the power consumption while awake.

You can also prevent the RF calibration during initial WiFi connection, which will shave off the high power peaks and also make the connection faster. (when connecting to WiFi access point. Sending to ESP-now is different)

martinus
Normal user
Posts: 129
Joined: 15 Feb 2020, 16:57

Re: Arduino Nano + INA219 = cheap current scope

#8 Post by martinus » 27 Jun 2020, 09:25

I'm using the LSC doorsensor circuit for my battery devices. So every boot is a cold-boot in this case and it cannot use normal deepsleep.
So i guess some issues cannot be avoided with this type of circuit.

But the sleep current of the entire circuit is now 14 uA which is sufficient. Battery life will mainly be affected by the active-time and the number of wake-ups.
Wake-ups are set to 10 minutes. Active time should be as short as possible and every 100 mS really counts here. I am aiming at <500 mS for my projects.

I've seen graphs from another topic that shows a total active time of 285 mSeconds with custom firmware. I have not been able to do this with ESPEasy and i guess it would take some customization to make the boot process on ESPEasy faster. Maybe we could skip a lot of init code in case were running on batteries.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Arduino Nano + INA219 = cheap current scope

#9 Post by TD-er » 27 Jun 2020, 12:18

You can look into the RF calibration (one of the mode parameters when enabling wifi if my memory serves me well) and make sure the receiving end of the ESP-now is running in AP-mode and not in STA-mode.
So make sure you try to send to the AP-MAC of the receiving end.
In AP-mode the radio is not set to sleep and is always listening.
Otherwise you may need to wait for the beacon interval (102.4 ms, so 51.2 ms on average) to send data to the STA interface of the receiving end.

Also make sure to have the peer set using the MAC + channel (preferably channel 1) as soon as you start the esp-now layer and before sending out data.
It may also help to do that as the first steps in the setup() and then load the settings etc. so you give it some delay before sending out a message.

ESP-now also tries to send out the message several times until it receives an acknowledgement.
Typically this is 20 msec retry time with every second attempt at a lower bit rate (to get a better range).

Enabling the serial output for logging may also delay it as the HW buffer may fill up and making the write to serial become blocking until the HW buffer has room again.
In the logging of ESPEasy I added a buffer mechanism to overcome this blocking behavior, but still it may try to flush all before going to sleep again.
You may want to have a look at those functions, preparing the sleep.

martinus
Normal user
Posts: 129
Joined: 15 Feb 2020, 16:57

Re: Arduino Nano + INA219 = cheap current scope

#10 Post by martinus » 27 Jun 2020, 17:36

I am using the AP mac interface on the receiver so that should be ok.

About the sleep, it turns out that it does work like planned. The power-off as assumed in the previous graph was not true. I also measured VCC and used a 4 ms timescale, to find out that the VCC remains active for an additional second. The VCC is controlled by the tuya MCU so we have no control over that.
But during that additional second, the ESP is already into deepsleep and uses very little current.

And it seems that it takes about 100 mS before the sleep actually reduces the current after the ESP.deepSleep() command.
ESPNOW_Current4.png
ESPNOW_Current4.png (54.22 KiB) Viewed 33774 times

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Arduino Nano + INA219 = cheap current scope

#11 Post by TD-er » 27 Jun 2020, 18:27

Maybe there is a capacitor over the EN-pin (which would make perfect sense) which takes some time to discharge.

martinus
Normal user
Posts: 129
Joined: 15 Feb 2020, 16:57

Re: Arduino Nano + INA219 = cheap current scope

#12 Post by martinus » 07 Jan 2024, 11:53

TD-er wrote: 27 Jun 2020, 18:27 Maybe there is a capacitor over the EN-pin (which would make perfect sense) which takes some time to discharge.
After some years being busy with other thinks in life (like moving to a new house, waiting for renovations to complete, etc), this winter time was convenient to get back to ESP life.
I dug up some hardware from the box in the attic and tried if things still worked and it did after some time. This time i googled on ESP sleep behavior and found out that this option also exists:

system_deep_sleep_instant()

This puts the ESP8266 into sleep without any delay, so when the messages have been send using ESPNOW, the power consumption goes to zero immediatly:
DoorSensorCurrent_3.png
DoorSensorCurrent_3.png (41.73 KiB) Viewed 17677 times
This will improve battery life again. BTW the battery operated LSC sensors are still working after several years. Battery life is at least 6 months.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Arduino Nano + INA219 = cheap current scope

#13 Post by TD-er » 07 Jan 2024, 14:52

Welcome back Martinus :)

Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests