Battery voltage

Battery Voltage - Photon 2

The Photon 2 does not have a fuel gauge chip, however you can determine the voltage of the LiPo battery, if present. The P2 does not include a LiPo battery connector, but if you connect your battery to VBAT_MEAS, this technique also works with the P2.

float voltage = analogRead(A6) / 819.2;

The constant is from the ADC range (0 - 4095) mapped to the voltage from 0 - 5 VDC (the maximum supported on VBAT_MEAS).

The charge indicator on the Photon 2 can be read using:

pinMode(CHG, INPUT_PULLUP);
bool charging = digitalRead(CHG);

On the Photon 2, the CHG digital input is HIGH (1) when charging and LOW (0) when not charging, however you must set pinMode(CHG, INPUT_PULLUP). You only have to set pinMode once, such as in setup.