Press a reset button or recycle the power of your board programmatically, with command-line interface remote switch!
A relay is an switch that operated by electricity. It could be controlled by a GPIO signal.
However, there is no GPIO available in most PCs. Instead, we have a USB to UART controller that can emulate one GPIO pin.
We can't control the state of the TX/RX manually. But RTS
, Request To Send, is a software-controlled pin that could be used as a GPIO.
- 1x USB to UART(TTL) converter
- 1x 5V relay
- a few jumper wires
USB to UART
converter
┌─────────────────────────┐
│ VCC ├──────────┐
┌────────────────┐ │ voltage │ │ RELAY
│ │ │ selector GND ├───────┐ │ ┌───────────────┐ RESET
│ ┌───┤ ├───┐ │ │ └──┤ VCC NO ├───x SWITCH
│ │ U │ │ U │ 3V3 TXD ├───x │ │ │ ┌──────────┐
│ PC │ S │=====│ S │ ┌─────┐ │ └─────┤ GND COM ├───────┤ │
│ │ B │ │ B │ │ VCC │ RXD ├───x │ │ │ │
│ └───┤ ├───┘ │ │ │ ┌─────┤ SIG NC ├───────┤ │
│ │ │ │ 5V │ RTS ├───────┘ └───────────────┘ └──────────┘
└────────────────┘ │ └─────┘ │
│ CTS ├───x
└─────────────────────────┘
- To correctly power up the relay, the voltage selector at the UART converter must be set to 5V.
- Since the state of the RTS pin is HIGH when idle, the relay will kept turned on. It will turned off only when the
ON()
function is called. This is why the switch is connected to theNC
terminal instead ofNO
.- Relay's
NO
andNC
terminals are Normally Open and Normally Close.
- Relay's
Implement your own switch logic in main.c and compile it with relay.c.
gcc relay.c main.c -o switch
gcc relay.c examples/push_return.c -o push-return # example
Then put the executable to somewhere in PATH
.
./switch /dev/<your_uart_converter>
./push-return /dev/cu.usbmodem51850106861 # example
ON(ms)
connects, andOFF(ms)
disconnects theCOM
and theNC
terminal of the relay electrically, for the duration ofms
.
- example/push_return.c: simple push-return(tact) switch press (ex. T2080RDB reset button)
- example/push_toggle.c: push-toggle switch on&off (ex. IMA-FCC-T2080 power switch)