Modbus RTU
Modbus RTU
1200/2400/4800/9600 bps
SPDT (Single Pole Double Throw)
5A/250VAC or 5A/30VDC
5-24VDC
1.5W
-20C to 70C
-40C to 85C
5-95% RH
128mm x 85mm x 25mm
approximately 160g
Documents and Resources
For more information, please refer to the product datasheet, user manual, and technical documentation available on the Waveshare website.
Warranty and Support
The Waveshare Modbus RTU 8-channel Relay Module RS485 is backed by a one-year warranty and supported by Waveshare's dedicated technical support team.
Waveshare Modbus RTU 8-channel Relay Module RS485 Documentation
Overview
The Waveshare Modbus RTU 8-channel Relay Module RS485 is an IoT component designed to control up to 8 relays remotely through a Modbus RTU protocol using an RS485 communication interface. This module is ideal for industrial automation, building automation, and IoT projects that require remote relay control.
Hardware Specifications
8-channel relay module with LED indicators
Modbus RTU protocol support
RS485 communication interface
Supports 9600, 19200, 38400, and 57600 baud rates
Power supply: 12V DC
Operating temperature: -20C to 75C
Software Library
To interact with the Waveshare Modbus RTU 8-channel Relay Module RS485, a Modbus RTU library is required. For this example, we will use the popular pyModbusRTU library.
Code Examples
### Example 1: Controlling Relays using Python (with pyModbusRTU)
In this example, we will use Python to control the relays using the pyModbusRTU library.
```
import pyModbusRTU
# Set up the Modbus RTU connection
modbus = pyModbusRTU.ModbusRTU('COM3', 9600, 8, 'N', 1) # Replace 'COM3' with your serial port
# Set up the relay module address and function code
slave_address = 1
function_code = 0x05 # Write single coil
# Turn on relay 1
modbus.send(slave_address, function_code, 0x00, 0xFF00) # Coil 0 is relay 1
# Turn off relay 1
modbus.send(slave_address, function_code, 0x00, 0x0000)
# Close the Modbus connection
modbus.close()
```
### Example 2: Automating Relay Control using a Python Script (with pyModbusRTU and scheduling)
In this example, we will create a Python script that uses the pyModbusRTU library to control the relays at specific times using the schedule library.
```
import pyModbusRTU
import schedule
import time
# Set up the Modbus RTU connection
modbus = pyModbusRTU.ModbusRTU('COM3', 9600, 8, 'N', 1) # Replace 'COM3' with your serial port
# Set up the relay module address and function code
slave_address = 1
function_code = 0x05 # Write single coil
def turn_on_RELAY_1():
modbus.send(slave_address, function_code, 0x00, 0xFF00) # Coil 0 is relay 1
def turn_off_RELAY_1():
modbus.send(slave_address, function_code, 0x00, 0x0000)
# Schedule the relay control tasks
schedule.every(1).minutes.do(turn_on_RELAY_1) # Turn on relay 1 every 1 minute
schedule.every(2).minutes.do(turn_off_RELAY_1) # Turn off relay 1 every 2 minutes
while True:
schedule.run_pending()
time.sleep(1)
# Close the Modbus connection when the script is stopped
modbus.close()
```
### Example 3: Controlling Relays using C++ (with libmodbus)
In this example, we will use C++ to control the relays using the libmodbus library.
```
#include <modbus.h>
int main() {
// Set up the Modbus RTU connection
modbus_t ctx = modbus_new_rtu("/dev/ttyUSB0", 9600, 'N', 8, 1); // Replace '/dev/ttyUSB0' with your serial port
modbus_set_slave(ctx, 1);
// Set up the relay module address and function code
uint8_t slave_address = 1;
uint8_t function_code = 0x05; // Write single coil
// Turn on relay 1
uint16_t coil = 0x0001;
modbus_write_bit(ctx, slave_address, function_code, 0x00, &coil);
// Turn off relay 1
coil = 0x0000;
modbus_write_bit(ctx, slave_address, function_code, 0x00, &coil);
// Close the Modbus connection
modbus_free(ctx);
return 0;
}
```
Note: The above code examples are for illustration purposes only and may require modifications to fit your specific project requirements. Additionally, ensure to replace the serial port and other configuration parameters with your actual setup.