Detect if the USB is connected
is there a way to detect if the USB is connected to the board?
No, the USB port only provides power, nothing more.
Well, in theory I could connect the Vusb pin to one of the SoC's input pins (with a voltage divider) and detect if the USB is connected or not, right?
My question was more, if by any chance the Vusb pin is already connected to any of the SoC's input.
Unfortunately, due to limited board real estate the Vusb signal is not connected to the SoC. You could use a voltage divider to drop the voltage down to 3V and connect it to a GPIO input. The battery charger IC will prevent backflow from the battery to Vusb when unconnected, so doing this will not affect the idle/standby current draw.
Alternatively, if you are only interested in knowing if the battery is actively charging, and you are comfortable with soldering very small wires, there is a charging status output from the battery charger. This would not need a voltage divider, and should be used with the GPIO active high pull up. When the battery is charging (Vusb connected, and the battery is not fully charged) it will pull the signal low. The GPIO pin change event can be used for notifications when the status changes.
You might consider a 3rd approach using software -- whenever Vusb is plugged in, there will be an uptick in the battery voltage due to the charge current. This of course is only reliable when the battery if partially discharged. In the near future we will release a raw battery voltage endpoint which is a more direct proxy for this capability than the battery charge %.
thank you very much for your reply.
Your second suggestion is very interesting, it would save a bit of work
but if I got it correctly the charging status pin will pull the GPIO low only when the battery is charging, right?
So when the battery is charged the battery charger will not pull my GPIO input down, right?
Would I get an event when the USB is disconnected regardless if the battery is charged or not?
This is what I want to do: receive an event whenever the USB is connected or disconnected, independently of the status of the battery.
Thanks a lot.
Alessandro, Your first two questions are correct. If the battery is fully charged, the charger will not pull the status pin low.
On the third question, you will not get an event if the battery is fully charged.
If you need to specifically know when the USB is connected or disconnected you would need voltage divider on the Vusb input connected to a GPIO.
Thanks a lot Matt, very helpful.
Just to conclude on this topic.
At the end I attached a voltage divider (both resistors are 1k) between GND, Vusb and GPIO 3, configuring the input as PULLDOWN.
I tried to use GPIO 1 or 2 but I had problems, the interrupt was not reliable, the pin was going high and low unpredictably and I couldn't figure out why.
This discussion has been closed.