This Python project can control up to 64 individual 8 channel R421A08 relay boards from the command line and GUI. It uses a universal USB - RS485 dongle.
The following hardware is required for this project:
WARNING: DO NOT USE THIS RELAY BOARD WITH 230V AC!
The distance between relay traces on the PCB are < 2mm without holes for isolation. This is dangerous when using it with high voltages. See the picture above.
The 16 relay board version works by changing
NUM_RELAYS = 16
in
R421A08.py
as reported by a user in
issue #1
.
This project requires a RS485 - USB dongle which is widely available, for example:
Device Manager
|
Ports (COM & LPT)
to find the
USB-SERIAL CH340 (COMxx)
serial port.
dmesg
command to find the serial port, such as
/dev/ttyUSB0
.
import time
import relay_boards
if __name__ == '__main__':
print('Getting started R421A08 relay board\n')
# Create MODBUS object
_modbus = relay_modbus.Modbus(serial_port=SERIAL_PORT)
# Open serial port
try:
_modbus.open()
except relay_modbus.SerialOpenException as err:
print(err)
sys.exit(1)
# Create relay board object
board = relay_boards.R421A08(_modbus, address=1)
print('Status all relays:')
check(board.print_status_all())
time.sleep(1)
print('Turn relay 1 on')
check(board.on(1))
time.sleep(1)
print('Turn relay 1 off')
check(board.off(1))
time.sleep(1)
print('Toggle relay 8')
check(board.toggle(8))
time.sleep(1)
print('Latch relays 6 on, all other relays off')
check(board.latch(6))
time.sleep(1)
print('Turn relay 4 on for 5 seconds, all other relays off')
check(board.delay(4, delay=5))
time.sleep(6)
print('Turn relays 3, 7 and 8 on')
check(board.toggle_multi([3, 7, 8]))
time.sleep(1)
print('Turn all relays on')
check(board.on_all())
time.sleep(1)
print('Turn all relays off')
check(board.off_all())
time.sleep(1)
Please refer to the Wiki page for installation and usage.
MODBUS Application Protocol Specification v1.1.b
The following Python packages are available in this project:
MODBUS is an open binary serial communication protocol, mainly used for PLCs.
--send
option.