Can Argon (or Xenon) Read the Battery State?

Looking forward to my new Mesh generation devices arriving and wanted to start prepping some code. One of the things I was looking for in the reference documentation was how to read the state of the battery connected to the Argon (or Xenon) but did not see anything about it.

Is this even possible? It is by no means a show stopper for me but it definitely does put a bit of a twist into one of my main uses cases (the device was going to determine when it was running low, charge up, then get back to work until it runs low again). Obviously there are workarounds possible but with the integrated battery charger and battery header I figured there must be a way that the battery state could be determined natively.

1 Like

image

It looks like pin P0.05 on the Xenon is used for reading the LiPo voltage.

We just need some code to read this pin and format it, so the voltage reading makes sense.

CHRG Status may be the pin feeding the yellow battery charging LED. Not sure if we can read this pin status via code also or not?

@rickkas7 Iā€™m sure has already done this and may be able to shed some light on the best way to do this.

1 Like

Looking at the schematic section of the datasheet P0.05 does appear to be connected as an input for battery detection in the NRF52840 section. Although it does not look to be broken out as one of the ā€œnormalā€ I/O pinsā€¦ so I am not sure how it could be read without some underlying API call.

Only a Boron comes with a Fuel Gauge for you to check the SOC of the battery.

How about just reading the battery voltage, thatā€™s what the pin is for right?

Or was that pin never broken out to be used and was left in the schematic drawling?

Good news, have fun :slight_smile:

I measured 3.97V on my multimeter and the analogRead() says 3.92V

Still within 1% tolerance i guess :smiley:

8 Likes

Nice!

Are the resistors built onto the devices or did you add them externally?

Itā€™s internally available. https://docs.particle.io/datasheets/mesh/xenon-datasheet/#nrf52840

2 Likes

Excellent!

Thanks for the example code!

Thank you very much! Good to know that part of my project will be reasonable to do.

@kennethlimcp For your voltage divider calculation you have R2 = 2100k, but from the schematic the corresponding resistor divider is actually 2M & 806k. A bit of error will creep in due to that.
The labelling on the Xenon schematic is a bit confusing as it says 2M1%R16 - but that appears to just be a lack of separating spaces between 2M / 1% / R16. Youā€™ll see the same 1% text on R15, the 806k resistor, and the same components & values on the Argon schematic with a little bit more spacing on the text.

2 Likes

Thanks for pointing out! Iā€™ll fix it :slight_smile:

2 Likes

The multiplier changes from 1.3838 to 1.403, and your analogRead() example above would now be spot on at 3.97.

3 Likes

Iā€™m sure Iā€™m just being dense, but where is the BATT variable defined?

Thatā€™s a #define in the system firmware that represents the corresponding pin number (P0.05 = port 0 bit 5).
Iā€™m not sure if that part of the code is already open sourced, but if you want to know the numeric value, you can always use Serial.println(BATT) to read that out - AFAICT itā€™s 24 for Xenons and 33 for Argons.

Thanks fellas.

@ScruffR, Should this be available on the Boron? I may be missing something obvious, but for me Serial.println(BATT) says " ā€˜BATTā€™ was not declared in this scope"

I was looking at reading the battery states on the mesh devices last night. The Electron, the closest comparison to the Boron, uses a ā€œFuelGuageā€ class to get richer details on the battery state. That Fuel Gauge class is missing on the Boron reference docs at the moment. I donā€™t think they implemented that yet.

fuel.getVCell(); woks on the Boron.

3 Likes