Battery Charging Indicator - not working?

I have been monitoring the digitalRead(CHG) for the battery is charging along with digitalRead(PWR).

For CHG pin 0 = charging and 1 = not charging. For PWR 0 = battery, 1 = USB powered.

When battery powered the CHG will show as 0 (charging)? Is there a reason for this - as it appears to be a fault/bug?

Not working for me either:

In the schematics this pin is marked as /CHG which indicates active low which will be pulled high when there is a supply coming from VUSB.

Without VUSB (indicated by PWR) the 6k2 pull-down will enforce the low level.
So only the combination PWR && !CHG will provide the actual charging status.


So on U3 /CHG means active LOW pin? I am glad you can read these schematics.
As you say it is tri-state battery, powered & not charging, powered & charging. Good explanation.

1 Like

Thanks for clarifying this! I am still figuring out how to apply it to detect whether there is USB power or not, while operating on battery. digitalRead(CHG) and digitalRead(PWR) are both 0 with battery plugged in, whether USB is plugged in or not. Should I be approaching this in a different way?

FYI, I’ve been doing this:

        hasUsbPower = digitalRead(PWR); 
        isCharging = (hasUsbPower && !digitalRead(CHG));  
        onBatteryPower = (!hasUsbPower || !isCharging);

Based on that if you have both battery and usb you’ll see the usb is only used to charge the battery, then it runs off battery for awhile. That surprised me, I thought it’d charge the battery and then run off the USB but that’s not what the above is showing in my testing.

–April update: I think the battery part of the above is wrong. It appears to use USB and not battery, when USB is available, thus onBatteryPower = !hasUsbPower; is what I use now. The part that tripped me up before is the voltage is different between USB only and USB + charged battery.


Thanks again @Fragma and @ScruffR.

Is it possible to do conditional compilation based on what the target board is? Some sort of #if .... #endif to check power one way for xenon and another for boron? I’d really like to have one code base to roll out on both boards if possible.

Yes, PLATFORM_ID would be the macro you want to check against PLATFORM_ARGON, PLATFORM_BORON or PLATFORM_XENON.

Here is the list for all platforms IDs

1 Like

Worked like a charm. The following allowed me to write different codes for Xenon and Boron in the same file:


// Stuff for Boron


// Stuff for other boards
pinMode(PWR, INPUT);


Also, I had some trouble with digitalRead(PWR) until I realized that it needs pinMode(PWR, INPUT); in setup() to work, per Mesh (Argon/Xenon) detecting USB power loss .

Everything is working well now. I really appreciate the fast and spot on help in this forum - thanks again.

1 Like