8
\$\begingroup\$

I have following wire as shown below, one end has male USB connector and other end has four wires. I know, when connected to laptop, the RED one acts as voltage source and BLACK as ground. If I give 2 bits data input to GREEN and YELLOW one, is there any software or API for (Python, C or any other language) to know about state of those two wires ? I mean to check if GREEN or YELLOW one have a voltage or not.

enter image description here

Please guide me if I am asking the wrong question.

\$\endgroup\$
12
\$\begingroup\$

No, you cannot sense the USB wire state directly. USB is a much more complex interface than that, it is no comparison to the old style serial and parallel ports that could be used for direct I/O with a simple driver program. A complex handshake is exchanged with the PC even before the first byte of 'real' data/payload can sent.

Maybe your PC has a parallel port that can be used? Or you should use a USB to GPIO converter which are broadly available for varying prices (both extremely high and extremely low).

\$\endgroup\$
  • 1
    \$\begingroup\$ Example: sparkfun.com/products/718 I don't have any experience with this module, but it looks like up to the job. There are many similar alternatives available if you look around a bit. \$\endgroup\$ – jippie Jun 10 '13 at 6:46
  • 1
    \$\begingroup\$ Just a small addition: you cannot abuse a USB port like this because the handshake happens at a much lower level than what you can access with normal programming languages. Parts of the handshake happen in the hardware. \$\endgroup\$ – Alexander Jun 10 '13 at 15:20
1
\$\begingroup\$

What is your ultimate goal? If it is to observe the USB protocol, you can use a relatively inexpensive or relatively expensive logic analyzer.

If your goal is to capture bytes on your computer, you can get a USB debugger for your operating system (e.g., OS X has a free USB Debug Kit).

If your goal is to have an easy way to determine if you put a voltage onto an input, you'd be better off using a USB-->GPIO, as jippie suggested, or you could go down the (more expensive) arduino route and have a lot of room to grow if you wanted to do more stuff with the inputs prior to analysis on the computer.

If you really want a super-simple way to get a voltage value into your computer without buying new hardware, jippie's suggestion to use the parallel port is a good one, and you could also investigate using your microphone input as a jerry-built solution.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.