P2 charge indicator

Hi all,

I have an application running on the photon 2. Part of this application is some health monitoring on the system and reading the status of the CHG input.

I am using the snippet from the datasheet for this.

pinMode(CHG, INPUT_PULLUP);
bool charging = digitalRead(CHG);

On the Photon 2, the CHG digital input is HIGH (1) when charging and LOW (0) when not charging.

However this CHG input doesn't appear to reflect what the CHG LED on the board is showing.
I have written some test code to verify this.

void setup() {
    pinMode(CHG, INPUT_PULLUP);
    pinMode (D7, OUTPUT); digitalWrite (D7, LOW);
}

void loop() {
    while (1) {
        digitalWrite (D7, digitalRead(CHG));    
    }
}

I am connecting and disconnecting USB power to start/stop charging and this is verified by the CHG LED turning on/off. However D7 remains off.

What am I missing?
I have not been able to find a schematic for the photon 2 board, or any information regarding the battery charger on the device.
Any ideas?

Thanks, Ben.

You need to use INPUT not INPUT_PULLUP. The input on CHG/S5 is already connected to a voltage divider so the extra pull will overwhelm the actual input.

Same problem for me ! CHG is always Low even if the battery is charging.

Using INPUT vs INPUT_PULLUP don't change anything.

I'm pretty sure the docs on the state of CHG are backwards. This is the code I used and by plugging in the battery and unplugging the battery the blue D7 LED matched the orange charge LED once I added the ! from digitalRead().

#include "Particle.h"

SYSTEM_THREAD(ENABLED);
SerialLogHandler logHandler;

void setup() {
    pinMode(CHG, INPUT);
    pinMode (D7, OUTPUT); 
    digitalWrite (D7, LOW);
}

void loop() {
    digitalWrite (D7, !digitalRead(CHG));    
}

However when I unplugged the USB power but left the battery connected, I also get the same behavior as you do. The yellow charge LED goes off, but the blue D7 LED stays on. I'm not sure why.

1 Like

Thanks for the feedback. I'll try again after work.

The docs do say to use INPUT_PULLUPS.

It would be nice if particle released the schematics for the Photon 2. As an EE, I find it easier to code if I understand the circuit. I understand keeping P2 closed shop, but Photon 2 is just a dev board.

Cheers.

You get the same result but reversed because you used a negation on the reading of CHG! CHG is then always high.

In principle, you plug and unplug the USB cable and not the battery.

I'm working on migrating a project with the Photon and the Sparkfun charging module and I absolutely need to be able to get the state of charge and the remaining capacity of the battery.

I created an ticket for engineering to examine the issue.

1 Like

Any news about the issue ?

I haven't heard anything.

It is still being investigated. A workaround for the issue has not been found yet.

1 Like

Hello,

Still no return from engineering ?

This is being looked with additional scrutiny this week, I should have an update for you in about a week.

1 Like