Particle Xenon read battery with mbed

Hi,
I am currently trying to get the voltage of an connected Lipo, but I am struggeling.
I am using mbed to read the voltages, and I can read fine from all pins, but when I try to read from P0_5, I just get some really low fluctuating values, and nothing correct.
I have read the datasheed and built another voltage divider connected to P0_4, and using this method, I can read the voltage from P04 correctly.
any Ideas why I cannot read correct values?

thanks,
Jonas

Are you connecting the battery to the JST connector/LiPo pin or another pin?

The;
(analogRead(BATT) * 0.0011224)
has been really easy for me to get a semi-accurate voltage off of Gen 3 hardware where I can then monitor and make sure the number doesn’t dip too low (signifying someone at the plant unplugged my monitoring system).

Yes, I am using the JST connecotor.
I assume you are using arduino framework? maybe thats a difference… I dont get why it doesnt work with mbed though.

I have never worked in mbed, so I googled. To read Analog voltage mbed code appears to look like;

#include "mbed.h"
Serial pc(SERIAL_TX, SERIAL_RX);
AnalogIn ain(A0); 
int main() {
  while(1) { 
    wait(10);
    float f=ain.read();
    pc.printf("value is: %d  \n",f); 
  }
}

So from that I would try to add something along the lines of;

float voltage = f * 0.0011224;

I can read analog voltage fine, just not from that pin strangely…
but why multiply it with such a small number? f will give you a number between 0 and 1, so voltage will be between 0 and 0.0011224V?! or did you want to take the raw ADC value and multiply it?

From the Argon docs;

“The constant 0.0011224 is based on the voltage divider circuit (R1 = 806K, R2 = 2M) that lowers the 3.6V LiPo battery output to a value that can be read by the ADC.”

Again, apologies if none of this is transferable given my lack of mbed knowledge. But I send the battery voltage on my entire fleet of Particle products and figured I would help on what I used to adapt to the Gen3 hardware since there isn’t on onboard “fuel gauge” like there was in Gen2.