Skip to content
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

Lipo battery voltage to % remaining #1

Open
patfelst opened this issue Jul 26, 2021 · 0 comments
Open

Lipo battery voltage to % remaining #1

patfelst opened this issue Jul 26, 2021 · 0 comments

Comments

@patfelst
Copy link

Hi Volos, I'm not sure if AXP192 provides remaining battery charge, but I use this formula for estimating % remaining as a function of measured battery voltage. So you can pass this to the function below M5.Axp.GetBatVoltage();

/*
-----------------
  Returns the estimated battery capacity remaining in a LiPo battery based on its measured voltage
  According to:
    Percentage = 123 - 123 / POWER(1 + POWER(Voltage /3.7, 80), 0.165)
-----------------
*/
uint8_t lipo_capacity_percent(float voltage) {
  float percent = 123.0 - (123.0 / pow(1 + pow(voltage / 3.7, 80), 0.165));

  if (percent > 100.0) percent = 100.0;
  if (percent < 0.0) percent = 0.0;
  return (uint8_t)(round(percent));
}
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

No branches or pull requests

1 participant