ESP32_Bat_Pro and esphome

Schematics, Example Code and Q&A
boverby
Posts: 4
Joined: Sun Apr 04, 2021 8:06 am

ESP32_Bat_Pro and esphome

Unread post by boverby »

Just received two of these. Starting to kick the tires. Still haven't gotten use to how little current these use in deepsleep.<good stuff>

I typically use esphome but they don't have component code for the LC709203F yet. I modified the code provided at https://github.com/EzSBC/ESP32_Bat_Pro/ ... 09203F.zip to make it look like other components at esphome.

example output so far:

Code: Select all

captured with mosquitto_sub  -F "%I %t %p" -v -t ezmin/debug
...
2021-04-04T11:38:24-0400 ezmin/debug [C][lc709203f.sensor:119]: LC709203F:
2021-04-04T11:38:24-0400 ezmin/debug [C][lc709203f.sensor:120]:   Address: 0x0B
2021-04-04T11:38:24-0400 ezmin/debug [C][lc709203f.sensor:126]:   Update Interval: 30.0s
2021-04-04T11:38:24-0400 ezmin/debug [C][lc709203f.sensor:128]:   Cell Voltage 'ezmin battery V'
2021-04-04T11:38:24-0400 ezmin/debug [C][lc709203f.sensor:128]:     Unit of Measurement: 'V'
2021-04-04T11:38:24-0400 ezmin/debug [C][lc709203f.sensor:128]:     Accuracy Decimals: 2
2021-04-04T11:38:24-0400 ezmin/debug [C][lc709203f.sensor:129]:   Cell Rem Pct 'ezmin battery lvl'
2021-04-04T11:38:24-0400 ezmin/debug [C][lc709203f.sensor:129]:     Unit of Measurement: '%'
2021-04-04T11:38:24-0400 ezmin/debug [C][lc709203f.sensor:129]:     Accuracy Decimals: 1
2021-04-04T11:38:24-0400 ezmin/debug [C][lc709203f.sensor:130]:   Cell StateCharge 'ezmin cell charge'
2021-04-04T11:38:24-0400 ezmin/debug [C][lc709203f.sensor:130]:     Unit of Measurement: '%'
2021-04-04T11:38:24-0400 ezmin/debug [C][lc709203f.sensor:130]:     Accuracy Decimals: 0
2021-04-04T11:38:24-0400 ezmin/debug [C][lc709203f.sensor:131]:   IC version 'ezmin ic'
2021-04-04T11:38:24-0400 ezmin/debug [C][lc709203f.sensor:131]:     Unit of Measurement: ''
2021-04-04T11:38:24-0400 ezmin/debug [C][lc709203f.sensor:131]:     Accuracy Decimals: 0
...
2021-04-04T11:38:42-0400 ezmin/debug [D][lc709203f.sensor:092]: Got Battery values: cellVoltage_mV=4149 cellRemainingPercent10=964 cellStateOfCharge=96 ic=0x2717
2021-04-04T11:38:42-0400 ezmin/debug [D][sensor:092]: 'ezmin battery V': Sending state 4.14900 V with 2 decimals of accuracy
2021-04-04T11:38:42-0400 ezmin/debug [D][sensor:092]: 'ezmin battery lvl': Sending state 96.40000 % with 1 decimals of accuracy
2021-04-04T11:38:42-0400 ezmin/debug [D][sensor:092]: 'ezmin ic': Sending state 10007.00000  with 0 decimals of accuracy
2021-04-04T11:38:42-0400 ezmin/debug [D][sensor:092]: 'ezmin cell charge': Sending state 96.00000 % with 0 decimals of accuracy
2021-04-04T11:39:23-0400 ezmin/debug [I][deep_sleep:067]: Beginning Deep Sleep
This is an encouraging start

===============================================
==== Required code changes: ===================
===============================================
revised [ESPHOME]/custom_components/lc709203f/lc709203f.h
revised [ESPHOME]/custom_components/lc709203f/lc709203f.cpp
revised [ESPHOME]/custom_components/lc709203f/sensor.py


===============================================
====== add stanza to yaml for RGB led =======
===============================================

Code: Select all

switch:
  - platform: gpio
    pin:
      number: GPIO16
      inverted: true
    name: "${devicename} ledr"
    id:  ${devicename}_ledr
  - platform: gpio
    pin:
      number: GPIO17
      inverted: true
    name: "${devicename} ledb"
    id:  ${devicename}_ledb
  - platform: gpio
    pin:
      number: GPIO18
      inverted: true
    name: "${devicename} ledg"
    id:  ${devicename}_ledg

===============================================
==== add stanza to yaml for fuel gauge ======
===============================================

Code: Select all

 - platform: lc709203f
    address: "0x0B"
    i2c_id: bus_a
    battery_voltage:
      name: "${devicename} battery V"
    battery_level:
      name: "${devicename} battery lvl"
    icversion:
      name: "${devicename} ic"
    cell_charge:
      name: "${devicename} cell charge"
    update_interval: 30s

Next up is tackling changes for setPowerMode, setCellCapacity, setCellProfile ( to replace hard coded setup )


Any advice or warnings, I'm all ears. I'm especially interested if someone has already been down this path.
Daniel
Posts: 133
Joined: Tue Nov 13, 2012 2:10 pm

Re: ESP32_Bat_Pro and esphome

Unread post by Daniel »

Nothing that I can think of. Thanks for publishing the code. Everything helps

I'm very interested in knowing how well the remaining capacity corresponds to remaining runtime. I did some tests but its a very slow process and I would like to see some data for cases where the average current drain is low. To speed up testing I added some artificial load.
boverby
Posts: 4
Joined: Sun Apr 04, 2021 8:06 am

Re: ESP32_Bat_Pro and esphome

Unread post by boverby »

I was intrigued that you mentioned "Remaining capacity vs runtime". Short of running until it wont exec, I interpret runtime as the span from 100% charge to ~20% charge. These are approx 4.2v to 3.73v

I took one board last night and set clock at 80, turned off deep sleep, turned on all RGB leds and set mqtt sensor refresh to 30 seconds between readings. I had a perl program collect values every 5 minutes overnight. The battery was not fully charged (cannot seem to get them up to 4.2 v).
Screenshot 2021-04-07 092420.png
I see several "stairsteps" overnight. I wonder if that is the LC709203F performing some sort of calibration.

I have traditionally used the chart at https://blog.ampow.com/lipo-voltage-chart/ to estimate capacity.
Last readings were 09:45AM > 3.85v -> 53% cellRemaingPct -> 55% from chart at ampow

one test might not represent performance, so I'll probably repeat these to look around.
boverby
Posts: 4
Joined: Sun Apr 04, 2021 8:06 am

Re: ESP32_Bat_Pro and esphome

Unread post by boverby »

finished the discharge/ charge cycle, chart enclosed
Discharge stopped at 3.7v across battery with my voltmeter (about 0.4v below LC709203F). Just plugged into usb hub to recharge (4.68v at Vin).
I also recorded the "offset bias" after reaching full charge. If it were a PID controller it would be overshoot and negative steady state error.
LC709203F agreed with voltmeter at 4.18v
Screenshot 2021-04-08 082820.png
raw data https://pastebin.com/9EBdXWK2 in pipe delim form

next up is full clock test
boverby
Posts: 4
Joined: Sun Apr 04, 2021 8:06 am

Re: ESP32_Bat_Pro and esphome

Unread post by boverby »

last test finished
240mhz clock, sensors refreshed mqtt every 30 seconds, perl script read every 5 minutes
Screenshot 2021-04-09 193939.png

Code: Select all

80mhz
v     pct  time                   epoch         elapsed
4.09   88  2021-04-06T17:40:02    1617745202
3.70   35  2021-04-07T22:05:01    1617847501   102,299   = 28.41 hours = 10.16 hrs longer = 56% longer
0.39   53  

240mhz
v     pct  time                   epoch         elapsed
4.08   87  2021-04-08T12:10:01    1617898201
3.76   35  2021-04-09T06:25:01    1617963901     65700   = 18.25 hours
voltage measurements above 25% rsoc tracked, but voltages measured by hand below 25% were typically lower than reported.
Just before plugging in the charger, I got values about 0.04v lower than the fuel gauge reported. This means
the fuel gauge was reporting a remaining capacity higher than the voltage indicated. This might not be an
error. It might just be the algo is more realistic than a simple voltage lookup table.

I'm think i'm trying to find a battery capacity that allows "3 dark days < 50% battery capacity"

btw, I also pushed my esphome modification of your code to github : https://github.com/boverby/lc709203f

Just drop it into the [esphome]/custom_component directory and modify LC709203FComponent::setup() routine to match your battery
Post Reply