Modbus RTU Relay
| ||
Overview
Electrical Safety Precautions
- This product must be operated by a professional electrician or technical personnel. During use, please ensure electrical safety and take protective measures against electric leakage and insulation.
- Before installing, maintaining, or replacing relay equipment, make sure to turn off the power and unplug the device.
- Do not attempt to disassemble the relay equipment to avoid damaging the device or causing the risk of electric shock.
- Please properly install and place the relay equipment. Avoid using it in damp, overly hot, or flammable environments to prevent safety accidents due to improper installation or use.
Hardware Test
RS485 Test
- Connect the USB TO 485 to the target board via cables, A-A and B-B connected as shown below:
- Download the SSCOM and open it on the computer. Open the corresponding port number, set the baud rate as 9600, and click Multi-Char to open the Send Multi-Char window, click the function to send the corresponding command.
- If you need to send other commands then select HEX to send, plus check select ModbusCRC16 checksum, enter the first six bytes of the command, and click send then the CRC checksum will be added automatically.
- For more detailed control commands, you can see them in the "Development Protocol".
From September 2024, the development protocol will adopt Version 3. Version 3 is compatible with Version 2 and will add some new features.
Modbus Poll Software
- If the serial port software is inconvenient for observing data, you can choose to use Modbus Poll software to read data. Download and install the Modbus Poll software.
- Open the software, select setup -> Read/Write Definition, choose the actual device address for Slave ID, select Function 01 Read Coils for the function code, and change the Quantity to 8 channels. Click OK to confirm.
- Select Connection -> Connect..., choose the corresponding serial port, with a baud rate of 9600, and 8-bit no parity mode. Click OK to connect.
- After a normal connection, you can view the current relay status. Select the corresponding channel, and double-click the status value to bring up the send page. Choose ON or OFF, and then send to control the corresponding relay to open or close.
Demo Test
Note: RS485 can not be directly connected to the serial port of the Raspberry Pi, otherwise it may burn the device, you need to add 485 level conversion, the Raspberry Pi is recommended to use with the RS485 CAN HAT module, NUCLEO-F103RB, and Arduino is recommended to use with the RS485 CAN Shield module!
Raspberry Pi
Open the Raspberry Pi terminal and input the following commands to enter the configure interface:
sudo raspi-config Select Interfacing Options -> Serial, disable shell visit, and open the serial port hardware
And then reboot the Raspberry Pi:
sudo reboot
Open /boot/config.txt file, and find the following configure sentence to enable the serial ports. If there is none, you can add it at the end of the file.
enable_uart=1
For Raspberry Pi 3B users, the serial port is for Bluetooth and needs to be removed.
#dtoverlay=pi3-miniuart-bt
And then reboot the Raspberry Pi:
sudo reboot
If you want to insert the RS485 CAN HAT into the Raspberry Pi, connect the A and B ports of the Modbus RTU Relay module and the RS485 CAN HAT module.
If you use other 485 devices, you need to make sure A-A and B-B.
Run the following commands:
sudo apt-get install unzip wget https://files.waveshare.com/upload/f/f9/Modbus_RTU_Relay_Code.zip unzip Modbus_RTU_Relay_Code.zip cd Modbus_RTU_Relay_Code/Python3 sudo python3 main.py
STM32
The STM32 demos are based on the NUCLEO-F103RB and the RS485 CAN Shield module.
Find the STM32 program file directory and open the STM32 project. Note that before using the computer to ensure that the keil5 software has been installed, download the demo to the development board can be downloaded.
Normal operation of the relay module will turn on and then turn off in turn. The serial port will output the command sent.
Arduino
The Arduino demos are based on the UNO PLUS and RS485 CAN Shield modules.
Use Arduino IDE to open the demo, select the corresponding development board, and then download the demo.
The relay module will turn on and then turn off in order to run normally. The serial port will output the commands sent.
Development Protocol V3
Function Code
Function code | Overview | Description |
---|---|---|
01 | Read coil status | Read the state of Relay |
03 | Read holding register | Read the address and version |
05 | Write single coil | Write a single Relay |
06 | Write single register | Set baud rate and address |
0F | Write multiple coils | Write all Relays |
Register Address
Address (HEX) | Address Content Storage | Register Value | Permission | Modbus Function Code |
---|---|---|---|---|
0x0000 to 0x0007 | Relay address for channel 1 to channel 8 | 0xFF00: Relay on; 0x0000: Relay off; 0x5500: Relay toggle; |
Read/Write | 0x01,0x05,0x0F |
0x00FF | Operate all relays | 0xFF00: All relays on; 0x0000: All relays off; 0x5500: All relays toggle; |
Write | 0x05 |
0x0100 to 0x0107 | Toggle relays for channel 1 to channel 8 | 0xFF00: Relay toggle; 0x0000: Relay status unchanged; |
Write | 0x05,0x0F |
0x01FF | Toggle all relays | 0xFF00: All relays toggle; 0x0000: All relays status unchanged; |
Write | 0x05 |
0x0200 to 0x0207 | Flash open for relays of channel 1 to channel 8 | Delay time is data * 100ms Value: 0x0007, Delay: 7 * 100ms = 700ms | Write | 0x05 |
0x0400 to 0x0407 | Flash open for relays of channel 1 to channel 8 | Delay time is data * 100ms Value: 0x0007, Delay: 7 * 100ms = 700ms | Write | 0x05 |
4x2000 | Serial port parameters | High byte for checksum method: 0x00~0x02 Low byte for baud rate method: 0x00~0x07 | Read/Write | 0x03,0x06 |
4x4000 | Device address | Directly stores Modbus address Device address: 0x0001-0x00FF | Read/Write | 0x03,0x06 |
4x8000 | Software version | Convert to decimal and shift the decimal point two places to the left to represent the software version 0x0064 = 100 = V1.00 | Read | 0x03 |
Operation Command
Control Single Relay
Send code: 01 05 00 00 FF 00 8C 3A
Byte | Meaning | Description |
---|---|---|
01 | Device address | 0x00: the broadcast address; 0x01-0xFF: device addresses |
05 | 05 Command | Command for controlling Relay |
00 00 | Address | The register address of controlled Relay, 0x0000 - 0x0007 |
FF 00 | Command | 0xFF00: open Relay; 0x0000: close Relay; 0x5500: flip Relay |
8C 3A | CRC16 | The CRC16 checksum of the first six bytes |
Return code: 01 05 00 00 FF 00 8C 3A
Byte | Meaning | Description |
---|---|---|
01 | Device address | 0x00: the broadcast address; 0x01-0xFF: dives addresses |
05 | 05 Command | Command for controlling relay |
00 00 | Address | The register address of controlled Relay,0 x 0000-0 x 0008 |
FF 00 | Command | 0xFF00: open Relay; 0x0000: close Relay 0x5500: flip Relay |
8C 3A | CRC16 | The CRC16 checksum of the first six bytes. |
Examples:
[Device with address 01]:
Relay 0 ON: 01 05 00 00 FF 00 8C 3A Relay 0 OFF: 01 05 00 00 00 00 CD CA Relay 1 ON: 01 05 00 01 FF 00 DD FA Relay 1 OFF: 01 05 00 01 00 00 9C 0A Relay 2 ON: 01 05 00 02 FF 00 2D FA Relay 2 OFF: 01 05 00 02 00 00 6C 0A Relay 3 ON: 01 05 00 03 FF 00 7C 3A Relay 3 OFF: 01 05 00 03 00 00 3D CA Relay 0 Flip: 01 05 00 00 55 00 F2 9A Relay 1 Flip: 01 05 00 01 55 00 A3 5A Relay 2 Flip: 01 05 00 02 55 00 53 5A Relay 3 Flip: 01 05 00 03 55 00 02 9A
Control All Relays
Send code: 01 05 00 FF FF 00 BC 0A
Byte | Meaning | Description |
---|---|---|
01 | Device Address | 0x00: the broadcast address; 0x01-0xFF: device address |
05 | 05 Command | Control relays |
00 FF | Address | Fixed 0x00FF |
FF 00 | Command | 0xFF00: Relay on 0x0000: Relay off 0x5500: Relay flips |
BC 0A | CRC16 | The CRC16 checksum of the first six bytes |
Return code: 01 05 00 FF FF 00 BC 0A
Byte | Meaning | Description |
---|---|---|
01 | Device address | 0x00: the broadcast address; 0x01-0xFF: devices address |
05 | 05 command | Command for controlling Relay |
00 FF | Address | Fixed 0x00FF |
FF 00 | CRC16 | 0xFF00: Relay open; 0x0000: Relay close; 0x5500: Relay flip |
BC 0A | CRC16 | The CRC16 checksum of the first six bytes |
Example:
[Device with Address 01]:
All relays open: 01 05 00 FF FF 00 BC 0A All relays closed: 01 05 00 FF 00 00 FD FA All relays flip: 01 05 00 FF 55 00 C2 AA
Read States of Relays
Send code: 01 01 00 00 00 08 3D CC
Bytes | Meaning | Description |
---|---|---|
01 | Device address | 0x00: the broadcast address; 0x01-0xFF: device addresses |
01 | 01 Command | Command for checking states of Relay |
00 00 | Relay start address | The register address for the relays,0x0000-0x0007 |
00 08 | Quantity | The quantity of relays to be read, should not exceed the maximum number of relays. |
3D CC | CRC16 | The CRC16 checksum of the first six bytes |
Return code: 01 01 01 00 51 88
Byte | Meaning | Description |
---|---|---|
01 | Device address | 0x00: the broadcast address; 0x01-0xFF: device addresses |
01 | 01 Command | Command for checking states of Relay |
01 | Number | The number of bytes returned |
00 | State | The state of Relay Bit0: The state of the first Relay; Bit1: The state of the second Relay; Bit2: The state of the third Relay; …… Bit7: The state of the eighth Relay |
51 88 | CRC16 | The CRC16 checksum of the first six bytes |
Examples:
[Device with Address 01]
Send: 01 01 00 00 00 08 3D CC Return: 01 01 01 00 51 88 //Close all Relays Send: 01 01 00 00 00 08 3D CC Return: 01 01 01 01 90 48 //Open Relay 0 and close other Relays Send: 01 01 00 00 00 08 3D CC Return: 01 01 01 41 91 B8 //Open Relay 0 and Relay 6, close other Relays
Write States of Relays
Send code: 01 0F 00 00 00 08 01 FF BE D5
Bytes | Meaning | Description |
---|---|---|
01 | Device address | 0x00: the broadcast address; 0x01-0xFF: the device address |
0F | 0F Command | Write Relay Status Command |
00 00 | Relay start address | The register address for the relays,0x0000-0x0007 |
00 08 | Quantity | The quantity of relays to be read, should not exceed the maximum number of relays. |
01 | Number of bytes | Status byte count |
FF | Relay Status | Bit0: control the first relay; Bit1: control the second relay; Bit2: control the third relay; …… Bit7: Control the eighth relay |
BE D5 | CRC16 | CRC16 checksum of the first 6 bytes of data |
Return code: 01 0F 00 00 00 01 94 0B
Bytes | Meaning | Description |
---|---|---|
01 | Device address | 0x00: the broadcast address; 0x01-0xFF: the device address |
0F | 0F Instruction | All Register Control Instructions |
00 00 | Relay start address | The register address for the relays,0x0000-0x0007 |
00 08 | Quantity | Control the quantity of relays. |
54 0D | CRC16 | CRC16 checksum of the first 6 bytes of data |
Example:
[Device with Address 01]
All relays on: 01 0F 00 00 00 08 01 FF BE D5 All relays off: 01 0F 00 00 00 08 01 00 FE 95 0-1 ON; 3-7 OFF: 01 0F 00 00 00 08 01 03 BE 94
Relay Flash ON/OFF Command
Send code: 01 05 02 00 00 07 8D B0
Bytes | Meaning | Description |
---|---|---|
01 | Device address | 0x00: the broadcast address; 0x01-0xFF: the device address |
05 | 05 Command | Single Control Command |
02 | Command | 02 for flashing on, 04 for flashing off |
00 | Relay Address | The address of the relay to be controlled, 0x00~0x07 |
00 07 | Interval time | Delay time is data*100ms Value: 0x0007, delay: 7*100MS = 700MS |
8D B0 | CRC16 | CRC16 checksum of the first 6 bytes of data |
Return code: 01 05 02 00 00 07 8D B0
Bytes | Meaning | Description |
---|---|---|
01 | Device address | 0x00: the broadcast address; 0x01-0xFF: the device address |
05 | 05 Command | Single Control Command |
02 | Command | 02 for flashing on, 04 for flashing off |
00 | Relay address | To control the relay address, 0x00~0x07 |
00 07 | Interval time | Delay time is data*100ms Value: 0x0007, delay: 7*100MS = 700MS |
8D B0 | CRC16 | CRC16 checksum of the first 6 bytes of data |
Example:
[Device with Address 01]
No.0 relay flash on: 01 05 02 00 00 07 8D B0 //700MS = 7*100MS = 700MS No.1 relay flash on: 01 05 02 01 00 08 9C 74 //800MS No.0 relay flash off: 01 05 04 00 00 05 0C F9 //500MS No.1 relay flash off: 01 05 04 01 00 06 1D 38 //600MS
Set Baud Rate Command
Send code: 01 06 20 00 00 05 42 09
Bytes | Meaning | Description |
---|---|---|
01 | device address | 0x00: the broadcast address; 0x01-0xFF: the device address |
06 | 06 command | set baud rate and address |
20 00 | command register | 0x2000 sets the baud rate |
00 | parity | 0x00: no parity check, 0x01: even parity check, 0x02: odd parity check |
05 | baud rate value | the corresponding baud rate value: 0x00: 4800 0x01: 9600 0x02: 19200 0x03: 38400 0x04: 57600 0x05: 115200 0x06: 128000 0x07: 256000 |
42 09 | CRC16 | CRC16 checksum of the first 6 bytes of data |
Return code: 01 06 20 00 00 05 43 D8
Bytes | Meaning | Description |
---|---|---|
01 | Device address | 0x00: the broadcast address; 0x01-0xFF: the device address |
06 | 06 command | set baud rate and address |
20 00 | command register | 0x2000 sets the baud rate |
00 | parity | 0x00: no parity check, 0x01: even parity check, 0x02: odd parity check |
05 | baud rate value | the corresponding baud rate value: 0x00: 4800 0x01: 9600 0x02: 19200 0x03: 38400 0x04: 57600 0x05: 115200 0x06: 128000 0x07: 256000 |
42 09 | CRC16 | CRC16 checksum of the first 6 bytes of data |
Examples:
[Device with Address 01]
Set baud rate 4800: 01 06 20 00 00 00 82 0A Set baud rate 9600: 01 06 20 00 00 01 43 CA Set baud rate 115200: 01 06 20 00 00 05 42 09
Set Device Address Command
Send code: 01 06 40 00 00 01 5D CA
Bytes | Meaning | Description |
---|---|---|
01 | device address | 0x00: the broadcast address; 0x01-0xFF: the device address |
06 | 06 command | set the baud rate and device address |
40 00 | command register | 0x4000 sets the device address |
00 01 | device address | set the device address as 0x0001-0x00FF |
5D CA | CRC16 | CRC16 checksum of the first 6 bytes of data |
Return code: 01 06 40 00 00 01 5D CA
Bytes | Meaning | Description |
---|---|---|
01 | device address | 0x00: the broadcast address; 0x01-0xFF: the device address |
06 | 06 command | set the baud rate and device address |
40 00 | command register | 0x4000 sets the device address |
00 01 | device address | set the device address as 0x0001-0x00FF |
5D CA | CRC16 | CRC16 checksum of the first 6 bytes of data |
Examples:
[Device with Address 01]
Set device address as 0x01: 00 06 40 00 00 01 5C 1b Set device address as 0x02: 00 06 40 00 00 02 1C 1A Set device address as 0x03: 00 06 40 00 00 03 DD DA
Read Device Address Command
Send code: 00 03 40 00 00 01 90 1B
Bytes | Meaning | Description |
---|---|---|
00 | Device address | 0x00: the broadcast address; 0x01-0xFF: the device address |
03 | 03 command | read the device address command |
40 00 | command register | 0x4000: read the device address |
00 01 | bytes | fixed 0x0001 |
90 1B | CRC16 | CRC16 checksum of the first 6 bytes of data |
Return code: 00 03 02 00 01 44 44
Bytes | Meaning | Description |
---|---|---|
00 | device address | 0x00: the broadcast address; 0x01-0xFF: the device address |
03 | 03 command | Read the software version and the device address command |
02 | bytes | return bytes |
00 01 | device address | set the device address as 0x0001-0x00FF |
44 44 | CRC16 | CRC16 checksum of the first 6 bytes of data |
Examples:
[Device with Address 02]
Send: 00 03 40 00 00 01 90 1B Return: 00 03 02 00 02 04 45 //address 0x02
Read Software Version Command
Send code: 01 03 80 00 00 01 AD CA
Bytes | Meaning | Description |
---|---|---|
01 | Device address | 0x00: the broadcast address; 0x01-0xFF: the device address |
03 | 03 command | Read the software version and the device address command |
80 00 | Command register | 0x4000: read the device address, 0x8000: read the software version |
00 01 | Bytes | Fixed 0x0001 |
AD CA | CRC16 | CRC16 checksum of the first 6 bytes of data |
Return code: 01 03 02 01 2C B8 09
Bytes | Meaning | Description |
---|---|---|
01 | Device Adress | 0x00: the broadcast address, 0x01-0xFF: the device addresses |
03 | 03 Command | Read the software version and the device address command |
02 | Bytes | Return bytes |
01 2C | Software version | Convert to decimal and move the decimal point to the left by two places to indicate the software version 0x012C = 300 = V3.00 |
B8 09 | CRC16 | CRC16 checksum of the first 6 bytes of data |
Examples:
Send: 01 03 80 00 00 01 AD CA Return: 01 03 02 01 2C B8 09 //0x012C = 300 =V3.00
Exception Function Code
When an erroneous command is received or an abnormal condition occurs, the device will return an exception response. The format of the exception response is as follows.
Response Code: 01 85 03 02 91
Bytes | Meaning | Description |
---|---|---|
01 | Device address | 0x00: the broadcast address; 0x01-0xFF: the device address |
85 | Exception Function Code | Exception function code = requested function code + 0x80 |
03 | Byte Count | Exception code |
02 91 | CRC16 | CRC16 checksum of the first 6 bytes of data |
The exception code is a single byte value used to indicate the type of error. The Modbus protocol defines several common exception codes:
Exception code | Name | Description |
---|---|---|
0x01 | Illegal Function | The requested function code is not supported |
0x02 | Illegal Data Address | The requested data address is incorrect |
0x03 | Illegal Data Value | The requested data value or operation cannot be executed |
0x04 | Server Device Error | The server device has a malfunction |
0x05 | Acknowledge | The request has been received and is being processed |
0x06 | Device Busy | The device is currently busy and cannot perform the requested operation |
Resources
Program
Softwares
- Sscom software for Modbus RTU Relay V2
- Sscom software for Modbus RTU Relay
- Modbus Poll Software
- SecureCRT Software
Related resources
- Modbus Protocol Introduction
- Modbus Series BootLoader Instructions
- Development Protocol V2
- Development Protocol V1
FAQ
1、If the module does not respond to the command, verify that the baud rate and device ID are correct. You may also try Restoring the factory settings.
2、If the above steps do not resolve the issue, please submit a ticket to contact the Waveshare technical support team.
{{{5}}}
The temperature range of the relay component is -40°C- +85°C. The humidity is 40-85%RH.
{{{5}}}
The temperature range of the relay component is -40°C- +85°C Humidity is 40-85%RH
{{{5}}}
Support
Technical Support
If you need technical support or have any feedback/review, please click the Submit Now button to submit a ticket, Our support team will check and reply to you within 1 to 2 working days. Please be patient as we make every effort to help you to resolve the issue.
Working Time: 9 AM - 6 PM GMT+8 (Monday to Friday)