Battery voltage

Hi!

Right now I do not have an issue or problem, I just want to share my findings - and as this forum is the first place where I look for solutions if I have a problem with Arduino - I think this is the right place to put it first.

I wanted to read the voltage of the battery like with the MKR1300. I failed. Here is the information what I was able to gather - so others can use (and don't have to research it for 1/2 day) :slight_smile:

  • The battery is not connected to an internal analog input on the MKR1310 like on other MKR's (PB08).
  • The on board power chip is connected through I2C bus. (type: TI bq24192l)
  • The address of the chip is 107.
  • Be careful, when reading the registries - for some bits, the first reading is referring to the time interval since it was read the last time (there is no automatic set back), and it is set back after the reading. So if you want to get the current state, read it twice: 1st read is for the past, 2nd read is the current state.

Some information of the battery state can be read from the REG 08 and REG 09 registers, like:

  • REG08; Bit 5&4: 00: Not charging / 01: Pre charging (depleted battery charging) / 10: Fast charging / 11: Charge termination done
  • Bit 0: 0: Battery voltage > System minimum voltage, 1: Battery voltage < System minimum voltage (literally: battery low)
  • REG09: Bit 0: BATT_FAULT

I would like to check for how long can the board operate and send messages in the the low battery state. (I know it depends on the power usage of the board)

I think a good comparison would be to see: how long can the board operate on a single charge and compare the 2 time intervals:
% = hours run on low battery (bit0=1) / full hours run on battery.

Of course the test should not be made in low power mode... :slight_smile: I do not have THAT long time for this test...

But I assume the calculated percentage could also be used with low power mode applications to calculate how long the device will last after the battery voltage has dropped under the V min level.

Or am I missing something? - I always keep the right to be wrong... :slight_smile:

G

1 Like

THX for this very interesting information's!

But one question: Why did you not use a voltage divider and make a measurement over a analogue pin? Than you have with one step the current voltage on the battery. :wink:

Hi!

You're welcome.

The answer to your question is simple:

During the design phase, I try to develop the system to be as simple as possible. In the MKR1300 the battery voltage is wired into one analog input - so it is simple to get the battery level through programming - no need to "solder" anything. (I believe laziness is one of the key triggers of technology advancement) To avoid cost, unnecessary parts and work.

I was curious if it's the same with the MKR 1310 - and after I failed I wanted to know why. AND - I wanted to know if there is another way to do it or not. (Although curiosity is dangerous for cats, I believe this is one of the key triggers for discoveries humankind has made)

I am running low with inputs in my current project and was hoping to "spare" an analog input.

By the way, I am working on a test to see how the bq24192l will change the status of those bits according to the battery level - and will share the data here. Hopefully the parts arrive tomorrow and I will have some time next week. (I hope I can get use of the bq24192l and spare that input...) :slight_smile:

Hi Kaszas,

in that case a voltage divider is absolute unnecessary... :wink:

Can it be, that the i2c address you wrote for the BQ24185 (106) is wrong? I believe it's the 107 (0x6b)... ?! :slightly_smiling_face:

Do you have a idea why it's not possible to charge the battery over VIN? Or better... a solution how I can charging the battery over VIN (maybe a register setting)?

THX in advance!

Hi Ageissler!

You are correct, the address is 107. This is what I wrote:

  • The address of the chip is 107.

The battery (connected to the battery connector) should be charged automatically by the chip (if it is a LiIon or LiPo rechargeable battery if the Viin is sufficient. No need to change anything in the registry.

G

Ups... you are right... I bet I had tomatoes on my eyes... :wink:

The VIN is supplying 5.2 V and 2500 mA, this should be enough to load a 600 mA LiPo battery, or?
Unfortunately the bit 6 and bit 7 of the REG08 gives a 0 back. That means no input, or DPDM detection incomplete... :sob:

Any idea?

THX

I got the fault... the fault was the using DC/DC step up converter... what ever, the data sheet says that it can supply 2500 mA but with it something goes wrong ... if I'm using a regulated DC/DC converter with 5V output with max 2A current the charging over the VIN works fine... a other (same) type but with max 1A the charging also fails over the VIN... it seams like the BQ24195 shortly checks the max current which can supplied... and it seams 1A is to less... o.k. ... the good part of the story is: I have some learned today... THX and greetings :confused:

Hello Kaszas, any news about this so far? I'd like to know if you ever figured out the status of battery from those registers :smiley_cat:

Hi community

still new to all this I think I'd achieved a lot with my mkr except of getting the voltage of the battery. Is there a tutorial or a how to on this? Even how to build the voltage divider in the meaning of which resistors to select ... I'm a mechanic so electronics is still sometimes a bit voodoo

thanks in advanced for pointing me in the right direction

try this one https://www.antratek.nl/ina260-high-or-low-side-voltage-current-power-sensor

Thanks MeandMrsJones, i just want to understand the logic...

so i made a voltage divider with 554kOhm and 1.55MOhm the sensor value gives me now 930. Is this value compared against maximum 3V3 on the input?
If yes ->
So 3V3 would be 1023 and my 930 would equal to 3.0 (i had ti calculate it twice as it gives exactly 3 and i thought i made an error :slight_smile: )

this would end up in a battery voltage of about (3 / 1500 * 2104) 4.07..Volts right?

Hi all,

Thanks for this very valuable info! For what it's worth, this is how I get a reading from my voltage divider using two 1M Ohm resistors (and a 0.1 uF capacitor, see Jeelabs), and it works flawlessly:

 analogReadResolution(10);
 analogReference(AR_DEFAULT); 
 int sensorValue = analogRead(A1);
 float voltage = sensorValue * (3.25 / 1023.0);
 Serial.print(voltage * 2);
 Serial.println("V");

As for reading the registers above, I think I am doing something wrong. The only bit that changes no matter what the battery is doing is the last bit. Here is my code (only the relevant parts):

#define DEVICE_I2C_ADDRESS 0x6B 

void setup() {

 Wire.begin();
 Wire.setClock(400000); // set I2C 'full-speed'

}

void prntBits(byte b)
{
  for(int i = 7; i >= 0; i--)
    Serial.print(bitRead(b,i));
  Serial.println(); 
}


void loop() {
  
  byte register0;

  Wire.beginTransmission(DEVICE_I2C_ADDRESS ); 

  Wire.write(0x08);

  Wire.endTransmission(false); 

  Wire.requestFrom(DEVICE_I2C_ADDRESS , 1); 

  register0= Wire.read(); 

  prntBits(register0);

}

It will print 00101100 or 00101101 depending on battery plugged in or not. The rest won't budge, charging or not. Any ideas greatly appreciated!

1 Like

Hi flymac!

If you read the previous posts, you can see, that you can not read the battery voltage through the I2C bus - the last bit is 0 if battery voltage is higher than minimum system voltage, 1 if not (low voltage or no battery). The reading, what you get of those registers are correct.

Gergo

Thanks a lot Gergo!

OK ... t he only possible way to measure the battery voltage on a MKR WAN 1310 is through a voltage divider...

But on which pin can you measure the battery voltage? VIN, VCC ?

Please advice, because I can not find a pin which shows the same voltage as my LiPo cell connected to the JST plug.

Thanks!

Well, I used A1 as you can see in my code above. You need some minimal circuitry as shown herefor instance. The output of the voltage divider will be connected to A1 (or any other analog input).

I attached a picture of my circuit before I soldered it: the yellow wire goes to A1, the two bare pins are for battery +/- and wires going to the MKR1310 itself.

Thanks flymac - I thought there might be a pin which shows the actual battery voltage (3 ... 4.3 Volt) as an existing pin of the MKR WAN 1310.

But if this is not available I will use the circuit as proposed by you.

Thanks

Peter

The MKR1300 has such a possibility through a register or actual pin (can't remember) but the MKR1310 does not, so you have to use a physical voltage divider unfortunately.
Cheers