Modbus RTU Relay 16CH

From Waveshare Wiki
Jump to: navigation, search
Modbus RTU Relay 16CH
Modbus-rtu-relay-16ch-3.jpg

RS485
{{{name2}}}

{{{name3}}}

{{{name4}}}

{{{name5}}}

{{{name6}}}

Overview

Electrical Safety Precautions

  • This product should be operated and used by professional electricians or technical personnel. Please ensure electrical safety measures are in place, including protection against leakage and insulation.
  • Before installing, maintaining, or replacing relay equipment, always turn off the power and unplug the plug.
  • Do not attempt to dismantle relay equipment to avoid damaging the device or risking electric shock.
  • Please properly install and place relay equipment. Avoid use in damp, overheated, or flammable environments to prevent accidents caused by improper installation or use.

Introduction

This product is an industrial-grade RS485 interface controlled 8DI / 8DO digital isolated input-output module. It supports passive input/active input, utilizes Modbus RTU protocol, and includes built-in protection circuits such as power isolation, optocoupler isolation, self-resetting fuses, and TVS.

Hardware Test

RS485

  • Connect the USB TO 485 and the target board with the cables, connect A --> A and B --> B, as shown below:

Modbus POE ETH Rela2.jpg

  • Download Sscom5.13.1_for_Modbus_RTU_Relay_16CH and open it on the PC, open the corresponding port, and set the baud rate as 9600. Clicking on multiple strings opens multiple string-sending windows. Clicking on the corresponding function will send the corresponding command.
  • If you need to send other commands, select "HEX" as the sending format and choose "Modbus CRC16" as the checksum. When entering the command, if the first six bytes are provided and you click on "Send," the CRC checksum will be automatically added.

Modbus-RTU-Relay-32CH-SSCOM-01.png

  • For detailed control commands, please check the development protocol.

Demo Test

Note: RS485 cannot be directly connected to the Raspberry Pi's serial port as it may damage the devices. It requires a level converter for RS485. It is recommended to use an RS485 CAN HAT module with the Raspberry Pi. For NUCLEO-F103RB and Arduino, it is recommended to use an RS485 CAN Shield module.

Raspberry Pi

Open the Raspberry Pi, and input the following commands to enter the configure interface:

sudo raspi-config
Choose Interfacing Options -> Serial, disable shell visit, enable the hardware serial port

L76X GPS Module rpi serial.png
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/f0/Modbus_RTU_Relay_16CH_Code.zip
unzip Modbus_RTU_Relay_16CH_Code.zip
cd Modbus_RTU_Relay_16CH_Code/Python3
sudo python3 main.py

SRM32

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 program 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 NUO PLUS and RS485 CAN Shield modules.
Use Arduino IDE to open the program, select the corresponding development board and then download the program.
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

Function Code Introduction

Function Code Note
01 Read relay status
03 Read the address and version
05 Write a single relay
06 Set baud rate and address
0F Write all relays

Register address introduction

Address (HEX) Address storage content Register value Permission Modbus function code
0x0000
……
0x000F
1~6 channel relay address 0xFF00: Relay on;
0x0000: Relay off;
0x5500: Relay flipped;
Read/Write 0x01,0x05,0x0F
0x00FF Operate all registers 0xFF00: All relays are on;
0x0000: All relays are off;
0x5500: All relays are flipped;
Write 0x05
0x0200
……
0x020F
1~6 channel relay flash on The delay time is data*100ms
Value: 0x0007, delay: 7*100MS = 700MS
Write 0x05
0x0400
……
0x040F
1~6 channel relay flash off The delay time is data*100ms
Value: 0x0007, delay: 7*100MS = 700MS
Write 0x05
4x2000 Serial port parameters The upper eight bits are the check mode: 0x00~0x02
The lower eight bits are the baud rate mode: 0x00~0x07
Write 0x06
4x4000 Device address Direct storage Modbus address
Device address: 0x0001-0x00FF
Read/write 0x03,0x06
4x8000 Software version Convert to decimal and then move the decimal point two places to the left to indicate the software version
0x0064=100=V1.00
Read 0x03

Single Relay Control

Sending Code: 01 05 00 00 FF 00 8C 3A

Fields Meaning Remarks
01 Device Address 0x00 is the broadcast address; 0x01-0xFF is the device address
05 05 command Control the relay command
00 00 Address Control the register address of the relay, 0x00 - 0x000F
FF 00 Command 0xFF00: relay on
0x0000: relay off
0x5500: relay flip
8C 3A CRC16 CRC16 checksum of the first 6 bytes of data

Return code: 01 05 00 00 FF 00 8C 3A

Field Meaning Remarks
01 Device Address 0x00 is the broadcast address; 0x01-0xFF is the device address
05 05 command Control the relay commands
00 00 Address Control the register address of the relay: 0x0000-0x000F
FF 00 Command 0xFF00: relay on
0x0000: relay off
0x5500: relay flip
8C 3A CRC16 CRC16 checksum of the first 6 bytes of data

For example:
[No. 1 address device]: No. 0 relay on: 01 05 00 00 FF 00 8C 3A
No. 0 relay off: 01 05 00 00 00 00 CD CA
No. 1 relay on: 01 05 00 01 FF 00 DD FA
No. 1 relay off: 01 05 00 01 00 00 9C 0A
No. 2 relay on: 01 05 00 02 FF 00 2D FA
No. 2 relay off: 01 05 00 02 00 00 6C 0A
No. 3 relay on: 01 05 00 03 FF 00 7C 3A
No. 3 relay off: 01 05 00 03 00 00 3D CA
No. 0 relay flip: 01 05 00 00 55 00 F2 9A
No. 1 relay flip: 01 05 00 01 55 00 A3 5A
No. 2 relay flip: 01 05 00 02 55 00 53 5A
No. 3 relay flip: 01 05 00 03 55 00 02 9A

Control All Relays

Sending code: 01 05 00 FF FF 00 BC 0A

Fields Meaning Note
01 Device Address 0x00 is the broadcast address; 0x01-0xFF is the device address
05 05 Command Control relay commands
00 FF Address Fixed 0x00FF
FF 00 Command 0xFF00: relay on
0x0000: relay off
0x5500: relay flip
BC 0A CRC16 CRC16 checksum of the first 6 bytes of data

Return code: 01 05 00 FF FF 00 BC 0A

Fields Meaning Code
01 Device Address 0x00 is the broadcast address; 0x01-0xFF indicates the device address
05 05 command Control the relay commands
00 FF Address Fixed 0x00FF
FF 00 Commands 0xFF00: relay on
0x0000: relay off
0x5500: relay flip
BC 0A CRC16 CRC16 checksum of the first 6 bytes of data

For example:

[No. 1 address device]:

All relays on: 01 05 00 FF FF 00 BC 0A
All relays off: 01 05 00 FF 00 00 FD FA
All relays flip: 01 05 00 FF 55 00 C2 AA

Read the Relay Status

Sending code: 01 01 00 00 00 10 3D C6

Fields Meaning Note
01 Device Address 0x00 is the broadcast address; 0x01-0xFF indicates the device address
01 01 Command Query Relay Status Command
00 00 Relay Start Address Fixed 0x0000
00 10 Relay Numbers Fixed 0x0010
3D C6 CRC16 CRC16 checksum of the first 6 bytes of data

Return code: 01 01 02 00 00 B9 FC

Field Meaning Note
01 Device Address 0x00 is the broadcast address, 0x01-0xFF is the device address
01 01 Command Query Relay Status Command
02 Number of bytes Returns all bytes of the status information
00 00 Status of the query Returned relay status
Bit0: the first relay status;
Bit1: the second relay status;
Bit2: the third relay status;
……
Bit15: the 16th relay status.
B9 FC CRC16 CRC16 checksum of the first 6 bytes of data

For example:

[NO.1 address device]

Send: 01 01 00 00 00 08 3D CC
Return: 01 01 02 00 00 B9 FC //All relays off
Send: 01 01 00 00 00 08 3D CC
Return: 01 01 02 00 01 78 3C //Relay 0 is on, the rest of the relays are off.
Send: 01 01 00 00 00 08 3D CC
Return: 01 01 02 00 41 79 CC //Relays 0 and 6 are on, the rest are off

Write Relay Status

Sending code: 01 0F 00 00 00 10 02 FF FF E3 90

Field Meaning Note
01 Device address 0x00 is the broadcast address; 0x01-0xFF is the device address
0F 0F Command Write relay status command
00 00 Relay start address Fixed 0x0000
00 10 Relay numbers Fixed 0x0010
02 Byte count Fixed 0x02
FF FF Relay status Bit0: control the first relay;
Bit1: control the second relay;
Bit2: control the third relay;
……
Bit15: control the 16th relay
E3 90 CRC16 CRC16 checksum of the first 6 bytes of data

Return code: 01 0F 00 00 00 10 54 07

Field Meaning Note
01 Device Address 0x00 is the broadcast address; 0x01-0xFF is the device address
0F 0F command All register control commands
00 00 Relay start address Fixed 0x0000
00 10 Relay numbers Fixed 0x0010
54 07 CRC16 CRC16 checksum of the first 6 bytes of data

For example:

[No.1 address device]

All relays on: 01 0F 00 00 00 10 02 FF FF E3 90
All relays off: 01 0F 00 00 00 10 02 00 00 E2 20
0-1 ON; 3-15 OFF: 01 0F 00 00 00 10 02 00 03 A2 21

Relay Flash On and Flash Off Command

Sending code: 01 05 02 00 00 07 8D B0

Field Meaning Note
01 Device Address 0x00 is the broadcast address, 0x01-0xFF is the device address
05 05 Command Single control demmand
02 Command 02 is the command for flashing on, 04 is the command for flashing off
00 Relay Address The address of the relay to be controlled: 0x00~0x0F
00 07 Interval time Delay time for 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

Field Meaning Note
01 Device Address 0x00 is the broadcast address; 0x01-0xFF is the device adress
05 05 Command Single control command
02 Command 02 is the command for flashing on, 04 is the command for flashing off
00 Relay Address The address of the relay to be controlled: 0x00~0x0F
00 07 Interval time Delay time for data*100ms
Value: 0x0007, delay: 7*100MS=700MS
8D B0 CRC16 CRC16 checksum of the first 6 bytes of data

Note:

The maximum setting for the flash on/flash off time is 0x7FFF.

For example:

[No.1 address device]

Relay 0 flashes on: 01 05 02 00 00 07 8D B0 //700MS=7*100MS=700MS
Relay 1 flashes on: 01 05 02 01 00 08 9C 74 //800MS
Relay 0 flashes off: 01 05 04 00 00 05 0C F9 //500MS
Relay 1 flashes off: 01 05 04 01 00 06 1D 38 //600MS

Set the Baudrate Command

Sending code: 00 06 20 00 00 05 43 D8

Field Meaning Note
00 Device Address 0x00 is the broadcast address, 0x01-0xFF is the device address
06 06 Command Set the baud rate and the device address
20 00 Command Register 0x2000 is the configurable baudrate, 0x4000 sets the device address
00 Checksum Method 0x00: no checksum, 0x01: even parity, and 0x02: odd parity
05 Baudrate value The baud value corrsponding to
0x00: 4800
0x01: 9600
0x02: 19200
0x03: 38400
0x04: 57600
0x05: 115200
0x06: 128000
0x07: 256000
43 D8 CRC16 CRC16 checksum of the first 6 bytes of data

Return code: 00 06 20 00 00 05 43 D8

Field Meaning Note
00 Device address 0x00 is the broadcast address; 0x01-0xFF is the device address
06 06 Command Set the baudrate and the device address
20 00 Command Register 0x2000 is the configurable baudrate, 0x4000 sets the device address
00 Checksum Method 0x00 is no checksum, 0x01 is odd check, 0x02 is even check
05 Baudrate The baud value corrsponding to
0x00: 4800
0x01: 9600
0x02: 19200
0x03: 38400
0x04: 57600
0x05: 115200
0x06 : 128000
0x07: 256000
43 D8 CRC16 CRC16 checksum of the first 6 bytes of data

For example:

[No.1 address device]

Set the baudrate 4800: 00 06 20 00 00 00 83 DB
Set the baudrate 9600: 00 06 20 00 00 01 42 1B
Set the baudrate 115200: 00 06 20 00 00 05 43 D8

Set the Device Address Comand

Sending code: 00 06 40 00 00 01 5C 1B

Field Meaning Note
00 Device Address 0x00 is the broadcast address, 0x01-0xFF is the device address
06 06 Command Configurable baudrate and device address
40 00 Command Register 0x2000 is for setting the baudrate, and 0x4000 is for setting the device address
00 01 Device address Set the device address, 0x0001-0x00FF
5C 1B CRC16 CRC16 checksum of the first 6 bytes of data

Return code: 00 06 40 00 00 01 5C 1B

Field Meaning Note
00 Device Address 0x00 is the broadcast address, 0x01-0xFF is the device address
06 06 Command Set the baudrate and the device address
40 00 Command Register 0x2000 is for setting the baudrate, 0x4000 is for setting the device address
00 01 Device address Set the device address, 0x0001-0x00FF
5C 1B CRC16 CRC16 checksum of the first 6 bytes of data

For example:

[No.1 address device]

Set the device address as 0x01: 00 06 40 00 00 01 5C 1b
Set the device address as 0x02: 00 06 40 00 00 02 1C 1A
Set the device address as 0x03: 00 06 40 00 00 03 DD DA

Read the Device Address Command

Sending code: 00 03 40 00 00 01 90 1B

Field Meaning Note
00 Device address 0x00 is the broadcast address; 0x01-0xFF is the device address
03 03 Command Read the device address command
40 00 Command register 0x4000 is to read the device address, 0x8000 is to read the software version
00 01 Bytes number Fixed 0x0001
90 1B CRC16 CRC16 checksum of the first 6 bytes of data

Return code: 01 03 02 00 01 79 84

Field Meaning Note
00 Device address 0x00 indicates the broadcast address; 0x01-0xFF indicates the device address
03 03 command Read software version, read device address command
02 Byte number Return the number of bytes
00 01 Device address Set device address, 0x0001-0x00FF
79 84 CRC16 CRC16 checksum of the first 6 bytes of data

For example:

[NO.1 address device]

Sending: 00 03 40 00 00 01 90 1B Return: 01 03 02 00 01 79 84 //Address 0x01
[NO.2 address device]

Sending: 00 03 40 00 00 01 90 1B
Return: 02 03 02 00 02 7D 85 //Address 0x02
[NO.3 address device]

Sending: 00 03 40 00 00 01 90 1B
Return: 03 03 02 00 03 81 85 //Address: 0x03

Read Software Version Command

Sending code: 00 03 80 00 00 01 AC 1B

Field Meaning Note
01 Device Address 0x00 indicates the broadcast address; 0x01-0xFF indicates the device address
03 03 Command Read software version, read device address command
80 00 Command Register 0x4000 is to read the device address, 0x8000 is to read the software version
00 01 Byte Number Fixed 0x0001
8F CA CRC16 CRC16 checksum of the first 6 bytes of data

Return code: 01 03 02 00 64 B9 AF

Field Meaning Note
01 Device Address 0x00 indicates the broadcast address; 0x01-0xFF indicates the device address
03 03 Command Read the software version and the device address commands
02 Byte Number Return code
00 64 Software Version Convert to decimal and move the decimal point two places to the left to indicate the software version
0x0064=100=V1.00
B9 AF CRC16 CRC16 checksum of the first 6 bytes of data

For example:

Sending: 00 03 80 00 00 01 AC 1B
Return: 01 03 02 00 64 B9 AF //0x0064 = 100 =V1.00

Resource

Demo

Software

Related application

FAQ

 Answer:

Click here to install the corresponding drivers.

{{{5}}}


 Answer:

Yes, it also supports Win7/8/8.1/10/11, Mac, Linux, Android, and WinC...

{{{5}}}


 Answer:

Remove the 120-ohm termination matching resistor for RS485.

{{{5}}}


 Answer:
  • Support USB to RS232, RS485 or TTL;
  • Does not support RS232, RS485, TTL simultaneous conversion to USB
  • RS232, RS485 and TTL cannot be converted to each other


 Answer:

Not supported, RS232, RS485 and TTL can not be interchangeable, support USB to RS232, RS485, or TTL.

{{{5}}}


 Answer:

TTL and RS232 are full-duplex communication, you can short RXD and TXD to test, RS485 is half-duplex communication, you can test with an external USB to RS485 device, the following figure is the loopback test TTL:
Serial Module FAQ01.png
Serial Module FAQ02.png

{{{5}}}


 Answer:

VCC is the power supply pin, which can be switched by 5V or 3.3V (50mA) to power the connected device, if the device already has another external power supply, it can be connected without VCC.

{{{5}}}


 Answer:
  • The module is only for interface switch in terms of hardware, it does not support Modbus. It supports connecting to Modbus devices with an onboard RS485 (RS232, TTL) interface.
  • When learning the Modbus protocol, you need to understand Modbus's function code and data format. Modbus has a variety of function codes, each of which corresponds to one type of operation, such as reading the coil status, reading the input status, reading the holding register, and so on.

{{{5}}}


 Answer:

No, but it is more stable with a connection to GND. For better performance, reliability, and anti-interference, it is recommended to connecting to GND for a long-distance communication.

{{{5}}}


 Answer:

It is about 3.7W, please refer to the figure below:
Modbus-rtu-relay-16ch-faq.jpg

{{{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)