Measure VCC

Moderators: grovkillen, Stuntteam, TD-er

Message
Author
namirda
Normal user
Posts: 53
Joined: 22 Jan 2016, 17:09

Measure VCC

#1 Post by namirda » 10 Apr 2016, 00:18

@Martinus

I've been looking though your compilation "Feature Wish List" http://www.esp8266.nu/forum/viewtopic.php?t=736 to see what I can help with.

In item number 18 you say that to measure VCC is not likely due to technical reasons or out of scope. I have just been looking into this and it is very simple indeed - I have tried it and it works really well. I could fork it myself but it requires small changes to a few routines and it is may better that such changes come from you.

a) In espeasy.ino at a suitable point after the includes add this line

ADC_MODE(ADC_VCC);

This sets the ADC to read VCC rather then an external voltage. For this reason it is necessary to have an option in the webserver/tools/advanced to switch it on or off. Also add a global variable to store the VCC values.

b) In one of the timer loops (perhaps every 30 seconds?) read the VCC value like this

float vdd = ESP.getVcc() / 1000.0;

and store it in the global variable created above.

c) Modify function parseTemplate so that it can handle something like %vcc%

That should do it. We would then be able to use VCC as a variable in our rules and displays.

Measurement of VCC in this way will be super useful to :

a) monitor VCC on local and remote OLED displays
b) Use rules to act on low voltage (connect charger via relay?)
c) send push notifications when voltage is low

What do you think?

N

Martinus

Re: Measure VCC

#2 Post by Martinus » 10 Apr 2016, 09:58

From what I've read, the ADC_MODE(ADC_VCC) command needs to be outside of any function call. This means that we can't do things like this:

Code: Select all

if (Settings.ADCVCC)
  ADC_MODE(ADC_VCC);
So it seems that the ADC_MODE can only be set at compile time because you can't conditionally run the ACD_MODE command from within a function.
That would be the "technical reason" if you can't configure this using the webgui or any other means after the firmware has been loaded onto the device.

I had planned to add the feature to the system info plugin but this limitation stopped me from developing this.

namirda
Normal user
Posts: 53
Joined: 22 Jan 2016, 17:09

Re: Measure VCC

#3 Post by namirda » 10 Apr 2016, 10:37

Thanks for replying. You're absolutely correct of course - I had not noticed that.

However it still works to do something like:

#if adcvcc == true
ADC_MODE(ADC_VCC);
#endif

and allow the user the option to set adcvcc with a #define statement at the top of the espeasy.ino.

Of course that's not quite as flexible as being able to set it at runtime but it's the best that can be done. I still think it might be a popular option even with that limitation - I suspect more folks are interested in measuring Vcc than any other analog voltage.

Isn't it very simple to implement?

N

battika
Normal user
Posts: 10
Joined: 15 May 2016, 14:17

Re: Measure VCC

#4 Post by battika » 15 May 2016, 14:24

Hello, I needed the same functionality as I'm experimenting with a solar-powered solution so I made the changes you guys discussed and opened a pull request on Github.
  • Added FEATURE_ADC_VCC to compile option with default of false
    Added new %vcc% parameter, collected twice a minute
    Added Internal VCC option to System Info device
    Enabled formula option on System Info device so that decimals can be configured
Pull request is here: https://github.com/ESP8266nu/ESPEasy/pull/36

I'm currently testing it by sending VCC data to Thingspeak every 15 minutes with deep sleep enabled and it works fine. Also hooked up an LCD display and displayed %vcc% on it for a quick test. Let me know what you think about this pull request.

JR01
Normal user
Posts: 260
Joined: 14 Feb 2016, 21:04
Location: South Africa

Re: Measure VCC

#5 Post by JR01 » 15 May 2016, 17:07

Have not tried it, but need this, thanks! I hope others agree to bring into main branch, and that it fits tue architecture. +1 !
-----------
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay, and blog https://iotplay.org. Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.

battika
Normal user
Posts: 10
Joined: 15 May 2016, 14:17

Re: Measure VCC

#6 Post by battika » 17 May 2016, 23:49

It's been working fine for me for the last two days, logging VCC to Thingspeak every 15 minutes with deep sleep enabled.

JR01
Normal user
Posts: 260
Joined: 14 Feb 2016, 21:04
Location: South Africa

Re: Measure VCC

#7 Post by JR01 » 22 May 2016, 17:41

Thanks @Battika, I see your code was now merged to main branch as well. Could you please explain how to use this?

// Enable FEATURE_ADC_VCC to measure supply voltage using the analog pin
// Please note that the TOUT pin has to be disconnected in this mode

Q1) I understand TOUT = ADC, thus no other connections to ADC.
Q2) So I assume this will work, without any other wiring required?
Q3) Will this work on an ESP01 ?
-----------
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay, and blog https://iotplay.org. Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.

battika
Normal user
Posts: 10
Joined: 15 May 2016, 14:17

Re: Measure VCC

#8 Post by battika » 24 May 2016, 01:05

Q1) I understand TOUT = ADC, thus no other connections to ADC.
Correct, when measuring internal VCC, the analog pin cannot be used - this is a chip limitation
Q2) So I assume this will work, without any other wiring required?
Correct, as long as you have FEATURE_ADC_VCC set to true and the analog pin left empty
Q3) Will this work on an ESP01 ?
Good question, I tried this on ESP07 and ESP12 so I don't really have an idea but I have an ESP01 somewhere so I can test and let you know

battika
Normal user
Posts: 10
Joined: 15 May 2016, 14:17

Re: Measure VCC

#9 Post by battika » 24 May 2016, 11:31

Just checked and it works on ESP01 as well. As the analog pin is not exposed there is even less risk of getting something wrong.

JR01
Normal user
Posts: 260
Joined: 14 Feb 2016, 21:04
Location: South Africa

Re: Measure VCC

#10 Post by JR01 » 24 May 2016, 17:06

Thank you !!!!

Last thing, you say it measures VCC 2 x per minute. Does this add lots of processing overhead in the ESP, and will it work with Deep Sleep ?
-----------
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay, and blog https://iotplay.org. Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.

User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Re: Measure VCC

#11 Post by costo » 24 May 2016, 19:41

Nice feature.

I tested this on a Sonoff wifi relais. The Sonoff has no accessable Tout pin.
Without recompiling with the ' #define FEATURE_ADC_VCC false' the reading was -1.
After recompiling with '#define FEATURE_ADC_VCC true' , doing a OTA of the new bin.file this works excellent,
showing me the Vcc of this module @ 3.47 volt . . . . NICE

battika
Normal user
Posts: 10
Joined: 15 May 2016, 14:17

Re: Measure VCC

#12 Post by battika » 26 May 2016, 21:19

Thanks for testing. You are correct, default VCC value is -1 meaning VCC cannot be read.

battika
Normal user
Posts: 10
Joined: 15 May 2016, 14:17

Re: Measure VCC

#13 Post by battika » 26 May 2016, 21:54

@JR01 I'm not sure about the overhead but I don't think it's huge. Obviously, no measurements take place in deep sleep as the chip is practically powered down. When it wakes up after the reset pin receives the signal VCC will be measured and %vcc% variable initialized in the setup loop. It works fine to me on two ESP-07's in deep sleep.

JR01
Normal user
Posts: 260
Joined: 14 Feb 2016, 21:04
Location: South Africa

Re: Measure VCC

#14 Post by JR01 » 27 May 2016, 08:19

Thank you @battika, well done with VCC implementation!
-----------
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay, and blog https://iotplay.org. Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.

BertB
Normal user
Posts: 1049
Joined: 25 Apr 2015, 14:39

Re: Measure VCC

#15 Post by BertB » 27 May 2016, 21:57

I have VCC read activated on several ESPs 12 and get weird readings, varying from 1.71 to 2.96 volts.
Am I missing something?

User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Re: Measure VCC

#16 Post by costo » 27 May 2016, 23:10

BertB wrote:I have VCC read activated on several ESPs 12 and get weird readings, varying from 1.71 to 2.96 volts.
Am I missing something?
The first thing I would think of is that your powersupply is not smooth enough and/or cannot deliver the peak-current for the ESP-12.
I would try to connect an extra capacitor of 470 to 1000 uF over the 3.3V and see if that helps.

BertB
Normal user
Posts: 1049
Joined: 25 Apr 2015, 14:39

Re: Measure VCC

#17 Post by BertB » 29 May 2016, 17:25

Nah, don't think so.
I have plenty of capacitors there.

Seems that the analog pin is still affected by external voltage.
After removing the resistors that made up a voltage divider, the problem was gone.

Thanks for thinking with me.

BertB
Normal user
Posts: 1049
Joined: 25 Apr 2015, 14:39

Re: Measure VCC

#18 Post by BertB » 29 May 2016, 18:45

Nah, don't think so.
I have plenty of capacitors there.

Seems that the analog pin is still affected by external voltage.
After removing the resistors that made up a voltage divider, the problem was gone.

Thanks for thinking with me.

JJussi
New user
Posts: 6
Joined: 10 Jun 2016, 09:25
Location: Helsinki, Finland

Re: Measure VCC

#19 Post by JJussi » 15 Jun 2016, 08:52

One thing what is too against adding internal Vcc measure.. I noticed that if I put

#define INTERNAL_VCC_READ 1 // Disable ADC and use it for Vcc reading

#if INTERNAL_VCC_READ
ADC_MODE(ADC_VCC);
#endif

It will break MQTT (at least with 2.2.0). :cry:
So, like others what want to read battery level, I need to create gate with two resistors 220k and 1000k connecting it to ADC
JJussi

User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Re: Measure VCC

#20 Post by costo » 19 Jun 2016, 00:44

BertB wrote:Nah, don't think so.
I have plenty of capacitors there.

Seems that the analog pin is still affected by external voltage.
After removing the resistors that made up a voltage divider, the problem was gone.

Thanks for thinking with me.
I tested this feature with a NodeMCU board which has a onboard voltage divider of 220k from input to ADCpin and 100 k from ADCpin to ground. The reading is stable but it is always 10% too low, so instead of removing the resistive devider, I made an optional setting for the Input VCC reading %value%*1.11 and now I have a good reading.

Now I have difficulty to display this reading on an OLED display.
I use this line " Vcc: [System Info#Vcc] " but only Vcc: is on the display, no actual value is displayed.

Someone has managed to get the System Info - Vcc on a display ?
edit: used here R107
JJussi wrote: So, like others what want to read battery level, I need to create gate with two resistors 220k and 1000k connecting it to ADC
I believe you mean 220k and 100k , 1000k is a zero too much.

JR01
Normal user
Posts: 260
Joined: 14 Feb 2016, 21:04
Location: South Africa

Re: Measure VCC ~ issues.....

#21 Post by JR01 » 22 Jun 2016, 00:00

Hi batikka, finally got around to test the VCC.

I have major issues if I compile r107 with #define FEATURE_ADC_VCC = true. When I switch a relay on with http://192.168.2.65/control?cmd=GPIO,2,1 - it hangs the ESP.

Any ideas?
-----------
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay, and blog https://iotplay.org. Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.

User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Re: Measure VCC

#22 Post by costo » 28 Jun 2016, 19:24

I have tested this feature on a WeMos D1 mini and it is working as on every ESP8266 I have seen so far.

WeMos has, just as the NodeMCU board, 2 resistors on the ADC/Tout pin, 100k to ground and 220k to the external ADC pin.
This means the ADC is always loaded with 100k which is not allowed when measuring VCC-internal. It results in a measured value being about 10% too low. Correction it is easy, in Optional Settings the field Formula needs this formula: %value%*1.1

Also I found that on a sonoff, where nothing is connected on the chip's ADC/Tout pin that the measured voltage is about 5% too high. measuring with a multimeter on the powersupply it is 3.32 but in espeasy this value is shown as 3.50 which is about 5% too high.

Assumed that my multimeter is still within 0.5% accurate.
This means that the internal measuring is 5% inaccurate, probably the ESP8266 internal voltage reference is not accurate enough.

I think this must be a warning to everyone not to trust the Vcc reading very much as there is a sizeble inaccuracy in the measurement. (5% is notable)

JJussi
New user
Posts: 6
Joined: 10 Jun 2016, 09:25
Location: Helsinki, Finland

Re: Measure VCC

#23 Post by JJussi » 06 Jul 2016, 09:05

JJussi wrote: So, like others what want to read battery level, I need to create gate with two resistors 220k and 1000k connecting it to ADC
I believe you mean 220k and 100k , 1000k is a zero too much.
Nope.. ADC measures 0 to 1V, so building:

Code: Select all

GND --<===>--|--<===>-- 4.2V LiPo battery
      220K   |  1000K
            ADC
gives me 1/4,54 ration, so max V measured at ADC is 0.924V
JJussi

User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Re: Measure VCC

#24 Post by costo » 06 Jul 2016, 17:21

JJussi wrote: Nope.. ADC measures 0 to 1V, so building:

Code: Select all

GND --<===>--|--<===>-- 4.2V LiPo battery
      220K   |  1000K
            ADC
gives me 1/4,54 ration, so max V measured at ADC is 0.924V
:o

That's not correct ;)
The ratio is 220/(220+1000) = (1/5.55) = 0.18 so when measuring a 4.2V cel it will read 0.76 Volt.

On the other hand, when measuring a battery and you do all the tricks to keep power consumption at minimum, (removing Led's and using deep sleep) it may be a good idea to use high value resistors like (not 220k but) 270k and 1000k so the current is less than 4 micro Amp.

User avatar
beic
Normal user
Posts: 142
Joined: 18 Aug 2016, 18:19

Re: Measure VCC

#25 Post by beic » 19 Sep 2016, 22:38

I have a question, about System Info plugin for Input VCC.

Why is it always showing me -1.00 value?

Thank you!

User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Re: Measure VCC

#26 Post by costo » 20 Sep 2016, 00:07

You need to compile the source code yourself with the FEATURE_ADC_VCC set to true.

You will see this part in the main body of the source at around line 113 to 119
// Enable FEATURE_ADC_VCC to measure supply voltage using the analog pin
// Please note that the TOUT pin has to be disconnected in this mode
// Use the "System Info" device to read the VCC value
#define FEATURE_ADC_VCC false

You must change the false to true save it and compile and flash your ESP with the new code than your system_info_Vcc will give the approximate Voltage.

User avatar
beic
Normal user
Posts: 142
Joined: 18 Aug 2016, 18:19

Re: Measure VCC

#27 Post by beic » 20 Sep 2016, 01:11

costo wrote:You need to compile the source code yourself with the FEATURE_ADC_VCC set to true.

You will see this part in the main body of the source at around line 113 to 119
// Enable FEATURE_ADC_VCC to measure supply voltage using the analog pin
// Please note that the TOUT pin has to be disconnected in this mode
// Use the "System Info" device to read the VCC value
#define FEATURE_ADC_VCC false

You must change the false to true save it and compile and flash your ESP with the new code than your system_info_Vcc will give the approximate Voltage.
Aha, thank you for quick info, but unfortunately I'm using the ESP-01, so, it has no ADC pin!

For this reason I ordered a few INA219 sensor. ;)

User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Re: Measure VCC

#28 Post by costo » 20 Sep 2016, 20:11

System info Vcc measures the Vcc inside the ESP8266 chip and it is beneficial if the ADC is not connected to the outside world.
If you want to measure any voltage , but not the Vcc then you indeed need a INA219 for the ESP-01, also you do not need to set the #define FEATURE_ADC_VCC to true because this setting is only used to measure the on_chip Vcc

User avatar
beic
Normal user
Posts: 142
Joined: 18 Aug 2016, 18:19

Re: Measure VCC

#29 Post by beic » 20 Sep 2016, 23:41

costo wrote:System info Vcc measures the Vcc inside the ESP8266 chip and it is beneficial if the ADC is not connected to the outside world.
If you want to measure any voltage , but not the Vcc then you indeed need a INA219 for the ESP-01, also you do not need to set the #define FEATURE_ADC_VCC to true because this setting is only used to measure the on_chip Vcc
Yes, I wanted to measure the ESP8266 power usage and voltage, so if I change the FEATURE_ADC_VCC to true and recompile it, then it will show me correct "Input VCC" in the System Info plugin?

Thank you! ;)

f-fish
New user
Posts: 9
Joined: 19 Sep 2016, 04:11
Location: Johannesburg - RSA
Contact:

Re: Measure VCC

#30 Post by f-fish » 21 Sep 2016, 03:32

Correct ...

Device:
Edit 1 System Info VCC 1156 VCC:3.33

This is on Build 120 own compile with #define FEATURE_ADC_VCC true

Esp-01 - timer for a dettol soap dispenser, that is now used as a 1,4ml dosing pump for liquid fertz on an aquarium.

Power is from the 12 volt LED lights - but step-down to 3.33 via a MP2307 DC-DC Switching Buck Step-Down Module .

Later Ferdie

User avatar
beic
Normal user
Posts: 142
Joined: 18 Aug 2016, 18:19

Re: Measure VCC

#31 Post by beic » 21 Sep 2016, 09:07

f-fish wrote:Correct ...

Device:
Edit 1 System Info VCC 1156 VCC:3.33

This is on Build 120 own compile with #define FEATURE_ADC_VCC true

Esp-01 - timer for a dettol soap dispenser, that is now used as a 1,4ml dosing pump for liquid fertz on an aquarium.

Power is from the 12 volt LED lights - but step-down to 3.33 via a MP2307 DC-DC Switching Buck Step-Down Module .

Later Ferdie
Thank you for your quick answer! ;)

marcfon
Normal user
Posts: 11
Joined: 17 Sep 2016, 10:50

Re: Measure VCC

#32 Post by marcfon » 02 Oct 2016, 10:12

costo wrote: WeMos has, just as the NodeMCU board, 2 resistors on the ADC/Tout pin, 100k to ground and 220k to the external ADC pin.
This means the ADC is always loaded with 100k which is not allowed when measuring VCC-internal. It results in a measured value being about 10% too low. Correction it is easy, in Optional Settings the field Formula needs this formula: %value%*1.1
I'm powering a WeMos D1 mini directly on the 5v pin via a 18650 Li-Ion battery. Using this setup the VCC shows 2.77v while it's actually around 4.2v (full battery). So it looks that I need to apply this multiplier: 5v/3.3v = 1.51. This yields 2.77v * 1.51 = 4.18v which seems quite right. Just wanted to check here if my assumptions are correct.

BertB
Normal user
Posts: 1049
Joined: 25 Apr 2015, 14:39

Re: Measure VCC

#33 Post by BertB » 02 Oct 2016, 10:43

Correct, I guess, but what are you actually meassuring?
I mean, VCC will not change, until the voltage of your battery drops under the threshold voltage of the regulator on the WEMOS.
The battery could then be damaged because of deep discharge.

marcfon
Normal user
Posts: 11
Joined: 17 Sep 2016, 10:50

Re: Measure VCC

#34 Post by marcfon » 02 Oct 2016, 13:29

BertB wrote:Correct, I guess, but what are you actually meassuring?
I mean, VCC will not change, until the voltage of your battery drops under the threshold voltage of the regulator on the WEMOS.
The battery could then be damaged because of deep discharge.
Well I enabled FEATURE_ADC_VCC so I though it would measure the voltage of the battery? Is that correct?

The wemos somehow shut down while the battery was still at 3.2v. I'm using batteries with internal voltage protection to prevent a too deep discharge.

User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Re: Measure VCC

#35 Post by costo » 02 Oct 2016, 15:41

@ marcfon

You do not seem to understand the concept of a WeMos. ALL ESP8266 chips work inside at a voltage between 3 to 3.6 Volt (preferrable 3.3V). Therefor the WeMos has a voltage regulator that makes 3.3V out of 5V. If you want to use a LiIon battery and a WeMos you probably best use a voltage booster that boosts the battery voltage to 5V.
like these https://www.aliexpress.com/item/DC-DC-V ... ca0177f5ea then feed the WeMos with this at the 5V input.

If you want to measure the voltage of the LiIon battery you need to use the ADC input of the WeMos (labeled as A0) You do not need to enable the #define FEATURE_ADC_VCC true because this feature will measure the inner supply voltage of the ESP-chip, which is NOT the battery voltage.
If you use the "Analog Input" device and connect a resistor of 100k between A0 and the battery+ you can measure the battery_voltage after applying a correction for the resistor divider and the 10bit ADC output. The "Formula Analog" will look like this: %value%*4.2/1024

marcfon
Normal user
Posts: 11
Joined: 17 Sep 2016, 10:50

Re: Measure VCC

#36 Post by marcfon » 02 Oct 2016, 16:58

costo wrote:@ marcfon

You do not seem to understand the concept of a WeMos. ALL ESP8266 chips work inside at a voltage between 3 to 3.6 Volt (preferrable 3.3V). Therefor the WeMos has a voltage regulator that makes 3.3V out of 5V. If you want to use a LiIon battery and a WeMos you probably best use a voltage booster that boosts the battery voltage to 5V.
like these https://www.aliexpress.com/item/DC-DC-V ... ca0177f5ea then feed the WeMos with this at the 5V input.

If you want to measure the voltage of the LiIon battery you need to use the ADC input of the WeMos (labeled as A0) You do not need to enable the #define FEATURE_ADC_VCC true because this feature will measure the inner supply voltage of the ESP-chip, which is NOT the battery voltage.
If you use the "Analog Input" device and connect a resistor of 100k between A0 and the battery+ you can measure the battery_voltage after applying a correction for the resistor divider and the 10bit ADC output. The "Formula Analog" will look like this: %value%*4.2/1024
Thanks for clearing some things up!

I actually considered using a step-down converter to go from the 18650 3.7v to a constant 3.3v and connect that to the 3.3v pin on the wemos. The reason why I didn't go for this is that I read that the wemos 5v pin accepts anything between 5v-3.6v so why adding the step down converter that would just eat more battery. But it's no problem to still do that. Is that something you'd recommend?

My misconception of FEATURE_ADC_VCC came from misinterpreting the description "Enable FEATURE_ADC_VCC to measure supply voltage". I didn't know the difference between the inner supply voltage and the voltage that is actually connected to the 3.3v or 5v pin. So the voltage you get by enabling FEATURE_ADC_VCC is the voltage that the ESP chip is fed after the voltage has been converted from let's say 3.7 or 4.2v? If this is the case I don't understand why the current reading I'm getting while having FEATURE_ADC_VCC enabled is 2.77v which doesn't seem to be the voltage that the ESP chip is running on.

I'm still learning that's for sure :)

User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Re: Measure VCC

#37 Post by costo » 02 Oct 2016, 18:05

The "FEATURE_ADC_VCC" gives results that are ambigious to interpret.
When the ADC pin is left open, so without any resistor connected to that pin, I get readings between 3.17 and 3.22 volt while the voltage on the ESP8266 chip is 3.3 volt.
When there is a resistor connected to the ADC_pin , like the 100k to ground as on the NodeMCU and WEMOS boards, the values with this feature enabled are more like 2.7 volt.
So the use of this feature is limited and inaccurate.

marcfon
Normal user
Posts: 11
Joined: 17 Sep 2016, 10:50

Re: Measure VCC

#38 Post by marcfon » 02 Oct 2016, 20:23

costo wrote:If you want to measure the voltage of the LiIon battery you need to use the ADC input of the WeMos (labeled as A0) You do not need to enable the #define FEATURE_ADC_VCC true because this feature will measure the inner supply voltage of the ESP-chip, which is NOT the battery voltage.
If you use the "Analog Input" device and connect a resistor of 100k between A0 and the battery+ you can measure the battery_voltage after applying a correction for the resistor divider and the 10bit ADC output. The "Formula Analog" will look like this: %value%*4.2/1024
Just made this setup. Added 100k resistor, FEATURE_ADC_VCC false, Analog Input, formula = %value%*4.2/1024... works great! Gives me exactly the same reading as my multimeter. Thanks costo!

adrianmihalko
Normal user
Posts: 51
Joined: 15 Sep 2016, 00:20

Re: Measure VCC

#39 Post by adrianmihalko » 03 Oct 2016, 21:48

Hi,

So...how do I actually measure voltage on Wemos D1 mini with ESP Easy?

"WeMos has, just as the NodeMCU board, 2 resistors on the ADC/Tout pin, 100k to ground and 220k to the external ADC pin.
This means the ADC is always loaded with 100k which is not allowed when measuring VCC-internal. It results in a measured value being about 10% too low. Correction it is easy, in Optional Settings the field Formula needs this formula: %value%*1.1"

Someone says that there is already a resistor on the ADC pin in Wemos D1, the other post says I need a 100k resistor.

marcfon
Normal user
Posts: 11
Joined: 17 Sep 2016, 10:50

Re: Measure VCC

#40 Post by marcfon » 03 Oct 2016, 21:54

hpapagaj wrote:Someone says that there is already a resistor on the ADC pin in Wemos D1, the other post says I need a 100k resistor.
It depends on what you want to measure. If you want to measure the voltage of a battery that is powering your wemos you need add the 100k resistor between the batt+ and analog pin in order to create a voltage divider. This enables you to measure the voltage at the point between the two 100k resistors.

adrianmihalko
Normal user
Posts: 51
Joined: 15 Sep 2016, 00:20

Re: Measure VCC

#41 Post by adrianmihalko » 03 Oct 2016, 22:06

Thanks, I am going to play with it. ;)

User avatar
beic
Normal user
Posts: 142
Joined: 18 Aug 2016, 18:19

Re: Measure VCC

#42 Post by beic » 03 Oct 2016, 22:13

It's a bit off-topic, but it's VCC measurement related question...

I got today my INA219 and I hooked up to my ESP-01 with all other i2c sensors, but...

I tough that the INA219 will show me all three measurement values like Current and Power too in the "Devices" page.

Image

Am I missing something here or I just miss see it somewhere that it will show me all three values? :oops:

Thank you for your answer! ;)

adrianmihalko
Normal user
Posts: 51
Joined: 15 Sep 2016, 00:20

Re: Measure VCC

#43 Post by adrianmihalko » 04 Oct 2016, 20:13

I can't find any 100k resistor around. What else value it can be? I have 91K resistors for example.

BertB
Normal user
Posts: 1049
Joined: 25 Apr 2015, 14:39

Re: Measure VCC

#44 Post by BertB » 04 Oct 2016, 23:08

hpapagaj wrote:I can't find any 100k resistor around. What else value it can be? I have 91K resistors for example.
With the 100k resistor the full range reading of the ADC would have been 4.2 volts.
When you have a 180k resistor in stead, you can have a full range reading of 5 volts.
So, just put two 91k resistors in series between battery + and A0 and change the formula to %value%*5/1023

adrianmihalko
Normal user
Posts: 51
Joined: 15 Sep 2016, 00:20

Re: Measure VCC

#45 Post by adrianmihalko » 04 Oct 2016, 23:53

Thanks, I found some more resistors, connected in series and final value is ca. 106K. How did you calculated the formula value/voltage? I am not an electric engineer, but I am interested. :)

At least it works well and I got value 3.43V from my 18650 battery.

BertB
Normal user
Posts: 1049
Joined: 25 Apr 2015, 14:39

Re: Measure VCC

#46 Post by BertB » 05 Oct 2016, 09:28

hpapagaj wrote:Thanks, I found some more resistors, connected in series and final value is ca. 106K. How did you calculated the formula value/voltage? I am not an electric engineer, but I am interested. :)

At least it works well and I got value 3.43V from my 18650 battery.
First you need to understand that a ESP8266 has a 10 bit ADC on board that can measure DC tensions of 1 Volt maximum.
The value that you then see ranges between 0 at 0 volt and 1023 (2^10 - 1) at 1 volt.
To enlarge the range, a voltage divider is required. I just made an article on that in the Wiki. It can be found here http://www.esp8266.nu/index.php/DC_Voltage_divider
With the formula you can calculate the voltages and resistors.
NodeMCU and Wemos D1 mini already have a divider in place that allows to measure up to 3.2 volt. To enlarge that further, you will need an additional resistor.

Then the formula in the ESPEasy. %value%/1023 gives you a value that is proportional with the measured tension. When you multiply that with the maximum voltage to be measured, 4.2 or 3.2 or 5, you gat a reading that is in an accurate representation of the measured tension.

Martinus

Re: Measure VCC

#47 Post by Martinus » 08 Oct 2016, 11:13

beic wrote:It's a bit off-topic, but it's VCC measurement related question...

I got today my INA219 and I hooked up to my ESP-01 with all other i2c sensors, but...

I tough that the INA219 will show me all three measurement values like Current and Power too in the "Devices" page.

Image

Am I missing something here or I just miss see it somewhere that it will show me all three values? :oops:

Thank you for your answer! ;)
It was designed for Domoticz that can handle only single value custom sensors. But you can run several tasks on the same module and select a different reading on each task.

User avatar
beic
Normal user
Posts: 142
Joined: 18 Aug 2016, 18:19

Re: Measure VCC

#48 Post by beic » 08 Oct 2016, 13:57

Martinus wrote: It was designed for Domoticz that can handle only single value custom sensors. But you can run several tasks on the same module and select a different reading on each task.
It would be really nice to see all 3 values in the ESPEasy Web GUI and to send desired value to Domoticz.

And how can I do that "But you can run several tasks on the same module and select a different reading on each task."?!

Some documentation would be greatly appreciated!

Thank you! ;)

adrianmihalko
Normal user
Posts: 51
Joined: 15 Sep 2016, 00:20

Re: Measure VCC

#49 Post by adrianmihalko » 10 Nov 2016, 18:45

adrianmihalko wrote:Thanks, I found some more resistors, connected in series and final value is ca. 106K. How did you calculated the formula value/voltage? I am not an electric engineer, but I am interested. :)

At least it works well and I got value 3.43V from my 18650 battery.
Back to my question for a while. With my multimeter I measured again the resistors value, and they are ca. 113K.

With current formula: %value%*4.2/1024 I get 3.60V in ESP Easy, however I measured 4.04V with my multimeter at the input. So...what's the truth?

User avatar
costo
Normal user
Posts: 500
Joined: 21 Nov 2015, 15:03
Location: NL, zw-NB

Re: Measure VCC

#50 Post by costo » 12 Nov 2016, 02:52

adrianmihalko wrote:
With current formula: %value%*4.2/1024 I get 3.60V in ESP Easy, however I measured 4.04V with my multimeter at the input. So...what's the truth?
Your multimeter will be close to the truth. Assumed your multimeter is good it will usually be better than +/- 1% accurate in the voltage range.

If your multimeter says 4.04V and ESPEasy say 3.60V while using the formula %value%*4.2/1024 ....... you need to adjust the formula, multiplying it by 4.04 and deviding it by 3.60 .
So the formula for your situation must not be %value%*4.2/1024 but should be %value%*4.71/1024

Other situations may require a different formula. Reason is because of the different resistor values/tolerances and also because the AD converter in the ESP seems not to be calibrated.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 3 guests