Click here to Skip to main content
15,436,489 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'd like to know how to send info through the usb port.
My project: I want to design a program that turns on leds using the usb port (because I'm using a laptop)
I have the code to make it uisng the serial port, but it's not useful for me.

Thanks for helping.
Posted
Comments
[no name] 2-Aug-13 15:48pm    
Maciej Los 2-Aug-13 15:57pm     CRLF
Very good answer. Do you know it? My virtual 5!

Alright, I'll expand on ThePhantomUpvoter's message, mostly because I dabble in embedded electronics...

Serial ports work by bringing a signal high or low. There are a couple signals like DTR and RTS that can be easily controlled through code, and made to stay high or low. These aren't typically the case with the RX and TX pins because they go high to low very quickly at a specific timing to send bits to the other end. DTR and RTS are there to notify the other end that its ready to send or ready to receive. Basically there are 9 pins that RS-232 uses, DTR, RTS, DCD, CTS, DSR, RI, RX, TX and GND. GND (Ground) is constant and shared with the computer power supply. RX and TX cycle at a specific timing for sending and receiving data. DTR, RTS, DCD, DSR, and CTS are control pins that can be driven to stay at a specific value.

USB is a completely different system from the electronics side. There are 4 pins, +5V, GND, D+ and D-. Obviously +5V and GND are used for power, but D+ and D- are kind of like the RX and TX pins, except they work differently. You can't use them to turn an LED on or off because you can't drive them to a specific state and hold them there.

If you want to drive LED's, take a look at interfacing the Arduino, or get a USB to Serial converter and do it that way.
 
Share this answer
 
v2
Comments
Ron Beyer 2-Aug-13 16:46pm    
Oh, and before you try, a really good way to burn out a USB port is to hook an LED directly to the +5V and GND pins. LED's will suck as much current as the power supply is able to give, you have to use resistors to limit the current.
lewax00 2-Aug-13 17:23pm    
I wanted to +5 this too, but then realized you were the answerer. You might want to edit that information into your answer though, it's kind of important.
In my opinion, you should use a microcontroller to switch ON/OFF the LEDs (or control other hardware). In turn your laptop would communicate with the microcontroller (directly via USB or by means of a virtual COM on the USB).
The direct connection of the LEDs (or other hardware) may (if wrong) phisically harm your laptop and it is difficult to handle in software).
 
Share this answer
 
Depending on your budget (they aren't exactly cheap for a quick personal project) you could also use XBee modules[^] to do this. One of them has a USB in (in the set I got), and then you can do it wirelessly.

Honestly, it's pretty hard to answer this question in a complete way without knowing the hardware you're using though.

EDIT: realized the page I linked just had information about the wireless modules, here's the USB adapter[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900