I stumbled upon this thread because I was having a similar issue. The issue with with the mbed framework. I’ll let this thread where speak for itself: XIAO_BLE_Sense(mbed 2.7.2) battery charge and voltage monitor, analogRead(P0_31) does not work - #2 by JeonLab
Actually, VBAT_ENABLE is defined in PlatformIO, it’s just called PIN_LSM6DS3TR_C_POWER (intuitive, I know). There’s also a pin for reading charge status, PIN_LSM6DS3TR_C_INT1. These are defined in something like “.platformio\packages\framework-arduino-mbed\variants\SEEED_XIAO_NRF52840_SENSE\pins_arduinio.h”:
#define PIN_VBAT (32u)
...
#define PIN_LSM6DS3TR_C_POWER (14u)
#define PIN_LSM6DS3TR_C_INT1 (17u)
The fun thing is, all of them except PIN_VBAT don’t work. The other forum thread explains it in detail but basically the integer value of the pins is not the same as their label (P0.14 =/= 14). My solution is to replace them with the proper value corresponding to an index from variant.cpp in the same folder:
#define VBAT_ENABLE (31u) // digital output: battery voltage enable
#define VBAT_CHG (22u) // digital input: charging status
Copy the above snippet into your code and you should be good to go.