I got a battery attached to my Seeed Studio XIAO nrf52840 and once I plug in USB-c cable the charging LED goes on. Is there a way in code to detect if the USB-c cable has been plugged in so I can run some code when that happens?
Hi Philipp,
Good question I have not seen a specific answer, but it leaves me to believe you should be able to read the charging state? and get the same result. Maybe one of the other GREAT seeed Hive mind members could reply. I’m somewhat skeptical however, because of reading the battery charge level is broken in 2.9.x board files and seeed engineering is not responding to it.
HTH
GL
PJ
What about reading an analog input pin connected to a voltage divider circuit from the +5V source to determine if the USB is connected? The charging state can be determined by reading P0_17, eg:
pinMode(P0_17, INPUT);
charging = ! digitalRead(P0_17); // negated so 0=not charging 1=charging
However, once a battery is fully charged, even if the USB cable remains connected the charging LED will go out and the variable “charging” in the example above will be zero.
So long as the USB cable is connected, the battery charge will be maintained but the charging LED will never go back on nor will the charging state change.
Yes, it is possible to detect whether the USB-C cable has been plugged in or not by monitoring the status of the USB connection using the nRF52840 microcontroller on the Seeed Studio XIAO board. You can achieve this by utilizing the USB API provided by the nRF SDK (Software Development Kit).
No examples exist for the Arduino IDE and Xiao Nrf52840 that I know of or have seen, So SDK may be the only method.
HTH
GL
I’m working with the Seeed Studio XIAO nrf52840 board and have a specific requirement related to detecting the status of the USB-C cable connection. I have a battery attached to the board, and whenever I plug in the USB-C cable, the charging LED turns on. I’m wondering if there’s a way to detect this USB-C cable connection in my code so that I can execute certain actions or run specific code when the cable is plugged in. Thanks
You may consider to use Vbus of the USB port to fire an interrupt. However the Vbus voltage is too high for Xiao and you need to add a divider circuit before connecting to Xiao. In other words you have to modify Xiao otherwise there is no way to detect the USB port.
A bit late to the party, but on the schematic, the P0.17 pin is wired to a charging status pin of the charging IC. It’s the same signal that drives the LED. Hope it helps.
LEDG or LED_PWR may be used to detect it.