Reading battery voltage on P2

How does one use the VBAT_MEAS (pin 12) to read battery voltage in firmware? I can see this was addressed in v5.0.0 changelog. Is there currently a built-in class or function in Particle OS for reading battery voltage on this pin? Thanks

It's here. It similar to how it works on the Argon, but the constant is different.

Just a note. The post indicates the P2 but this really only applies to the Photon2. @rickkas7, perhaps a change to the title and hardware is warranted?

The VBAT_MEAS does exist on the P2, it's pin 12. If you connect that to a LiPo battery connected to your base board it does work and can be read using the same formula as the Photon 2.


Excellent thank you.
How do target pin 12 on the P2? I see that A6 is mapped to 27 on the Photon2 in pinmap_defines.h.

Yes, pin A6.

float voltage = analogRead(A6) / 819.2;

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.