Measure battery level - htcc-ab01

Hello guys,

I would like to know what is the meaning of the battery lvl from cubecell

I’m measuring using your code:

pinMode(VBAT_ADC_CTL,OUTPUT);
digitalWrite(VBAT_ADC_CTL,LOW);
voltage=analogRead(ADC)*2;

My measure using a multimeter is around 3,89 V and the values with this code is around 6800.

Could you help me to understand what is the relation betwen these values?

i use this code:

/*  get the BatteryVoltage in mV. */
uint32_t BoardGetBatteryVoltage(void)
{
    float temp = 0;
    uint16_t volt;
    uint8_t pin;
    pin = ADC;
#if defined(CubeCell_Board) || defined(CubeCell_Capsule) || defined(CubeCell_BoardPlus) || defined(CubeCell_BoardPRO) || defined(CubeCell_GPS) || defined(CubeCell_HalfAA)
    /*
     * have external 10K VDD pullup resistor
     * connected to VBAT_ADC_CTL pin
     */
    pinMode(VBAT_ADC_CTL, OUTPUT);
    digitalWrite(VBAT_ADC_CTL, LOW);
#endif
    for (int i = 0; i < 50; i++) // read 50 times and get average
        temp += analogReadmV(pin);
    volt = temp / 50;
#if defined(CubeCell_Board) || defined(CubeCell_Capsule) || defined(CubeCell_BoardPlus) || defined(CubeCell_BoardPRO) || defined(CubeCell_GPS) || defined(CubeCell_HalfAA)
    pinMode(VBAT_ADC_CTL, INPUT);
#endif
    volt = volt * 2;
    return volt;
}

Do you need to put any adicional circuits to the board?

have external 10K VDD pullup resistor
connected to VBAT_ADC_CTL pin

Have you had good result? I’ll try to implement here, as soon as possible I ll give the feedback.

i didn’t put any external pull ups or any hardware changes and I’m getting accurate results… something like 4128mV when fully charged.

2 Likes

Works like a charm, many thanks @jayjay!

hello, I just bought a HTCC-AB01 so I’m still learning to use it. I’m trying to display the batterie level of an external 2000 mah 3.7V batterie connected to the board throught the back batterie pin connector. Itried both, the code in the Heltec example and your function but i don’t get anything usable. I tried to modify the code but nothing worked and I can’t get the batterie % or even the batterie voltage. Here the full code I used to test it :

#include “LoRaWan_APP.h”
#include “Arduino.h”

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
}

void loop() {
/* get the BatteryVoltage in mV. /
delay(10000);
float temp = 0;
float temp_m =0;
uint16_t volt;
uint8_t pin;
pin = ADC;
#if defined(CubeCell_Board) || defined(CubeCell_Capsule) || defined(CubeCell_BoardPlus) || defined(CubeCell_BoardPRO) || defined(CubeCell_GPS) || defined(CubeCell_HalfAA)
/

* have external 10K VDD pullup resistor
* connected to VBAT_ADC_CTL pin
*/
pinMode(VBAT_ADC_CTL, OUTPUT);
digitalWrite(VBAT_ADC_CTL, LOW);
#endif
for (int i = 0; i < 50; i++){ // read 50 times and get average{}
temp += analogReadmV(pin);

    Serial.println(temp);
}
volt = temp / 50;

#if defined(CubeCell_Board) || defined(CubeCell_Capsule) || defined(CubeCell_BoardPlus) || defined(CubeCell_BoardPRO) || defined(CubeCell_GPS) || defined(CubeCell_HalfAA)
pinMode(VBAT_ADC_CTL, INPUT);
#endif
volt = volt * 2;
Serial.print("voltage: ");
Serial.println(volt);
}

If someone has an idea that may solve it.

Thanks in advance.