Skip to content

Conversation

@luigi311
Copy link

@luigi311 luigi311 commented Dec 4, 2025

This adds battery chemistry type mapping for more accurate battery percentage to be calculated for companion devices. It also adds in the battery percentage as a number in the sensor screen on the companion ui-new.

This is similar to the approach used by meshtastic and i think its one of the easy ways to handle this without bloating the memory usage as only a single OCV table needs to be loaded in at a time, li-ion is used by default since most devices use that. Using a similar approach to meshtastic and using the same table definition should also allow for easy collaboration down the line for these curves, say a new device is released and its got a new battery chemistry or a funky curve, either meshtastic or meshcore can do the initial implementation and the OCV_ARRAY should be able to be copied over between the two projects.

It can be changed in the variants.h file for devices in case some devices come from the factory with a different chemistry type by setting
-D CELL_TYPE_LIFEPO4=1

It should also allow variants to define their own curve with the OCV_ARRAY build flag with their own 11 values map.

This will not impact the percentages displayed from the mobile app side as that uses its own calculations for it from my understanding and that probably always maps over to li-ion curve so it either needs to be updated to pull battery percentage from the device that way it uses the correct chemistry curve automatically or meshcore needs to broadcast the chemistry type externally so the app can chose the correct curve.

For now i left it out of the main meshcore code and only used it in the ui but it should hopefully be easy to add in everywhere else and use it instead voltages so it does certain tasks when percentage thresholds are reached such as shutting down at X percentage.

This also adds a NUM_CELLS_IN_SERIES build flag that defaults to 1 that way it brings the pack voltage down to an averaged cell value to be used for the mapping. This is untested though as i only have the t-echo with the single cell.

I only have t-echo devices for now so this was only tested two t-echos to compare the before and after % so it probably needs to be tested by other devices and other chemistry types to see if its calculating the percentages correctly.

Inspired by #413
Fixes #1124 #398

@luigi311
Copy link
Author

luigi311 commented Dec 4, 2025

Heres what it looks like with this change on the t-echo, left is with the change, right is with the current linear calculation

image

Here is also what all the battery voltages -> SoC look like when graphed out

battery_plot

@luigi311
Copy link
Author

luigi311 commented Dec 4, 2025

@jbrazio since it seemed like you were the most involved person with reviews on the 413 implementation.

@luigi311 luigi311 changed the base branch from main to dev December 4, 2025 02:24
…tery chemistry mapping

Signed-off-by: Luis Garcia <git@luigi311.com>
…r battery percentage calculations and add it to the sensors page

Signed-off-by: Luis Garcia <git@luigi311.com>
@luigi311
Copy link
Author

luigi311 commented Dec 4, 2025

accidently built this on top of main, has been retargeted to dev and rebased

…ltage to a single cell version

Signed-off-by: Luis Garcia <git@luigi311.com>
@jbrazio
Copy link
Contributor

jbrazio commented Dec 9, 2025

@luigi311 very well implemented. 👏

I added some comments for brainstorming if it would make sense to decouple the battery properties from the boards, as almost none of them have a battery standard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add option to change battery type/chemistry to LiFePo4

2 participants