For some reason, analogRead(PIN_VBAT) and LEDs have a close relationship, and some combinations can cause hang-up.Below is a summary of the relationship between red LED or green LED and analogRead().
v2.9.0 v2.9.0+patch v2.9.1 v2.9.1+variant
with LEDG
analogRead(PIN_VBAT) XXX O XXX O
analogRead(P0_31) X O X O
with LED_BUILTIN
analogRead(PIN_VBAT) XXX O O O
analogRead(P0_31) X O X O
X: can't read
XXX:hang up
O: work
Both v2.9.0 and v2.9.1 do not work properly with the green LED. Applying the patch proposed in #1/30 to v2.9.0 makes it work as expected, but Seeed-Jx pointed out a compatibility problem.I modified two files in the variant folder to work around the compatibility problem. I replaced variant.cpp and pins_arduino.h with the attached files and checked the sketch and it works fine.
I would be happy if someone could confirm this.
analogReadTEST.zip (5.4 KB)
The following is the confirmation procedure.
- Unzip the file “analogReadTEST.zip”.
- Delete “pin_arduino.h” and “variant.cpp” in directry “\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF5284” and “\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF5284_SENSE”,
then copy “pin_arduino.h” and “variant.cpp” from the unzip folder. - Copy “analogRead_LED” to an appropriate location.
- Compile and execute “analogRead_LED” from ArduinoIDE.
The pinDefinitions.h patch is not necessary since the variants file will be replaced in v2.9.1.