Argon check power source?

I’m looking for direction/ideas.

What is the best way to output the current “power status” for an Argon. I would like to know if the Argon is powered via USB or battery at a given time . When on battery, what is the current battery level and if it is charging or not?

For that you could look at this thread

For detection whether external power is present or not, you can use the VUSB pin with voltage divider to keep the input range between 0 & 3.3V.

About charging, I’m not sure whether the CHG LED can be accessed easily but @rickkas7 may know.

Yes, all of those are available on the Argon and Xenon.

#include "Particle.h"

SerialLogHandler logHandler;

char lastMsg[128];
unsigned long lastPublish = 0;

void setup() {
	Serial.begin();
	pinMode(PWR, INPUT);
	pinMode(CHG, INPUT);
}

void loop() {
	float voltage = analogRead(BATT) * 0.0011224;

	// PWR: 0=no USB power, 1=USB powered
	// CHG: 0=charging, 1=not charging
	char buf[128];
	snprintf(buf, sizeof(buf), "voltage=%.1f PWR=%d CHG=%d", voltage, digitalRead(PWR), digitalRead(CHG));

	if (strcmp(buf, lastMsg) != 0 && millis() - lastPublish > 2000) {
		Particle.publish("battery", buf, PRIVATE);
		Log.info(buf);
		strcpy(lastMsg, buf);
		lastPublish = millis();
	}
}

They’re available on the Boron as well, but the technique is different because you need to query the PMIC instead.

7 Likes

Thanks @ScruffR @rickkas7 This is spot on!

1 Like

Hi I an using Espruino firmware on Xenon after its end of support. T got the Xenon few days ago and it is fairly new.

I was trying to read the Charge status via reading P1.09 pin when the board is attached with a small 65 mah lipo battery with Li+/GND pin.

I am reading the pin value in a time loop of 1 second and values is toggling when board is powered from USB.

Is it a faulty hardware?

Thanks

It looks like the /CHG pin on the XC6802 charge controller is only a pull-down. When you read it via GPIO you probably need to enable a software pull-up on P1.09 as there does not appear to be a hardware pull-up on that line. It’s toggling because it’s just floating when fully charged.