Question to Seeed: Why is the bug that analogRead (PIN_VBAT) does not work in mbed 2.9.1 for XIAO_nRF52840 not resolved?

XIAO_nRF52840 has the pin to read the battery voltage, but it does not work as shown in the link below.

I submitted a post to “GitHub - Seeed-Studio/ArduinoCore-mbed” but neither 2.8.1 nor 2.9.0 solved the problem. Why doesn’t Seeed fix this bug?

Translated with DeepL

1 Like

MSFujino, thanks for finding this issue - do you know, if I’m using a firmware that itself uses PlatformIO/Arduino, where would I look to fix this error? At the moment a simple search in VisualStudio Code does not find keywords such as you changed

Hi braddo,
Sorry, I am not using PlatformIO, so I don’t know where to find the directory equivalent to “/Arduino15”.
Try to find the equivalent of the following directories and files on your PC.

C:\Users\xxxx\AppData\Local/Arduino15/packages/Seeeduino/hardware/mbed/2.9.0/cores/arduino/pinDefinitions.h : 22

Hello msfujino - I reverted to trying just Arduino. In that case, I can find the pins definition in the file pins_arduino.h Pins 14 and 31 do not existin this file. When I try to add them, I get an error during compile that those pins are invalid.

It seems like you were able to solve this in MBED, I’m hoping I can also solve it in Arduino so that I can read the battery level without an external voltage divider circuit.

I added the last two lines to try, but didn’t work:

#ifndef Pins_Arduino_h
#define Pins_Arduino_h

#include <stdint.h>

#define EXTERNAL_NUM_INTERRUPTS 22
#define NUM_DIGITAL_PINS        22
#define NUM_ANALOG_INPUTS       6

#define analogInputToDigitalPin(p)  (((p)<NUM_ANALOG_INPUTS)?(analogChannelToDigitalPin(p)):-1)
#define digitalPinToInterrupt(p)    (((p)<NUM_DIGITAL_PINS)?(p):-1)
#define digitalPinHasPWM(p)         (p < EXTERNAL_NUM_INTERRUPTS)

static const uint8_t TX = 21;
static const uint8_t RX = 20;

static const uint8_t SDA = 6;
static const uint8_t SCL = 7;

static const uint8_t SS    = 20;
static const uint8_t MOSI  = 10;
static const uint8_t MISO  = 9;
static const uint8_t SCK   = 8;

static const uint8_t A0 = 2;
static const uint8_t A1 = 3;
static const uint8_t A2 = 4;
static const uint8_t A3 = 5;

static const uint8_t D0 = 2;
static const uint8_t D1 = 3;
static const uint8_t D2 = 4;
static const uint8_t D3 = 5;
static const uint8_t D4 = 6;
static const uint8_t D5 = 7;
static const uint8_t D6 = 21;
static const uint8_t D7 = 20;
static const uint8_t D8 = 8;
static const uint8_t D9 = 9;
static const uint8_t D10 = 10;

static const uint8_t D14 = 14;
static const uint8_t A31 = 31;


#endif /* Pins_Arduino_h */

Hi braddo,

What is the “Arduino” here?

Not sure if this is what your after , It did work when I tried it, Also I use Platformio and have no issues compiling or downloading or even Debugging with the jlink all works.
I do recall it using a check-mark or option for the VScode to use the same Library. but env, board, pins etc. is in the INI.
https://medium.com/@alwint3r/working-with-seeed-xiao-ble-sense-and-platformio-ide-5c4da3ab42a3
HTH
GL :slight_smile:

Arduino meaning Aduino v2 software for writing/uploading the firmware to the XIAO C3. This uses Arduino wrapper around the espressif library, not MBED (not sure what that is though). I think you mentioned in another post however that this info is only for the Sense version of XIAO.

Thanks for this - I guess it (like the thread) is somewhat specific to the Nordic based XIAO Sense. Probably some info re Platformio is also useful though - thanks for the link

v2.9.1 has been released, but
analogRead(P0_31) returns 0xFFFFFFFFFF
analogRead(PIN_VBAT) hangs the IDE.
I have no idea what part was fixed and for what purpose.

Seeed’s engineers have started to look into it, and the topic has achieved its goal.
Please see the link below.

XIAO_BLE_Sense(mbed 2.7.2) battery charge and voltage monitor, analogRead(P0_31) does not work - #29 by msfujino