Cubecell HTCC-AB02 Get Battery Voltage

Hello Everyone,
I’m using the Heltec Cube Cell HTCC-AB02 Board and have the following problem:

When reading the battery voltage with the function getBatteryVoltage(), I get sometimes the correct voltage, but sometimes or most of the times the read value is zero.

I also tried to modify the function, because I thought I have to wait a little time after pulling down the pin VBAT_ADC_CTL to low, but the problem is also there.

static void getBatteryVoltageFloat( void )
{
  pinMode(VBAT_ADC_CTL,OUTPUT);
  digitalWrite(VBAT_ADC_CTL,LOW);
  delay (50);
  uint16_t u16BatteryVoltage = analogRead(ADC) * 2;
  pinMode(VBAT_ADC_CTL, INPUT);
  fBatteryVoltage = (float)u16BatteryVoltage / 1000;
  if (cbDebugConsoleActive) {
    Serial.print("Battery Voltage: ");
    Serial.print(fBatteryVoltage);
    Serial.println("V");  
  }  
}

I could think of the following problems: Maybe some problem after deep sleep, because I read every 5 minutes the battery voltage after deep sleep and send them by LoRaWan to TheThingsNetwork.
Or maybe some problems with the internal firmware and the mux?

Has anyone the same problem and maybe a solution?

Best regards
Thomas

Hi Thomas, I have the same issue but not have fund the solution.

hi,

could you try this code? I think the problem may be float format

static void getBatteryVoltageFloat( void )
{
  pinMode(VBAT_ADC_CTL,OUTPUT);
  digitalWrite(VBAT_ADC_CTL,LOW);
  delay (50);
  uint16_t u16BatteryVoltage = analogRead(ADC) * 2;
  pinMode(VBAT_ADC_CTL, INPUT);
 // fBatteryVoltage = (float)u16BatteryVoltage / 1000;
  if (cbDebugConsoleActive) {
    //Serial.print("Battery Voltage: ");
    Serial.print(u16BatteryVoltage);
    //Serial.println("V");  
  }  
}

Hi Jason,
could you explain why you think that the problem could be the float format?
I also use an BME280 and convert all measured data to float. There is no problem.
At the end I need the float format for CayenneLPP.
But I will try it later.
Thanks.
Thomas

Do you have another board you can try it on? Unfortunately I’ve got hardware problems on 2/7 CellCube units I bought for prototyping. One won’t connect to LoRa and the other reads close to zero for the battery voltage just like you describe - however the same battery monitoring software works fine on the other boards.

Unfortunately I only have one board. I already thought that it could be a hardware problem. It seems that colder temperatures increase the problem.
Maybe I should complain about the product by the seller.
Regards Thomas

Hi frind, I try this procedure and also getBatteryVoltage(). On both I got Battery voltage = 270.
what is the meaning of this value?

hi,

This is just to verify the conjecture: Is it the float data problem?

It has no practical meaning.

The value is in mV. E.g. 3,7 V battery voltage would give you a value of 3700.

Float data is not the problem. The integer value is also wrong. I’m quite sure that the board has a problem. I have complained the board by the seller and get a new one the next days.

the value does not make sense, the battery is fully charged and I get 270

@jasonXu Hi friend, can you help me to resolve this issue with battery pls.

How can I help you? The measuring of the battery voltage works well with the new hardware I got yesterday. What problem do you have?

Thomas my problem is I got 270 as result of the getBatteryVoltage().
is variable but value are near to 270.

You can see how the solar panel are charging the battery because the fluctuation. But the result go from 255 to 282.

By the way I check on the serial monitor with print that I have and the value is the same.

image

That is really strange. It seems that it is somehow working, but not with the correct resolution.
I guess you use the getBatteryVoltage() function from the Heltec library? Am I right?

If you have a multimeter to measure voltage you could check your hardware (the on board voltage divider and the mosfet switch) if you activate the voltage measuring with the follwing code:
pinMode(VBAT_ADC_CTL,OUTPUT);
digitalWrite(VBAT_ADC_CTL,LOW);

After that you can measure the voltage on the pin 2 “ADC1”. This is on the upper pin header the pin on the right outside. Here you should measure exactly half the battery voltage, bevause of the 100k / 100k voltage divider. If the voltage is ok, the hardware up to the adc should be ok.

Regards Thomas

I have used the ADC1 to read a sensor in my project, so I have resistor of 4.7K to ground.

image

I think when you use the getBatteryVoltage() the procedure put in LOW the VBAT_ADC_CTL and that disconnect temporally what I have on the pin, make the measurement and the put VBAT_ADC_CTL to HIGH again to reconnect the pin.
Are this correct?

BTW: I make the test direct in the code without use the lib and the result its the same.
I have no voltage on ADC1 pin.

image

Ok. Am i right that you also use the board HTCC-AB02?
If yes the VBAT_ADC_CTL makes something different. When pulling it low the following circuit is activated:


Then a 100K / 100 K voltage divider measuring the VBAT voltage on the PIN ADC1. That means your voltage on pin ADC1 is somehow overwritten by the on board voltage divider.
If you don’t want to use the onboard voltage divider you should set VBAT_ADC_CTL to HIGH. Then you can use the ADC1 input by your own.
Which voltage did you get from your signal Sonda EC? And what voltage divider you get together with the 4,7k resistor? Because the code “analogRead(ADC)*2” only is correct with the 100k / 100k voltage divider. You have to adapt this to your voltage divider…

%E5%9B%BE%E7%89%87

1 Like

]Finally I remove the resistor and all working.
But I cant use the adc1 in my application.