Closed ronaldvdmeer closed 3 years ago
I am having exactly the same issue (using Arduino IDE).
FYI: GetBatteryVoltage works fine.
That's the correct behaviour - it's designed to tell if the battery is being charged or not WHEN USB is connected, not if the USB is connected or disconnected. Sorry.
My latest TinyPICO's have the ability to check isa USB is present or not by reading IO9 - All TinyPICO USB-C have this, and my Micro-B also has it now, but not all stock out in the wild is the latest versions.
if you have an older TinyPICO you can put a voltage divider on the 5V pin and connect that to a spare IO to read to see if there is a 5V source present or not.
Thank UM, I (incorrectly) assumed it was reflecting the Battery Charge LED.
As my wild TP is USBC, I'll read IO9 as you suggest :)
It does, but the STAT pin on the PMIC requires 5V to work ;) So if no 5V is present, it means the PMIC can't do anything, so it won't change STAT state.
That's the correct behaviour - it's designed to tell if the battery is being charged or not WHEN USB is connected, not if the USB is connected or disconnected. Sorry.
Thank you. That explains.
A little snip of Arduino code that determines if USB is connected and if USB is connected and charging... (just to say it - needs pinMode and tp to be declared)
bool charging = tp.IsChargingBattery();
bool plugged = digitalRead(9);
if (plugged == 1) { // If USB is plugged in (battery able to charge)
Serial.println("USB is plugged in.");
}
if (plugged == 1 && charging == 1) { // If USB is connected & Battery is charging
battCharg = "Yes";
}
else {
battCharg = "No";
}
Serial.print("Battery charging: ");
Serial.println(battCharg);
Perhaps i'm not understanding this but
IsChargingBattery
does not seem to change to false (0) when I disconnect USB. At that point the TinyPICO (ESP32-PICO-D4) is completely running from battery. I'm using the VBAT and GND pin for the battery.https://github.com/UnexpectedMaker/tinypico-helper/blob/f6f992d3f36738796c21d6c7825b8ef641a5f31b/src/TinyPICO.cpp#L197
To give you an idea. A snippet of the script below.