How to detect USB is connected

Aside from the issues of whether or not the Wixel USB drivers have been installed properly, what is the recommended way to determine (within the app) whether the USB cable is connected. I have internal diagnostics in my project which I currently turn on via a param variable, but at this point I’d rather turn diags on or off by detection of the port rather than a load time parameter.

I see that P2_4 connects to the green LED, which is tied through a resistor to USB power. So theoretically if I occasionally set this pin to be an input (pulled low) between calls to usbComService(), I should be able to read whether it is high or low (high would mean the USB cable is connected). Afterward I would restore P2_4 to an output (set LOW I suppose). I’m hoping this will let me detect the usb is present without interfering significantly with the wixel’s normal maintenance of the P2_4 line. Am I correct? The green LED and resistor should isolate the I/O pin enough to avoid damage from the +5V USB power, right? (Again, I realize this has nothing to do with the the USB communication actually working).

Or… better yet… maybe there is already an undocumented function or variable I could just read to accomplish all the above :slight_smile:


We already wrote some functions to do that. You can call usbPowerPresent, which is documented here: … cbc4ac0b72