tags:

views:

233

answers:

4

I want to control LED with C# using only USB port. I don't want to attach any other device with USB. I just want to attach LED directly to USB port pins and program it (blink etc). How can i do that? I am new to hardware programming and it will be my first program.

EDIT: I can do it already (blink LED) using printer port by attaching one led pin to data pin and other to ground. How can i do the same with USB port? My motherboard does not have a printer port. USB is the only option.

+3  A: 

Many mainboards will permanently supply USB ports with current.

You could theoretically put the USB controller into some suspend mode and back again but this is bad.

You'd need some sort of controller to accept commands over USB then some discrete elements to open/close current from the permanent USB supply and let it reach your LED.

Developer Art
If you're going to try to toggle the LED, you have to have a USB controller to decode the USB packets from the USB host which Windows directly controls.Also, depending on the LED, you will probably want an a resistor between the control circuit and LED.Interesting experiment: take a power supply and attach the LED to the positive and negative leads. Wait and watch what happens.
Dr. Watson
Just remember to put in a current limiting resistor, else will fry the poor diode - http://en.wikipedia.org/wiki/LED_circuit
nonnb
Also check out the nominal voltage and consumption current. With some very strong LEDs there is some risk of burning out the USB controller.
Developer Art
LED do work with USB cable when its wires are connected to pin 1 and 4 of USB. What i want is to control the blinking of LED. Turning off USB power is not a good solution. There should be a way to control it, may be using data pins
LifeH2O
There is a way to control it... With a USB controller... :-) What you're missing is that USB is a true bus and not a simple endpoint/port.
Brian Knoblauch
+2  A: 

I can do it already (blink LED) using printer port...

OK, so why not buy a cheap USB based printer port and use that? Since you already have the LPT port code working, this gives you a transparent solution.

John Lopez
I bought that board. I can not program it like i programmed the real printer port on another pc :(
LifeH2O
Sounds like that should be another SO question. "I have C# LED blinking code that works with the built in LPT port, but doesn't work with the GeeWizBang Model 1234 USB printer port. What is wrong?"
John Lopez
+2  A: 

You really can't do this. You can do it with a parallel port because you have individual control over the data pins. With USB, you only have control over the data the rides on top of the USB protocol. It's likely that protocol is being run in firmware by a chip on the motherboard anyway, so there's most likely no way to do what you want to do, short connecting the LED across the power pins and toggling the USB bus power, which you should NOT do for a whole variety of reasons.

Just get an Arduino or something. In the long run it will be a lot easier and be more flexible.

Bob Somers
A: 

This is not possible.

4 usb pins

| | | |  
| | | |  
1 2 3 4

1: +5V
2: D-
3: D+
4: Ground

To trun on LED connect with 1 and 4

Current on Data pins is too low therefore LED will never turn on if connected with 5V and any Data pin. Hence LED can not be controlled directly using data pins on USB port

LifeH2O