m5stack / M5StickC

M5StickC Arduino Library
MIT License
477 stars 222 forks source link

GetCoulombData doesn't appear to work - always returns 0 #143

Closed KevWal closed 3 years ago

KevWal commented 3 years ago

Hi

In my code I call EnableCoulombcounter() in setup(), and then call and print M5.Axp.GetCoulombData() each time around loop(), but it doesn't appear to work - it always returns 0.

Another person points out the issue here: https://forum.m5stack.com/topic/2434/axp192-coulomb-counter-issues

Thanks Kevin

Tinyu-Zhao commented 3 years ago

Now they can work normally

image
#include <M5StickC.h>

long loopTime, startTime = 0;
uint8_t sleep_count = 0;

void setup() {
    // put your setup code here, to run once:
    M5.begin();
    M5.Lcd.setRotation(3);
    M5.Lcd.fillScreen(WHITE);
    M5.Lcd.setTextColor(BLACK, WHITE);
    M5.Axp.EnableCoulombcounter();
}

void loop() {
    loopTime = millis();
    if(startTime < (loopTime - 5000))
    {
        if(M5.Axp.GetWarningLevel())
        {
            sleep_count++;
            M5.Lcd.fillScreen(WHITE);
            M5.Lcd.setCursor(0, 20, 2);
            M5.Lcd.setTextColor(RED, WHITE);
            M5.Lcd.printf("Warning: low battery");
            //delay(3000);
            if(sleep_count >= 2)
            {
                sleep_count = 0;
                M5.Axp.SetSleep();
            }
        }
        else
        {
            M5.Lcd.fillScreen(WHITE);
        }
        startTime = loopTime;
    }

    M5.Lcd.setCursor(0, 0, 1);
    M5.Lcd.setTextColor(BLACK, WHITE);
    M5.Lcd.printf("vbat:%.3fV\r\n", M5.Axp.GetBatVoltage());
    M5.Lcd.printf("aps:%.3fV\r\n", M5.Axp.GetAPSVoltage());
    M5.Lcd.printf("level:%d\r\n", M5.Axp.GetWarningLevel());
    Serial.printf("GetCoulombData:%f\n",M5.Axp.GetCoulombData());
    Serial.printf("GetCoulombchargeData:%d\n",M5.Axp.GetCoulombchargeData());
    Serial.printf("GetCoulombdischargeData:%d\n\n",M5.Axp.GetCoulombdischargeData());
    delay(500);
}
Tinyu-Zhao commented 3 years ago

If you successfully run this function, please allow me to close this issue