-
-
Notifications
You must be signed in to change notification settings - Fork 313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Battery monitor feature #847
base: beta
Are you sure you want to change the base?
Battery monitor feature #847
Conversation
Great job done! |
Updated Just been looking at this and all the devices listed linear regulators rather than switching regulators so are very inefficient. Will design a board with switching regulator and a voltage divider connected to the ESP8266, my aim is for a universal sensor board that can work from 12V, 5V, Battery, Solar/battery and have the option for fitting a Lora radio for the data. This will of course be open sourced. Interested? |
Thank you @DeeKey for your remarks. You are right. Battery charge is the right definition and I just was not sure. I'll try to update the code in the next few days along with the updated labels proposed by. Listen, can you send me an email in order to get in touch? I would like to discuss a few things with you. Thanks. |
"battery_last_value" isn't used anywhere. Why not sum the analogue reading straight into "battery_sum" and save a few bytes ? |
@gvidinski if it is not something which need private discussion, then better ask question on the official forum. So that others can join discussion and add valuable information: |
…BR tag befor battery settings for better UX;
…ery_analog_value' is outside of the predefined range by any circumstances;
Update Hello everyone! |
Sorry, as per discussion with core developers I had to admit that this pull request will not be accepted upstream. Thus it is better to add some i2c hardware monitor sensor than to add such a heavy and hard for ordinal user solution. Still let it be as a pull request for advanced users and hackers :) |
i am sad about considering that feature an hacker advanced user's request, but the project has space limits and i have to cope with that :). |
There are several problems with the battery system you are proposing. Firstly you are providing Vin of 5V that is stepped up from the LiPo cell or stepped down from a LiPo battery, this has loses. As Vin is a regulated 5V any measurement of Vin as apposed to the actual cell voltage is meaningless. Secondly the LDO (Low Drop Out) regulator supplying the 3.3V for the ESP8266 is dumping 33% of the chips consumption as heat. Thirdly you are powering a USB to serial chip constantly draws power. My suggestion would be to use a LiFo cell and dump the LDO regulator and serial to usb chip, use a small efficient boost converter to power the dust sensor and you are all good. |
Thanks @DeeKey for the answer! Guys, we can continue at my discussion board in order not to make it too noisy here. |
I would like to introduce to you a small feature as an addition to the main functionality. I called it “Battery monitor”. It allows you to monitor the state of the battery if UPS topology is used to power the board by showing current battery capacity percentage and its voltage which might be useful for many advanced users I believe.
The feature can be enabled through the configuration menu. When enabled user will have to enter few parameters – threshold voltage for both, the discharged [Battery U min (mV)] and the fully charged [Battery U max (mV)] state along with the maximum input voltage at the voltage divider [ADC divider U max]. In case when NodeMCU1) is used and battery voltage is greater than 3.3V user will have to add additional resistor (R1) to the monitor line, in series with the positive terminal and the A0 input of the board (Figure 1):
Figure 1.
The value of the R1 can be found by solving the following equation (1):
(1),
where R2 = 220kΩ and R3 = 100kΩ both forming the internal voltage divider provided inside the NodeMCU1) board; Vin is the voltage at the battery’s positive terminal; Vout is the maximum input voltage of the ESP8266’s 10-bits ADC which is always 1V. Internal voltage divider provides sufficient solution for input voltages ≤ 3.3V without having the need of R1 to be installed. But having for instance a Li-Polymer single cell battery we will need to be able to read voltage of at least 4.2V. For example solving equation (1) for Vin = 5V will give us a standard value for the R1 resistor of 180kΩ.
Of course there could be another approach especially if we do not have a resistor with the exact value of 180kΩ for R1 on hand but we have one with value of 155kΩ instead. By simply using the values of all the resistors in the voltage divider and solving (2):
(2),
where Vout = 1V; R1 = 155kΩ; R2 = 220kΩ; R3 = 100kΩ will give us the [ADC divider U max] value for the configuration – VinMAX = 4.75V.
The code takes into account if we build it for ESP8266 or ESP32 platform. For ESP32 platform I’ve used a definition where pin 36 (GPIO36) is selected for the battery monitor input which corresponds to the ADC1 channel 0 (ADC0) of the ESP32. (By the time I was writing this I didn’t have any available Node322 so the definition needs to be tested and eventually changed.) In this case user will have to implement his own voltage divider by using only two resistors as shown in Figure 2:
Figure 2.
Then the following equation (3) have to be used:
(3),
where Vin is the voltage at the battery positive terminal; Vout = 3.3V (the maximum meaningful input voltage for the 12-bit ADC’s analog inputs of the ESP32); R1 & R2 by your choice. Just pick large enough value in order of hundreds kilo Ohms to keep the current that will be drawn from the battery at insignificant levels. I would suggest using 220kΩ (R1) and 330kΩ (R2) standard 1% resistors. This will give readings of maximum 5.5V with small enough current draw (7.6 µA @ 4.2V).
In Table 1 are shown different solutions for different input voltage ranges for both platforms using standard resistors of 1% tolerance and will draw current as low as 10µA form the battery.
Table 1.
The UI is organized in the following manner. All the settings for the Battery monitor have to be entered form the “Configuration” page, “More settings” tab, under the “Enable battery monitor” checkbox (Figure 3.). By enabling it another three more input fields will become visible. For the Battery discharged, fully charged voltage and for the maximum input voltage at the divider (Figure 4). Then the actual battery state can be obtained at the “Device status” page in the form of “Capacity: [%]([V])” (Figure 5.).
All the measurements are done by averaging 3 consecutive readings taken in periods of 1 second, then followed by 10 seconds pause period. Also no reading will be taken during the report period, when data has to be send to the external web resources (taking into account the “send_now” state). In addition the Battery state data is added to the json result. This way users can track the state of the battery and also may develop customized battery state charts on their platforms.
Build and testing was done using the PlatformIO under the Visual Studio Code IDE following the “Contributing Guidelines”.
1) Developments boards based on ESP8266 chips – NoneMCU v2 & v3.
2) Development boards based on ESP32 chip – Node32.
3) Single cell (1S) Li-Ion or Li-Polymer 3.7V batteries (2.8V ~ 4.2V).
4) Double cell (2S) Li-Ion or Li-Polymer 7.2V battery packs (5.6V ~ 8.4V).
5) Six cell lead acid 12V battery (10.5V ~ 13.8V).
6) Four cell (4S) Li-Ion or Li-Polymer 14.4V battery packs (11.2V ~ 16.8V).