I bought a china usb 8 relay switch board. It shows up in ubuntu server as a serial device. I figured out the commands to get it to work.
*Set Baud Rate of relay board
stty -F /dev/ttyUSB0 9600 -parity cs8 -cstopb
To start relay controller:
echo -e -n "x50" > /dev/ttyUSB0
To activate relay for commands:
echo -e -n "x51" > /dev/ttyUSB0
To turn on relay
echo -e -n "x(number)" > /dev/ttyUSB0*
But my issue is if I turn on relay 1 (/x01) and then turn on relay 2 (/x02) relay 1 turns off. I’m trying to automate and will need it to turn on more than one relay at a time. I went thru with testers and started mapping each number, Like 03 turns on relay 01 and 02. But there has to be an easier way. Any help would be grateful.
2
Answers
It is a bitwise control.
For example to turn on only port 0 (the first), you send xFE.
Essentially take 255 and subtract these values for each port you wish to start:
|Port|Number|
|–| —|
|0|1|
|1|2|
|2|4|
|3|8|
|4|16|
|5|32|
|6|64|
|7|128|
To turn relay 1, 4, 5, and 7 you need to send:
In hex 109 is 6D, so send x6D to the device.
A more visual example:
Known issues:
rm -f /dev/ttyUSB0