LilyGO / TTGO-T-Beam

336 stars 111 forks source link

How to measure battery level? #38

Open andrecurvello opened 4 years ago

andrecurvello commented 4 years ago

Hello,

There is any example on how to measure the battery level of hte TTGO T-Beam?

Thank you.

KenADev commented 4 years ago

With v1.0+ you can query the AXP chip with: axp.getBattVoltage()/1000.0

fphammerle commented 3 years ago

tested on t-beam v1.1:

#include <Wire.h>
// https://github.com/lewisxhe/AXP202X_Library
#include <axp20x.h>

AXP20X_Class axp;

void setup() {
  // ...
  Wire.begin(21, 22);
  if(axp.begin(Wire, AXP192_SLAVE_ADDRESS) == AXP_FAIL) {
    Serial.println(F("failed to initialize communication with AXP192"));
  }
}

void loop() {
  // ...
  Serial.print(axp.getBattVoltage());
  Serial.println(" mV");
}
amalinda commented 11 months ago

Hi, is the library https://github.com/lewisxhe/AXP202X_Library no longer maintained? Would there be an alternate lib?

chinswain commented 4 months ago

Lewis has created a library for all of the power chips LilyGO use:

https://github.com/lewisxhe/XPowersLib/blob/master/examples/AXP202_Example/AXP202_Example.ino