1
\$\begingroup\$

I would like to control a simple servo or led with USB.

I opened the cable up and connecting the red and black wires to the servo made it spin properly with about 5V, as those are VCC and GND. Ok.

Now I would like to use one of the data channels to control the state (on/off) of the servo via my computer.

In the end I would like to have a script to turn it on and off. The problem is that every tutorial uses an USB architecture that makes drivers overly complicated by using vendor and products ids' to auto identify the hardware at the end of the USB (to allow for plug'n'play, I imagine), and I don't have that - that is, I don't want to make a circuit that is able to inform to the PC the specs of my device. And I do not want to use Arduino's or other complex boards for such a simple task.

I couldn't even identify my ports (in linux), as every software and utility I found lists only the plugged usb's, with their crazy ids, and my bare ended (servo apart) half-cut usb extension is not listed, as (it seems) it is not connected to a 'proper' usb gadget.

I would like to make a program that would run, ask for a physical usb port on my machine (identifying then somehow) and then let me set the output in each of the two wires, instead of a driver that can automatically detect my gadget. Simple as that.

Is there a way to do that with USB? Or should I choose another way of communicating with my device? (though I can't think of any other ways that my computer would handle... and with the advantage of built-in power...)

\$\endgroup\$
4
\$\begingroup\$

Usb is a complicated protocol that does not work the way you want it to work. It must enumerate, must have a VID/PID pair, must report it's structure and endpoints.

A solution for you would be looking for a usb to gpio or usb to relay board and using that to control your servo (bypass the relay, but timing might not be as good as you expect). Another solution is a usb to serial (ttl) adapter, with the rts and/or dts pins broken out, which can then be toggled by serial port software.

Otherwise you need a usb capable microcontroller solution.

\$\endgroup\$
  • \$\begingroup\$ So if I had a 'usb to ttl' chip like a PL2303 (like this one) I could just install its driver and set the outputs? Or would I need something more complex? \$\endgroup\$ – Luan Nico Nov 20 '14 at 17:01
  • \$\begingroup\$ You will need a relay at least where you connect the Rx (output from PL2303) to the relay control pin. To close the relay (the On state) you will need to send continues High signal since once you stop sending it will go low and turn of the relay. ** Also make sure your set-up (servo + relay + PL2303) won't consume more than 500mA which is the USB limit. \$\endgroup\$ – Fahad Alduraibi Nov 20 '14 at 17:11
  • \$\begingroup\$ The relay would be just to amplify the signal, right? So I could put full 5V or more instead of the 3.3V output of the Rx into the servo. But if I were ok with it, could I connect the RX directly into the servo and the other in the GND? Then if it is high it will turn, otherwise stop, only that with 3.3V (it runs well on 3.3V too). \$\endgroup\$ – Luan Nico Nov 20 '14 at 17:20
  • \$\begingroup\$ A relay or transistor would be needed for a load, but a servo has control circuitry. An direct connection with a 5V level TTL ic like the pl2302 is possible. A transistor or opto coupler if you want or need some isolation/protection. A single 20mA led could also use a direct connection, but a bigger load would need a transistor or mosey or relay. \$\endgroup\$ – Passerby Nov 20 '14 at 18:14
  • \$\begingroup\$ @luannico a chip like the ftdi2303 series can be used in both serial mode or use t he direct interface driver for more advanced control. The pl2303 only has serial mode iirc but I may be wrong. \$\endgroup\$ – Passerby Nov 20 '14 at 18:16
4
\$\begingroup\$

A USB to UART breakout board will do what you want. You can get one from Sparkfun for $15. They come in both 5v and 3.3 volt versions. No VID/PID is needed because the chip on the board already contains one from its manufacturer (FTDI).

The breakout board will appear as a virtual comm port on your computer.

enter image description here

In addition to the normal TX/RX leads, the control leads like DTR and RTS are brought out as well. You can use these to drive a transistor which in turn interfaces with your servo. (The DTR/RTS outputs of the FTDI chip may be adequate to drive you servo without a interface.)

For testing, you can use a terminal program than manipulates these leads, like RealTerm. You can also control it from a program which has access to comm ports. For example, you can control it from a Python script using the pySerial API.

enter image description here

\$\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.