Control Con Computadora

Embed Size (px)

Citation preview

  • 8/13/2019 Control Con Computadora

    1/12

    10 minute bidirectional USB controlby Denkimono

    This is a simple method to quickly enable USB control of external devices without usingmicrocontrollers or expensive dev boards. Both input and output are possible allowing two way

    interaction with the environment.

    The pro!ect is based around a generic USB"Serial converter and a small number of discrete

    components likely to be found in any well"stocked !unk box. #ode examples are given for controlof the interface and simple to construct examples are given throughout. $ originally developed this

    interface to build an office control system  but have since used it on many pro!ects where $ wanted

    quick results and didn%t need the complexity of full USB control.

    Preview of the steps involved:&. 'verview " how does it work(

    ). 'utput

    *. 'utput examples+ ,-D control and motorised flashing beacon notification. $nput

    /. $nput example+ signature hotkey

    0n arbitrary number of interfaces can be controlled by the same host machine via hubs etc. which

    combined with the low cost of USB"Serial converters makes this a great starting point for manypro!ects.

    http://www.instructables.com/member/Denkimono/http://www.frisnit.com/telemetry/http://cdn.instructables.com/FLO/RRX8/GQRAVNJH/FLORRX8GQRAVNJH.LARGE.jpghttp://www.instructables.com/member/Denkimono/http://www.frisnit.com/telemetry/

  • 8/13/2019 Control Con Computadora

    2/12

    Step 1: Overview

    The pinout of a standard 1"pin serial connector is shown in the diagram. $n addition to the 2xD andTxD data lines a number of signals are exposed that can be put under software control. These are

    the modem control lines. 3or input these are D#D DS2 2$ #TS while for output we can use DT2and 2TS. The 2S)*) logic levels for the modem control lines are logic 4$54 6&7+ anywhere

    between *8 and &/8 logic ,'9 6:7+ anywhere between "*8 and "&/8. ;ote that this is the reverse

    of those used by the 2xD and TxD serial data line levels.

    These levels mean they can%t be interfaced directly with the TT, logic levels of 4$54

  • 8/13/2019 Control Con Computadora

    3/12

    :8 and /8. The addition of the diode prevents damage to the transistor due to the reverse base"

    emitter voltage when the 2S)*) input is logic ,'9 6"*8 to "&/87.

    Step 3: Output examples: !" and beacon

    The USB specification allows USB ports to drive a load of up to &::m0 which even allowing forthe power required for the adapter is plenty to drive an ,-D. The 2S)*) to ,-D driver is shown in

    the first image. $f you can open your USB serial adapter then you can tap the 3 from the motor damaging thetransistor.

    The attached file %serialcontrol.c% can be used to control both these circuits. $t allows the level on the

    http://cdn.instructables.com/FPB/LENT/GQRB1X56/FPBLENTGQRB1X56.LARGE.jpghttp://cdn.instructables.com/FIN/7IX0/GQRB1X58/FIN7IX0GQRB1X58.LARGE.jpg

  • 8/13/2019 Control Con Computadora

    4/12

    2TS line to be switched from the command line for example+

    serialcontrol ?dev?ttyUSB: on

    This makes it simple to control the beacon from a script allowing you to make an incoming emailindicator or a server monitor indicator etc. ;ote that the circuits in both of these examples invert the

    input so you%ll have to turn the port %off% to switch the device on.

    ;ow we !ust need to capture some input and we can really begin to interact with our environment@

    serialcontrol.c& AB

    Step #: $nput

    $nput is a little more tricky. 9e can use the

  • 8/13/2019 Control Con Computadora

    5/12

    Step %: $nput example: Si&nature hot'e(

    0 simple input example is the Csignature hotkeyC. This allows a preset word or phrase to be

    automatically pasted when an external button is pressed. This is particularly useful if like me youhave an awkward surname or if you have to end all your documents with a set phrase. 3or example

    a British railways employee might want to assign the phrase C9e apologise for any inconveniencecaused to your !ourney.C

    The attached file %hotkey.c% gives an example of a daemon process that monitors the external hotkey.9hen the hotkey is pressed the daemon sends the phrase to the currently active window as a series

    of keypresses. This saves me considerable time when filling in online forms or writing letters. The

    daemon uses T$'#>$90$T to sleep while waiting for a keypress and then sleeps for a fewmilliseconds afterwards to debounce the key before sending the phrase.

    hotkey.c* AB

    http://www.instructables.com/files/orig/FKV/8AWW/GQRB1YUT/FKV8AWWGQRB1YUT.chttp://www.instructables.com/files/orig/FKV/8AWW/GQRB1YUT/FKV8AWWGQRB1YUT.chttp://cdn.instructables.com/FMU/MHB8/GQRBNR1N/FMUMHB8GQRBNR1N.LARGE.jpghttp://www.instructables.com/files/orig/FKV/8AWW/GQRB1YUT/FKV8AWWGQRB1YUT.c

  • 8/13/2019 Control Con Computadora

    6/12

    Serial )ontrolled *ariable Speed +otorby westfw

    #ontrol the speed of a small D# motor with nothing but the serial port on your computer a single>'S3-T and some trivial software. 6The >'S3-T and the serial port make up the CspeedcontrolC you%ll still need a motor and an appropriate power supply for that motor while the serial

    port can provide the voltage to turn a mosfet on and off it can%t supply the current needed by atypical motor.7

    http://www.instructables.com/member/westfw/http://cdn.instructables.com/FU0/AIQ0/4P0EUF10PJ9/FU0AIQ04P0EUF10PJ9.LARGE.jpghttp://www.instructables.com/member/westfw/

  • 8/13/2019 Control Con Computadora

    7/12

    Step 1: oo' at the circuit

    9e%re going to do ulse 9idth >odulation using a generic ;"channel power >'S3-T connected tothe Transmit data pin from the computer%s rs)*) port. 9hen the serial port is idle the pin will sit atthe C&C state which by the time it%s translated to rs)*) is something like "&)8 6depending on

    drivers it might be closer to "18 or "/87 and the transistor will be quite '33. 9hen we transmitC:C bits on the serial port the rs)*) pin will go to

  • 8/13/2019 Control Con Computadora

    8/12

    Step 2: ,ire it up

    Since there%s only a single component and only a few connections you can !ust add wires

    Cfreeform.C

    >'S3-Ts are static sensitve so be a little bit careful but very little is critical.

    http://cdn.instructables.com/FO4/6H03/VKIEUF10PGV/FO46H03VKIEUF10PGV.LARGE.jpg

  • 8/13/2019 Control Con Computadora

    9/12

  • 8/13/2019 Control Con Computadora

    10/12

    Step #: Pla( with "OS: confi&ure (our )O+ port and cop(the files

    1J:: bps is a common bitrate. $t matches nicely to CaboutC one byte per millisecond so in this case

    it corosponds to a 9> frequency of &:::4K which $ think ought to be ok for smallish motors.Eou can experiment with different bit rates to see how things work which is one of the advantagesof this method.

    #reate a D'S 6or C#ommand promptC7 window 6assuming you%re using a windows 'S7 andconfigure

    your com port like+

    mode com1: -.00/n//1

    That tells the comm port to run at 1J::bps and send H bits in each character 6to match up with our

    H different bit"lengths.7 The CnC means ;' parity so those will be the only data bits. The C&C meansthere will be one CstopC bit which will prevent us from turning the motor all the way on 6oh well.7

    http://cdn.instructables.com/FU0/AIQ0/4P0EUF10PJ9/FU0AIQ04P0EUF10PJ9.LARGE.jpg

  • 8/13/2019 Control Con Computadora

    11/12

    So now you can turn on the motor with commands like+

    cop( 0pwm com1:

    Since we%re sending /::: characters at about & per millisecond the motor should turn on at close tofull speed for about / seconds. $f you want less than / seconds make a shorter file. Similarly you

    can do+

    cop( 12pwm com1:

    to run the motor at the lowest possible speed. 9ith the setup $ had the motor wouldn%t turn at all

    with anything CslowerC than *&.pwm but E>>8 6$ think $ had a &)8 motor running off /8 ofbatteries.7

    The #'E command lets you string files together so if you want your motor to speed up and thenslow down again you can do something like+

    cop( 31pwm1%pwmpwm0pwmpwm1%pwm31pwm com1:

    Step %: )ontrol the motor from a pro&ram

    $f you%re writing a program you can probably open #'>&+ as a file and simply write to it as if it

    were any other file. Being able to time the periods that the motor is on by outputting a particular

    number of characters would seem to be very handy. Don%t forget that the system is very likely tobuffer the characters that you send to the serial port so !ust because a 92$T- call returns doesn%tmean that the motor has finished doing whatever you told it to. Since we don%t do anything CfancyC

    with the com port signals you shouldn%t have to investigate the arcane options that it might support.

    6although if you can figure out how to send a B2-0A sequence to the com port that%s a continuousC:C state and will drive the motor 0,, the way on more than sending continuous : characters.7

    $f your programming language doesn%t let you output to #'>&+ you may still be able to control the

    motor by CcallingC D'S to do copy commands.

    6'A. $%ve downloaded >icrosoft%s 8isual Basic -xpress )::/ 6which is free7 and managed to tie a

    horiKontal scroll bar to the motor speed controlled via the serial port. Kip attached. $t%s probably gotmore than it needs to duplicate the program on your system but $ couldn%t figure out exactly which

    bits were needed. The program is both simplified and made more difficult to understand 6sorry7 by

    http://cdn.instructables.com/FBB/SYXD/UOYEUHSVMPG/FBBSYXDUOYEUHSVMPG.LARGE.jpg

  • 8/13/2019 Control Con Computadora

    12/12

    being multi"threaded. 'ne thread does nothing but output to the serial port and the main thread

    reads the scroll bar and updates info used by the serial thread.7

    #omSpeed.KipJ) AB

    Step .: !xperiment4

    $f things are basically working this provides an awful lot of room for experimentation.

    • 3ix my bit patterns@

    • Does the bitrate matter much(

    • Do you have to control the width of ConC and CoffC pulses or is simply controling their ratiosufficient(

    • $f you only have to control the ratio you can consider multi"character sequences at higher

    bit rates to get more speed levels. 'utputing : followed by &)H would be about half on.

    • This should work for dimming flashlight bulbs too.

    http://www.instructables.com/files/orig/F7S/LMZC/VFJEUHSVMQJ/F7SLMZCVFJEUHSVMQJ.ziphttp://cdn.instructables.com/F0H/6J78/B7MEUFUB60S/F0H6J78B7MEUFUB60S.LARGE.jpghttp://www.instructables.com/files/orig/F7S/LMZC/VFJEUHSVMQJ/F7SLMZCVFJEUHSVMQJ.ziphttp://www.instructables.com/files/orig/F7S/LMZC/VFJEUHSVMQJ/F7SLMZCVFJEUHSVMQJ.zip