Pages: [1]   Go Down
Author Topic: Any way to detect USB disconnect event?  (Read 1593 times)
0 Members and 1 Guest are viewing this topic.
Seattle, WA
Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all, this is my first post here. I'm using an Arduino Uno and I've been experimenting with the USB COM connection usng the Serial class, and it seems to be manageable so far. Now I'm wondering if there is a way to detect if the USB is disconnected (assuming I have an external source that powers the Uno board)?

It seems like there is no way to do it using the Serial class, short of requiring some sort of a heartbeat or querying the host. Does anyone have any wisdom to share?

Thanks,
- K.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 613
Posts: 49330
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It seems like there is no way to do it using the Serial class, short of requiring some sort of a heartbeat or querying the host.
You're right. There isn't. Typically, though, opening and closing the serial port, by an application on the PC, resets the Arduino. So, your heartbeat/query can be done in setup(), not continuously in loop(). Unless you've modified your Arduino to not reset on serial port connections.
Logged

Seattle, WA
Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Paul, sorry it took me a while to test this, You are right in that properly closing the serial port (e.g. closing the serial monitor) will reset the board, but I seem to observe a different behavior when I just unplug the USB plug from on my stock Uno board.

With a separate power supply, unplugging the USB cable seems to not reset the board and the loop continues to run. However, I did notice that if I plug in the USB again, then the board is automatically reset.

Does this make sense to you?

Thanks,
- K.
Logged

Pages: [1]   Go Up
Jump to: