Photon 2 : Battery : CHG and A6 Pin error on compilation

Hello,

I am trying to get battery information like explained in the documentation but i get error on compilation :

void setup() {
// Put initialization like pinMode and begin functions here.
pinMode(CHG, INPUT);
}

void loop()
{
// The core of your code will likely live here.
bool ChargingState = digitalRead(CHG);
float voltBat = analogRead(A6) / 819.2;
}

Errors :
'CHG' was not declared in this scope
'A6' was not declared in this scope; did you mean 'A3'?

What am i missing ?

Thanks in advance.

Best regards.

Which build environment are you using?

WebIDE: Make sure there's a gold star before the Photon 2 device in the Device tab

Workbench: Use Particle: Configure Project for Device and make sure you've selected P2 as the device type.

I use the WebIDE and my photon 2 is selected (Gold star in front on it).

Device OS Target : Default (3.2.1-p2.3)
On the device: 5.1.0

I get this error on compilation log :

make -C ../../../user
make[2]: Entering directory /firmware/user' Building cpp file: buzzer_p2_v4.cpp Invoking: ARM GCC CPP Compiler mkdir -p ../build/target/user/platform-32-m arm-none-eabi-gcc -DSTM32_DEVICE -Drtl872x -DCONFIG_PLATFORM_8721D -DPLATFORM_THREADING=1 -DPLATFORM_ID=32 -DPLATFORM_NAME=p2 -DPLATFORM_GEN=3 -DUSBD_VID_SPARK=0x2B04 -DUSBD_PID_DFU=0xD020 -DUSBD_PID_CDC=0xC020 -DSPARK_PLATFORM -fno-builtin-puts -fno-builtin-printf -Wl,--wrap=puts -Wl,--wrap=printf -g3 -gdwarf-2 -Os -mcpu=cortex-m33 -march=armv8-m.main+dsp -mthumb -mcmse -mfloat-abi=hard -mfpu=fpv5-sp-d16 -DARM_CPU_CORTEX_M33 --specs=nano.specs -DINCLUDE_PLATFORM=1 -DPRODUCT_ID=32 -DPRODUCT_FIRMWARE_VERSION=65535 -D_WIZCHIP_=W5500 -DUSE_STDPERIPH_DRIVER -DDFU_BUILD_ENABLE -DLFS_CONFIG=lfs_config.h -DSYSTEM_VERSION_STRING=3.2.1-p2.3 -DRELEASE_BUILD -I./inc -I../wiring/inc -I../system/inc -I../services/inc -I../third_party/nanopb/nanopb -I../communication/inc -I../hal/inc -I../hal/shared -I../hal/src/tron -I../hal/network/ncp/wifi -I../hal/network/lwip/esp32 -I../hal/network/ncp/wifi -I../hal/src/rtl872x -I../hal/src/rtl872x -I../hal/src/rtl872x/lwip -I../hal/src/rtl872x/freertos -I../hal/src/rtl872x/mbedtls -I../hal/src/rtl872x/littlefs -I../hal -I../hal/src/rtl872x/posix -I../hal/network -I../hal/network/api -I../hal/network/lwip -I../hal/network/lwip/posix -I../hal/network/lwip/wiznet -I../hal/network/ncp -I../hal/network/ncp/at_parser -I../hal/network/util -I../third_party/lwip/lwip/src/include -I../third_party/freertos/freertos/FreeRTOS/Source/include -I../third_party/ambd_sdk/ambd_sdk/component/os/freertos/freertos_v10.2.0/Source/portable/GCC/RTL8721D_HP/non_secure -I../third_party/wiznet_driver/wiznet_driver/Ethernet -I../platform/shared/inc -I../third_party/ambd_sdk -I../third_party/ambd_sdk/ambd_sdk/component/soc/realtek/amebad/cmsis -I../third_party/ambd_sdk/ambd_sdk/component/soc/realtek/amebad/fwlib/include -I../third_party/ambd_sdk/ambd_sdk/component/soc/realtek/amebad/swlib/include -I../third_party/ambd_sdk/ambd_sdk/component/soc/realtek/amebad/app/monitor/include -I../third_party/ambd_sdk/ambd_sdk/component/os/os_dep/include -I../third_party/ambd_sdk/ambd_sdk/component/os/freertos -I../third_party/ambd_sdk/ambd_sdk/component/common/api -I../third_party/ambd_sdk/ambd_sdk/component/common/api/platform -I../third_party/ambd_sdk/ambd_sdk/component/common/api/wifi -I../third_party/ambd_sdk/ambd_sdk/component/soc/realtek/amebad/misc -I../third_party/ambd_sdk/ambd_sdk/component/soc/realtek/amebad -I../third_party/ambd_sdk/ambd_sdk/component/common/drivers/wlan/realtek/include -I../third_party/ambd_sdk/ambd_sdk/component/common/drivers/wlan/realtek/src/osdep -I../third_party/ambd_sdk/ambd_sdk/component/common/drivers/wlan/realtek/src/osdep/freertos -I../third_party/ambd_sdk/ambd_sdk/component/common/bluetooth/realtek/sdk/board/amebad/lib -I../third_party/ambd_sdk/ambd_sdk/component/common/bluetooth/realtek/sdk/board/amebad/src -I../third_party/ambd_sdk/ambd_sdk/component/common/bluetooth/realtek/sdk/board/amebad/src/vendor_cmd -I../third_party/ambd_sdk/ambd_sdk/component/common/bluetooth/realtek/sdk/board/common/inc -I../third_party/ambd_sdk/ambd_sdk/component/common/bluetooth/realtek/sdk/inc/app -I../third_party/ambd_sdk/ambd_sdk/component/common/bluetooth/realtek/sdk/inc/bluetooth/gap -I../third_party/ambd_sdk/ambd_sdk/component/common/bluetooth/realtek/sdk/inc/bluetooth/profile -I../third_party/ambd_sdk/ambd_sdk/component/common/bluetooth/realtek/sdk/inc/bluetooth/profile/client -I../third_party/ambd_sdk/ambd_sdk/component/common/bluetooth/realtek/sdk/inc/bluetooth/profile/server -I../third_party/ambd_sdk/ambd_sdk/component/common/bluetooth/realtek/sdk/inc/os -I../third_party/ambd_sdk/ambd_sdk/component/common/bluetooth/realtek/sdk/inc/platform -I../third_party/ambd_sdk/ambd_sdk/component/common/bluetooth/realtek/sdk/inc/stack -I../third_party/ambd_sdk/ambd_sdk/component/common/api/at_cmd -I../third_party/ambd_sdk/ambd_sdk/component/common/mbed/targets/hal/rtl8721d -I../third_party/ambd_sdk/ambd_sdk/component/common/mbed/hal_ext -I../third_party/ambd_sdk/ambd_sdk/component/common/mbed/hal -I../third_party/ambd_sdk/ambd_sdk/component/common/file_system/fatfs -I../third_party/ambd_sdk/ambd_sdk/component/common/file_system/fatfs/r0.10c/include -I../third_party/ambd_sdk/ambd_sdk/component/common/file_system/ftl -I../third_party/ambd_sdk/ambd_sdk/component/common/drivers/usb/device_new/core -I../third_party/ambd_sdk/ambd_sdk/component/common/drivers/usb/common_new -I../third_party/littlefs/littlefs -I../third_party/miniz/miniz -I../platform/MCU/rtl872x/inc -I../dynalib/inc -I -I./libraries -I. -MD -MP -MF ../build/target/user/platform-32-mbuzzer_p2_v4.o.d -ffunction-sections -fdata-sections -Wall -Wno-switch -fmessage-length=0 -Wno-error=deprecated-declarations -Wno-error=unused-parameter -Wno-deprecated-declarations -Wimplicit-fallthrough=2 -Wno-expansion-to-defined -Wno-cast-function-type -Wno-unused-parameter -Wno-error=type-limits -fno-strict-aliasing -DSPARK=1 -DPARTICLE=1 -Werror=return-type -Wundef -DSTART_DFU_FLASHER_SERIAL_SPEED=14400 -DSTART_YMODEM_FLASHER_SERIAL_SPEED=28800 -DSPARK_PLATFORM_NET=rtl872x -fno-builtin-malloc -fno-builtin-free -fno-builtin-realloc -DLOG_INCLUDE_SOURCE_INFO=1 -DPARTICLE_USER_MODULE -DMODULAR_FIRMWARE=1 -DMODULE_VERSION=6 -DMODULE_FUNCTION=5 -DMODULE_INDEX=1 -DMODULE_DEPENDENCY=4,1,3212 -DMODULE_DEPENDENCY2=0,0,0 -D_GNU_SOURCE -DLOG_MODULE_CATEGORY="\"app\"" -fno-exceptions -fno-rtti -fcheck-new -flto -ffat-lto-objects -DPARTICLE_COMPILE_LTO_FAT -fno-use-cxa-atexit -std=gnu++14 -c -o ../build/target/user/platform-32-mbuzzer_p2_v4.o buzzer_p2_v4.cpp buzzer_p2_v4.ino: In function 'void setup()': buzzer_p2_v4.ino:66:11: error: 'CHG' was not declared in this scope 66 | pinMode(CHG, INPUT); | ^~~ buzzer_p2_v4.ino: In function 'void loop()': buzzer_p2_v4.ino:100:66: error: 'CHG' was not declared in this scope 100 | bool ChargingState = digitalRead(CHG); | ^~~ buzzer_p2_v4.ino:102:60: error: 'A6' was not declared in this scope; did you mean 'A3'? 102 | float voltBat = analogRead(A6) / 819.2; | ^~ | A3 make[2]: *** [../build/target/user/platform-32-mbuzzer_p2_v4.o] Error 1 make[2]: Leaving directory /firmware/user'
make[1]: *** [user] Error 2
make[1]: Leaving directory `/firmware/modules/tron/user-part'
make: *** [modules/tron/user-part] Error 2

Select a newer version of Device OS in the target popup. 5.4.1 is recommended.

3.2.1-p2.1 did not have support for CHG or A6.

That's it !

Thanks a lot.

Best regards.

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