Difference between revisions of "Control an LED via USB/RS232 adapter"

From ThorstensHome
Jump to: navigation, search
Line 1: Line 1:
Today I connected my [http://www.linuxintro.org/wiki/Usb-rs232-adapter USB to serial adapter] to my computer. Then I [http://www.saleplc.com/systemfile/eWebEditor/UploadFile/2011530204256173.JPG looked up which pin is TXD and which is GND]. Then I used python's serial library to switch on TXD, connected TXD to GND and the result can be seen here:
+
Today I lighted an LED using my [http://www.linuxintro.org/wiki/Usb-rs232-adapter USB to serial adapter]. Here is how it looks:
  
 
[[File:Led-on-rs232.png]]
 
[[File:Led-on-rs232.png]]
 +
 +
Here is how it works:
 +
* Connect your USB to serial adapter to your computer.
 +
* Find out what device name it got using dmesg:
 +
[29231.270163] usb 2-1.6: pl2303 converter now attached to '''''ttyUSB0'''''
 +
: in this case it is /dev/ttyUSB0
 +
* Find out [http://www.saleplc.com/systemfile/eWebEditor/UploadFile/2011530204256173.JPG which pin is TXD and which is GND]. PIN 3 is TXD and PIN 5 is GND.
 +
* Write a small python program to switch on the TXD pin on the respective device:
 +
import serial, time
 +
conn = serial.Serial('/dev/ttyUSB0',
 +
                    baudrate=9600,
 +
                    bytesize=serial.EIGHTBITS,
 +
                    parity=serial.PARITY_NONE,
 +
                    stopbits=serial.STOPBITS_ONE,
 +
                    timeout=1,
 +
                    xonxoff=0,
 +
                    rtscts=0)
 +
conn.setBreak(True)
 +
* '''know''' that you can probably hold an LED directly to the pins as they should contain current limiters.
 +
* '''know''' that PIN 5 holds 0V and all other PINs hold 0V or +5V usually
 +
* So risk it and hold the long pin (plus) to PIN 3 and the short one to PIN 5
  
 
Why does this work? Because there is a limiter that limits the power so the LED does not break.
 
Why does this work? Because there is a limiter that limits the power so the LED does not break.

Revision as of 13:44, 30 September 2012

Today I lighted an LED using my USB to serial adapter. Here is how it looks:

Led-on-rs232.png

Here is how it works:

  • Connect your USB to serial adapter to your computer.
  • Find out what device name it got using dmesg:
[29231.270163] usb 2-1.6: pl2303 converter now attached to ttyUSB0
in this case it is /dev/ttyUSB0
import serial, time
conn = serial.Serial('/dev/ttyUSB0',
                    baudrate=9600,
                    bytesize=serial.EIGHTBITS,
                    parity=serial.PARITY_NONE,
                    stopbits=serial.STOPBITS_ONE,
                    timeout=1,
                    xonxoff=0,
                    rtscts=0)
conn.setBreak(True) 
  • know that you can probably hold an LED directly to the pins as they should contain current limiters.
  • know that PIN 5 holds 0V and all other PINs hold 0V or +5V usually
  • So risk it and hold the long pin (plus) to PIN 3 and the short one to PIN 5

Why does this work? Because there is a limiter that limits the power so the LED does not break. If I connect RI and TXD then via an LED it shines, plus RI's state, read by python, turns from off to on.

See also