Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Detect if USB is connected

detec usb netduino

Best Answer Chris Walker, 28 April 2015 - 06:22 PM

Hi navinedrev,

Here is an adaptation of the code we use to detect VBUS during the manufacturing QA process... [ We do fairly thorough testing on each board :) ]

            InputPort vbusDetect = new InputPort((Cpu.Pin)0x09, false, Port.ResistorMode.PullDown);
            if (vbusDetect.Read() == false)
            {
                Debug.Print("VBUS not detected.");
            }
VBUS is "USB bus voltage". When a USB cable is connected, you'll see voltage (high state / true) on that pin. By using the PullDown internal resistor, one avoids getting false high readings from a disconnected (floating) pin.

Does that get you on the right path?

Welcome to the Netduino community,

Chris Go to the full post


  • Please log in to reply
3 replies to this topic

#1 navinedrev

navinedrev

    New Member

  • Members
  • Pip
  • 2 posts

Posted 28 April 2015 - 04:12 PM

Hello all. I'm new to Netduino.

 

I'm trying to detect if my Netduino is connected to USB for execute different code:

if(usbIsConnected){
     // Routine if have USB connection
} else {
    // Other Routine
}

How can I detect if USB is connected?



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 28 April 2015 - 06:22 PM   Best Answer

Hi navinedrev,

Here is an adaptation of the code we use to detect VBUS during the manufacturing QA process... [ We do fairly thorough testing on each board :) ]

            InputPort vbusDetect = new InputPort((Cpu.Pin)0x09, false, Port.ResistorMode.PullDown);
            if (vbusDetect.Read() == false)
            {
                Debug.Print("VBUS not detected.");
            }
VBUS is "USB bus voltage". When a USB cable is connected, you'll see voltage (high state / true) on that pin. By using the PullDown internal resistor, one avoids getting false high readings from a disconnected (floating) pin.

Does that get you on the right path?

Welcome to the Netduino community,

Chris

#3 navinedrev

navinedrev

    New Member

  • Members
  • Pip
  • 2 posts

Posted 30 April 2015 - 12:45 PM

Yes. I've been testing it and works perfect!

 

Thanks a lot. I read your answers in other posts and I can only say: You are the man. Thanks for your work in this fantastic forum.



#4 Frode

Frode

    Advanced Member

  • Members
  • PipPipPip
  • 202 posts
  • LocationNorway

Posted 16 May 2015 - 04:47 PM

Chris, perhaps the code you use for QA could be hosted on GitHub? Seems like that would be code which is useful for developers wanting to figure out how to do stuff.





Also tagged with one or more of these keywords: detec, usb, netduino

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.