# Controlling a digital switch using Python through USB

I have an RF digital switch that takes two digital inputs (AB) in order to decide from which antenna port to take the input. Is their a simple way to use Python to send the AB values through the USB port to this switch?

The pseudo code would be something like this:

while(1):
Switch antenna
Read the input
Do some processing


Thank you very much.

• I don't see a USB port on this device. It seems to be a 4 pole switch. – CFCBazar com May 5 '20 at 22:22
• You will need an additional device to connect the RF switch to USB. There are many options. Google USB GPIO: google.com/search?q=usb+gpio – Drew May 5 '20 at 22:32
• Thank you guys for your comments. Yes, there is no USB port for the switch. I know there should be some kind of device between the switch and the computer USB port but I wasn't sure what kind of device I should use! I'll check the google search again! – HadK May 5 '20 at 23:37

## 1 Answer

I think you could use a USB-UART (sometimes called USB-TTL) adapter module and co-opt one of the serial control output pins such as DTR or RTS. Make sure the module you pick has access to at least one of the control outputs. This could be extremely cheap (a dollar or two from China or maybe \$15-20 from Adafruit etc.) There are various chips such as CH340G, CH340E, PL2303, FT232RL etc., most or all of which have the control outputs on the chip but often not brought out to a convenient connector on modules since many applications need only TxD and RxD and power/ground.

That switch chip draws very little so you should also be able to draw the 3.3V from the USB bus via the adapter.

Here is some Python info regarding direct control of the handshaking pins.

As usual with direct connections to your computer, make sure no harmful voltages are connected to the circuitry, and consider the supply will be grounded through the USB in many cases.

• Thank you so much Spehro, this is very helpful!! – HadK May 6 '20 at 18:20