tags:

views:

172

answers:

6

Hello!

I am working on a personal project involving sending simple signals from my computer to a circuit via USB. Basically I am using the USB signal as the gate signal for a MOSFET which will in turn activate a relay to turn on/off various AC peripherals. For example if I want to turn on a light bulb for 5 seconds every minute I would be sending a 1 down the first wire for the first 5 seconds of every minute.

This is my problem: I have no idea how to manually send a 0/1 down a specific wire on a USB cable, or even interact with a USB port at all :(

So I guess there are multiple parts to this question, is it possible to interact directly with the bits being sent via a USB port? If so how would I do this? I am familiar with C++ and C#, so I really hope that you can do it in one of those...

Thanks!

edit Hmm so it looks like the USB port actually only has one 5V pin so direct USB interaction wont work. Going to take a look at a parallel adapter and get back on it.

+3  A: 

USB is a bad fit for anything that doesn't have a USB interface at the other end of the wire. If you don't want to get into building your own USB device, I'd suggest buying a USB to serial adapter, which gives you two directly-controllable output lines (the flow control lines), or a USB to parallel adapter, which gives you more than 8 lines.

Chris Johnson's answer has a link to instructions for Windows serial port programming. You'll want to look at section 7 -- the SETDTR, CLRDTR, SETRTS, and CLRRTS are your flow control line toggles (for the DTR and RTS lines, respectively).

As far as hardware goes, a "1" (SET) value on a flow control line is +3 to +15 volts on the line, and a "0" is -3 to -15. Actual voltages can vary between devices; measure it to be sure. (EDITED; I got the 1 and 0 mixed up. The control lines use the opposite convention from the data lines.)

Here are Wikipedia pages for voltage characteristics and pinouts.

EDIT: Having done some more research on USB-to-parallel adapters, I don't think they will give the needed level of control. For best results, you'll need a PCI or PCMCIA parallel card, or a parallel port built into the motherboard.

I'm not a Windows programmer, but this library might be useful for controlling the parallel port's lines from Windows.

Jander
So if I were to use a DE9 serial adapter I could theoretically have six control lines? DTR, DCS, DSR, RI, RTS and CTS? The MOSFET's can handle a gate voltage of 5-15V so the actual voltage on the line should matter too much beyond causing excess heat if it is on the low end.
FlyingStreudel
Hrm, by the by... do you know what the implication of a negative voltage would be on a transistor like a MOSFET? That might be a stupid question but it is 6am :) But isn't a negative voltage (for the intents and purposes of this project) equivalent to a 0V? (i.e. it wont open the gate)
FlyingStreudel
Not exactly - the problem is, some of those are input lines. DTR and RTS are outputs (from computer to device), while CTS, DCD, DSR, and RI are inputs (from device to computer).
Jander
Hmm, I may just roll with a parallel port then. I need more than two controllable lines.
FlyingStreudel
As I understand it, yes, a negative voltage should force the gate closed if a positive voltage opens it. Take with a grain of salt; I'm not an electrical engineer :)
Jander
Do not use parralel ports, use a device designed to give you serial I/O from the usb. See my post for a piece of hardware I used for a project.
Scott Chamberlain
Err, no, a negative voltage is not equivalent to 0V. Negative voltages will bias parasitic diodes formed with the substrate of the transistor and can cause permanent damage to devices which aren't protected against it.
Ben Voigt
+3  A: 

The easiest thing to do for this application is to use serial port emulation, either with a USB-Serial cable, or with a USB-Serial converter chip (e.g. the FTDI FT232) in your hardware device.

Either way, this allows you to interact with your USB device as you would a serial port (see, e.g. here for how to do this in C++ in Windows)

Chris Johnson
I read the documentation but it doesn't seem to cover any specifics on how to output via the serial port :( I am not looking to send information over the wire, I just want a 5V charge on pin 8 when I tell it to.
FlyingStreudel
These devices emulate a serial port, so you use the serial port API to control pins. In Windows, see EscapeCommFunction in http://msdn.microsoft.com/en-us/library/aa363194%28v=VS.85%29.aspx
Lee Reeves
The FTDI chip also has a "bit-banging" mode (use their DLL instead of treating it as a virtual serial port) that gives you direct control over I think 12 pins. IIRC it will be 0V/3.3V, but that's enough to turn on most MOSFETs.
Ben Voigt
A: 

Use a USB prototype board. It usually comes with a software SDK.

rwong
+1  A: 

I built something very similar to what you are doing (I was running a car window motor from a usb device, used a mossfet H bridge (the HDR1X8 on the diagram) to drive the motor.). You need a USB to I/O device this is what I used (I got a U421, they fit perfectly over the center line of a breadboard, the 401 works well with breadboards too if you don't have a split one.

http://img201.imageshack.us/img201/9316/u421.png

They give you a dll and you just link in to it with your code. its just as simple as making a call to WriteA and WriteB for writing out to your mosfet device. Be warned logic level lines are not meant to drive current so you will need to hook this up to a transistor if you expect any kind of medium to large current flow. See App1 in the application notes of the menu on the usbmicro site to see the proper way to hook it up.

Scott Chamberlain
"hook this to a transistor" -- FlyingStreudel is already doing this, he says it's driving the gate of a MOSFET (metal-oxide semiconductor field-effect *transistor*).
Ben Voigt
I know that and you know that, but anyone trying to drive a light bulb with the raw USB may not know that, so sometimes it's nice to reiterate problems before he blows out his IO chip.
Scott Chamberlain
A: 

http://www.phidgets.com/ has a good selection of low-cost USB to I/O boards.

[I am not affiliated with them in any way, but I have used them in my home automation system]

Hightechrider
+2  A: 

Much like Chris suggested, you can get a USB slave device from FTDI. $27 at digikey will get you a small board with all the fine wiring already done.

However, for your purposes the bit-banging mode described on page 39 of the datasheet would be much better than the UART mode (UARTs generate pulses at several kilohertz, you want to have the voltage stay at the level you set it to).

Hopefully your MOSFET will turn on with a 3V signal since the FTDI will put out approximately 3.1-3.2V for a high output.

Also, make sure you use the latest drivers from FTDI... a couple years ago they had drivers (WHQL-certified even) that caused frequent BSOD, and I've often found that driver CDs that come with hardware are several years out of date.

Ben Voigt