Control an LED via USB/RS232 adapter
Today I lighted an LED using my USB to serial adapter. Here is how it looks:
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 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. If I connect RI and TXD then via an LED it shines, plus RI's state, read by python, turns from off to on.