Hi, you can connect a resistor between the 5V pin and the analog pin on the XIAO, and then use the analog pin to measure the voltage at the 5V pin. Since the 5V pin is directly connected to the power supply from the Type-C, you should measure around 5V when the data cable is plugged in. If powered by a battery, the voltage on that pin will be noticeably lower than 5V. By observing this voltage change, you can determine whether the power source is the battery or the data cable.