Question about Particle Argon BATT, CHG and PWR digitalRead()

I have a Particle Argon with a 3.7v LiPo battery plugged into the onboard connector. The board is powered by USB. There are no other connections.

digitalRead(PWR) always returns 0 – Shouldn’t this be 1 since the particle is connected to USB power? I tried unplugging the (micro) USB and plugging this back in, but the value is always 0.

!digitalRead(CHG)always returns 1 - even when the onboard charging light is off. I’ve tried to drain the battery and then plug it back in after it is fully charged. The value is always 1.

I looked through the sparse documentation and cannot figure this out. Can anyone throw light on why this is the case?

Updated the instructions for determining charging status and USB power on the Argon. You're right, PWR does not work. I changed it to method that works on all nRF52 devices. Also, CHG requires a pull-up. Here's full sample code:

#include "Particle.h"

SYSTEM_MODE(SEMI_AUTOMATIC);
SYSTEM_THREAD(ENABLED);

SerialLogHandler logHandler(LOG_LEVEL_INFO);

bool hasVUSB();

void setup() {
    RGB.control(true);
    RGB.color(64, 64, 64); // Gray

    pinMode(CHG, INPUT_PULLUP);

    // Particle.connect()
}

bool chgLast = false;
bool pwrLast = false;

void loop() {
    bool chg = !digitalRead(CHG);
    bool pwr = hasVUSB(); // Use this instead of reading PWR

    if (chgLast != chg || pwrLast != pwr) {
        String msg = String::format("chg=%d pwr=%d", chg, pwr);
        if (Particle.connected()) {
            Particle.publish("testChgBat", msg);
        }
        Log.info(msg);

        if (chg && pwr) {
            // Charging from USB power
            RGB.color(255, 165, 0); // Orange (looks kind of yellow)
        }
        else
        if (!chg && pwr) {
            // USB power, fully charged
            RGB.color(0, 255, 0); // Green            
        }
        else if (!pwr) {
            // No USB power, is powered from battery and discharging
            RGB.color(64, 64, 64); // Gray 
        }
        else {
            // Unexpected case
            RGB.color(255, 0, 0); // Red
        }

        chgLast = chg;
        pwrLast = pwr;        
    }
}

bool hasVUSB() {
    // This only works with nRF52-based devices (Argon, Boron, B-SoM, Tracker)
    uint32_t *pReg = (uint32_t *)0x40000438; // USBREGSTATUS

    return (*pReg & 1) != 0;
}
1 Like