Modbus RTU Analog Output 8CH

From Waveshare Wiki
Jump to: navigation, search
Modbus RTU Analog Output 8CH
Modbus RTU Analog Input 8CH.jpg

RS485 Current Analog Output Module, RS485
{{{name2}}}

{{{name3}}}

{{{name4}}}

{{{name5}}}

{{{name6}}}

Overview

Hardware Description

  • AO1~AO8 is the analog output, AGND is the analog ground, and the output range is 0-20mA.

Modbus RTU Analog Output 8CH-01.jpg
Please note that the output current is related to the input voltage and the load, and if the input voltage is insufficient, the output current will be insufficient.
For example: if the internal sampling resistance is 100R, the external load is 500R with an output of 20mA, and the voltage is (100R+500R)*20mA=12V. Additionally, considering a 2V internal voltage drop, the input needs to be a minimum of 14V to achieve an output of 20mA.

Version Comparision

Currently, the analog output has two versions: the current output version and the voltage output.

  • Modbus RTU Analog Output 8CH outputs the current with the range of 0-20mA.
  • Modbus RTU Analog Output 8CH (B) outputs the voltage with the range of 0-10V.

Modbus RTU Analog Output 8CH-02.png

Hardware Connection

  • Connect the USB TO 485 and the target board through dupont line, connects A --> A and B --> B as shown below:

Modbus RTU Analog Output 8CH-03.jpg

Software Test

SSCOM

  • Download SSCOM and open it on the PC, open the corresponding port, set the baud rate of 9600, and select hex to send and receive.
    Send the following commands, channel 1 will then output 1mA of current.
01 06 00 00 03 E8 89 74

Modbus RTU Analog Output 8CH-SSCOM.png

  • 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 example, send the following command to set channel 1 to output 5mA current.

01 06 00 00 13 88

Modbus RTU Analog Output 8CH-SSCOM02.png

  • For more details, you can see the development protocol.

Modbus Poll Software

  • It is not convenient to observe data through the SSCOM software. You can use Modbus Poll software to read data. Download and install Modbus Poll software.
  • Open the software, and select 'Setup -> Read/Write Definition'. Choose the actual device address for Slave ID, select 16 Write Multiple Registers in Function, and change the Quantity to 8 channels. Click "OK" to confirm.

Modbus RTU Analog Output 8CH-Poll01.png

  • Select Connection -> Connect..., and choose the corresponding serial port, the baud rate as 9600, 8 Data bits, none parity mode. Click "OK" to connect.

Modbus Poll-2.png

  • After the connection is normal then you can set 1-8 channels analog output current, unit uA, range 0-20000uA, i.e. 0-20mA.

Modbus RTU Analog Output 8CH-Poll03.png

Demo Test

Note: RS485 cannot be directly connected to the Raspberry Pi's serial port; otherwise, the device may be burned. It requires a 485 level converter. It's advisable to use the RS485 CAN HAT with the Raspberry Pi. For NUCLEO-F103RB and Arduino, it's recommended to use with the RS485 CAN Shield module.

Raspberry Pi

Enter the Raspberry Pi terminal and input the following commands to enter the configure interface:

sudo raspi-config
Select Interfacing Options -> Serial Port, Select Yes, and Open the hardware serial port 

And then reboot the Raspberry Pi:

sudo reboot

Insert the RS485 CAN HAT module into the Raspberry Pi, and connect A and B of ModBus RTU Relay module and RS485 CAN HAT module.
If you are using other 485 devices, make sure the connection is A-A, B-B.
Run the following command to run the demo:

sudo apt-get install unzip
sudo apt-get install python3-pip
pip install modbus_tk
wget https://files.waveshare.com/wiki/Modbus-RTU-Analog-Output-8CH/Modbus_RTU_Analog_Output_Code.zip
unzip Modbus_RTU_Analog_Output_Code.zip
cd Modbus_RTU_Analog_Output_Code/Python3
sudo python3 modbus.py

After the demo runs normally, all channels will output 5mA current.

STM32

STM32 demo is based on the NUCLEO-F103RB and the RS485 CAN Shield module.
Find the STM32 demo file directory and open the STM32 project. Note that before use make sure the computer has installed keil5 software, and download the demo to the development board.
After the demo runs normally, all channels will output 5mA current.

Arduino

The Arduino demo is based on NUO PLUS and RS485 CAN Shield module.
Use Arduino IDE to open the demo, select the corresponding development board, and then download the demo.
After the demo runs normally, all channels will output 5mA current.

Development Protocol

Function Code Introduction

Function Code Note
03 Read Holding Registers
06 Write Single Holding Register
10 Write Multiple Holding Register

Register Address Introduction

Address (HEX) Address Storage Content Register Value Permissions Modbus Function Code
4x0000
……
4x0007
Channel 1 ~ 8 Output Data Unsigned hexadecimal Read/Write 0x03, 0x06, 0x10
4x2000 Serial port parameters High 8-bit is the parity mode: 0x00~0x02
Low 8-bit is the baud rate mode: 0x00~0x07
Read/Write 0x03, 0x06
4x4000 Device address Direct store Modbus addresses
Device address: 0x0001-0x00FF
Read/Write 0x03, 0x06
4x8000 Software version Convert to decimal and then shift the decimal point two places to the left to represent the software version
0x0064 = 100 = V1.00
Read 0x03

Set Single-channel Output Command

Send code: 01 06 00 00 03 E8 89 74

Fields Description Note
01 Device Address 0x00 indicates the broadcast address, 0x01-0xFF indicates the device address
06 06 Command Write a single register command
00 00 Register Address 0x0000 - 0x0007 corresponds to 1~8 channel output data
03 E8 Value Setting Set the value to hexadecimal, unit uA, high bits in the front, low bits at the end
0x03E8 = 1000uA, or 1mA
89 74 CRC16 CRC16 checksum of the first 6 bytes of data

Receive code: 01 06 00 00 03 E8 89 74

Fields Description Note
01 Device Address 0x00 indicates the broadcast address, 0x01-0xFF indicates the device address
06 06 Command Write a single register command
00 00 Register Address 0x0000 - 0x0007 corresponds to 1~8 input channel data type
03 E8 Value Setting Set the value in hexadecimal, unit mV, high bits in the front, low bits in the end.
0x03E8 = 1000mV, or 1V
89 74 CRC16 CRC16 checksum of the first 6 bytes of data

For example:

[No.1 address device]

Set channel 1 output 1mA : 01 06 00 00 03 E8 89 74
Read channel 2 output 5mA : 01 06 00 01 13 88 D5 5C

Set Multiple-channel Output Command

Send code: 01 10 00 00 00 08 10 03 E8 03 E8 03 E8 03 E8 03 E8 03 E8 03 E8 03 E8 3C 05

Fields Description Note
01 Device Address 0x00 indicates the broadcast address; 0x01-0xFF indicates the device address
10 10 Command Write multi-register command
00 00 Register Initial Address 0x0000 - 0x0007 corresponds to 1~8 output channels
00 08 Register Numbers Set the number of registers, up to 8 channels
10 Bytes Numbers Set the output bytes
03 E8
……
03 E8
Command Channel 1 analog output
……
Channel 8 analog output
Set the value in hexadecimal, unit in mV, high bits in the front, low bits in the end
0x03E8 = 1000uA, or 1mA
3C 05 CRC16 CRC16 checksum of the first 6 bytes of data

Receive code: 01 10 00 00 00 08 C1 CF

Fields Description Note
01 Device Address 0x00 indicates the broadcast address; 0x01-0xFF indicates device address
10 10 Command Write multi-register command
00 00 Register Initial Address 0x0000 - 0x0007 corresponds to 1~8 output channels
00 08 Register Numbers Set the register numbers, up to 8 channels
C1 CF CRC16 CRC16 checksum of the first 6 bytes of data

For example:

[No.1 address device]

Set channel 1-8 output 1mA: 01 10 00 00 00 08 10 03 E8 03 E8 03 E8 03 E8 03 E8 03 E8 03 E8 03 E8 3C 05
Set channel 3-5 output 2mA: 01 10 00 02 00 03 06 07 D0 07 D0 07 D0 84 0E

Read Channel Output Command

Send code: 01 03 00 00 00 08 44 0C

Fields Description Note
01 Device Address 0x00 indicates the broadcast address; 0x01-0xFF indicates device address
03 03 Command Read holding register
00 00 Register Initial Address 0x0000 - 0x0007 corresponds to 1~8 input channels
00 08 Register Numbers Read the register numbers, up to 8 channels
44 0C CRC16 CRC16 checksum of the first 6 bytes of data

Return code: 01 03 10 03 E8 03 E8 03 E8 03 E8 03 E8 03 E8 03 E8 03 E8 C1 91

Fields Description Note
01 Device Address 0x00 indicates the broadcast address; 0x01-0xFF indicates device address
03 03 Command Read holding register
10 Byte Numbers Number of bytes for returning status information
03 E8
……
03 E8
Output Value Channel 1 analog output
……
Channel 8 analog output
Set the value in hexadecimal, unit mV, high bits in the front, low bits in the end
0x03E8 = 1000uA, or 1mA
C1 91 CRC16 CRC16 checksum of the first 6 bytes of data

For example

[No.1 address device]

Read channel 1-8 data type: 01 03 00 00 00 08 44 0C
Read channel 1 data type: 01 03 00 00 00 01 84 0A
Read channel 2 data type: 01 03 00 01 00 01 D5 CA
Read channel 3-5 data type: 01 03 00 02 00 03 A4 0B

Set Baudrate Command

Send code: 00 06 20 00 00 05 43 D8

Fields Description Note
00 Device Address 0x00 indicates the broadcast address; 0x01-0xFF indicates device address
06 06 Command Set the baud rate and device addresses
20 00 Command Register 0x2000 for setting baudrate, 0x4000 for setting device addresses
00 Parity Method 0x00 is no parity, 0x01 is even parity, 0x02 is odd parity
05 Baudrate Value The baud rate values correspond:
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

Fields Description Note
00 Device Address 0x00 indicates the broadcast address; 0x01-0xFF indicates device address
06 06 Command Set the baud rate and device addresses
20 00 Command Register 0x2000 is setting the baud rate, 0x4000 is setting the device address
00 Parity Method 0x00 is no parity, 0x01 is even parity, 0x02 is odd parity
05 Baudrate The baud rate values correspond:
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 baud rate 4800: 00 06 20 00 00 00 83 DB
Set baud rate 9600: 00 06 20 00 00 01 42 1B
Set baud rate 115200: 00 06 20 00 00 05 43 D8

Set Device Address Command

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

Fields Description Note
00 Device Address 0x00 indicates the broadcast address; 0x01-0xFF indicates device address
06 06 Command Set the baud rate and device addresses
40 00 Command Register 0x2000 is setting baudrate, 0x4000 is 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

Fields Description Note
00 Device Address 0x00 indicates the broadcast address; 0x01-0xFF indicates device address
06 06 Command Set the baud rate and device addresses
40 00 Command Register 0x2000 is setting baudrate, 0x4000 is 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 Device Address Command

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

Fields Description Note
00 Device Address 0x00 indicates the broadcast address; 0x01-0xFF indicates device address
03 03 Command Read device address command
40 00 Command Register 0x4000 for read device address, 0x8000 for read software version
00 01 Byte Numbers Fixed 0x0001
90 1B CRC16 CRC16 checksum of the first 6 bytes of data

Received code: 01 03 02 00 01 79 84

Fields Description Note
00 Device Address 0x00 indicates the broadcast address, 0x01-0xFF indicates device address
03 03 Command Read the software version and the device address
02 Byte Numbers Return byte numbers
00 01 Device Address Set the device address, 0x0001-0x00FF
79 84 CRC16 CRC16 checksum of the first 6 bytes of data

For example:

[No.1 address device]

Send: 00 03 40 00 00 01 90 1B
Receive: 01 03 02 00 01 79 84 //address 0x01

[No.2 address device]

Send: 00 03 40 00 00 01 90 1B
Receive: 02 03 02 00 02 7D 85 //address 0x02
[No.3 address device]

Send: 00 03 40 00 00 01 90 1B
Receive: 03 03 02 00 03 81 85 //address 0x03

Read Software Version Command

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

Fields Description Note
01 Device Address 0x00 indicates the broadcast address; 0x01-0xFF indicates device address
03 03 Command Read the software version and the device address
80 00 Command Register 0x4000 is reading device address, 0x8000 is reading software version
00 01 Byte Numbers Fixed 0x0001
8F CA CRC16 CRC16 checksum of the first 6 bytes of data

Receive code: 01 03 02 00 64 B9 AF

Fields Description Note
01 Device Address 0x00 indicates the broadcast address; 0x01-0xFF indicates device address
03 03 Command Read the software version and the device address
02 Byte Numbers Received Byte Numbers
00 64 Software Version Convert to decimal and then shift the decimal point two places to the left to represent the software version.
0x0064 = 100 = V1.00
B9 AF CRC16 CRC16 checksum of the first 6 bytes of data

For example:

[No.1 address device]

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

Resource

Demo

Software

FAQ

 Answer:
The command must be sent in hex format with a CRC checksum.

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}}}


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)