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.
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?
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.
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().
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.
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.
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.