Disabling the Electron red charging LED when not using the LiPo

If you are in a situation where you have a power supply on VIN that can support 1800 mA and do so very quickly, it is possible to use the Electron without the LiPo battery. One use case for this high or low temperature environments, outside of the range of the LiPo.

I think I discovered the settings you must make to disable the battery and charging completely. I had missed the watchdog before, and that would cause the charging light to start blinking at odd times, including when sleeping. Then I discovered you have to disable the charge safety timer, otherwise an hour or so later the red light starts slowly blinking. I’ve been running it with these settings for a few hours and it seems to work now. Just call setCharging(false) from setup and you should be set. No more blinking red!

void setCharging(bool enable) {

	PMIC pmic;

	// DisableCharging turns of charging. DisableBATFET completely disconnects the battery.
	if (enable) {
		pmic.enableCharging();
		pmic.enableBATFET();
	}
	else {
		pmic.disableCharging();
		pmic.disableBATFET();
	}

	// Disabling the watchdog is necessary, otherwise it will kick in and turn
	// charing at random times, even when sleeping.

	// This disables both the watchdog and the charge safety timer in
	// Charge Termination/Timer Control Register REG05
	// pmic.disableWatchdog() disables the watchdog, but doesn't disable the
	// charge safety timer, so the red LED will start blinking slowly after
	// 1 hour if you don't do both.
	byte DATA = pmic.readChargeTermRegister();

	if (enable) {
		DATA |= 0b00111000;
	}
	else {
		// 0b11001110 = disable watchdog
		// 0b11000110 = disable watchdog and charge safety timer
		DATA &= 0b11000110;
	}

	// This would be easier if pmic.writeRegister wasn't private (or disable
	// charge safety timer had an exposed method
	Wire3.beginTransmission(PMIC_ADDRESS);
	Wire3.write(CHARGE_TIMER_CONTROL_REGISTER);
	Wire3.write(DATA);
	Wire3.endTransmission(true);

}

Note that this completely disables support for the LiPo battery attached to the JST connector or Li+, and the setting is sticky! In order to use a battery again you need to run setCharging(true).

15 Likes

Thanks Rick for sharing this!

1 Like

Works great!
Only problem is when you use System.sleep() the red LED turns back on. Any idea how to avoid it?

That shouldn’t happen. Which sleep mode, and does the LED turn on immediately or later? How much later?

1 Like

It turns on immediately. I am using:

System.sleep(TRIGGER_PIN, FALLING, TIME);

I’m not sure why the LED is behaving that way for you. This is the circuit I tested with:

  • The yellow wire is connected to D2 (sleep pin)
  • The orange wire is connected to D3 (wake pin)

Here’s the source I used:

#include "Particle.h"


void setCharging(bool enable);

const int SLEEP_PIN = D2;
const int WAKE_PIN = D3;

void setup() {
	Serial.begin();

	pinMode(SLEEP_PIN, INPUT_PULLUP);
	pinMode(WAKE_PIN, INPUT_PULLUP);

	setCharging(false);
}

void loop() {
	if (digitalRead(SLEEP_PIN) == LOW)  {
		System.sleep(WAKE_PIN, FALLING, 3600, SLEEP_NETWORK_STANDBY);
	}
}

void setCharging(bool enable) {

	PMIC pmic;

	// DisableCharging turns of charging. DisableBATFET completely disconnects the battery.
	if (enable) {
		pmic.enableCharging();
		pmic.enableBATFET();
	}
	else {
		pmic.disableCharging();
		pmic.disableBATFET();
	}

	// Disabling the watchdog is necessary, otherwise it will kick in and turn
	// charing at random times, even when sleeping.

	// This disables both the watchdog and the charge safety timer in
	// Charge Termination/Timer Control Register REG05
	// pmic.disableWatchdog() disables the watchdog, but doesn't disable the
	// charge safety timer, so the red LED will start blinking slowly after
	// 1 hour if you don't do both.
	byte DATA = pmic.readChargeTermRegister();

	if (enable) {
		DATA |= 0b00111000;
	}
	else {
		// 0b11001110 = disable watchdog
		// 0b11000110 = disable watchdog and charge safety timer
		DATA &= 0b11000110;
	}

	// This would be easier if pmic.writeRegister wasn't private (or disable
	// charge safety timer had an exposed method
	Wire3.beginTransmission(PMIC_ADDRESS);
	Wire3.write(CHARGE_TIMER_CONTROL_REGISTER);
	Wire3.write(DATA);
	Wire3.endTransmission(true);

}

I tested with 0.7.0.

After disconnecting the battery the red charging LED stayed off.

Connecting the yellow wire to GND caused the Electron to sleep; the red charging LED stayed off. After asleep I disconnected the yellow wire.

Connecting the orange wire to GND caused the Electron to wake up. I disconnected the orange wire.

I repeated a few cycles of this and it seemed to work fine.

Hi @rickkas7,
Why do you need to “disable the battery and charging completely” if no battery is connected and the device is being powered by a DC power supply in VIN? Will the device have some issues without using this code, in that situation?
Thanks,
David

This is only necessary for non-LTE cellular devices.

The LTE variations already suppress the blinking of the charge LED when there’s no battery connected, except for when it checks to see if a battery has recently been connected so you should not use this code.

For non-LTE devices, if you don’t mind the red charge LED flickering, there’s no harm from leaving the default settings and letting the LED flicker.

If you do want to disable the red charging LED you could use the code above. You could probably leave the BATFET enabled if you wanted to, but all of the other steps are necessary in order to prevent the charge LED from coming on when there’s no battery connected. Note that if you connect a battery, it won’t charge until you reset the PMIC settings once you’ve run the code above.

1 Like

Got it, @rickkas7 , only about the LED. I thought it was related to some current limiting in the VIN pin.
Thanks!
David