Modbus RTU Analog Input 8CH

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

RS485
{{{name2}}}

{{{name3}}}

{{{name4}}}

{{{name5}}}

{{{name6}}}

Overview

Hardware Description

  • Each channel can be individually configured for its range, making it more convenient for users.
"AIN+" is the positive input, and "AIN-" is the negative input. The module supports both differential and single-ended input. When used as a single-ended input, "AIN-" is connected to the ground.
Modbus-RTU-AI-8CH-06.jpg

Note: When inputting the different powers, it is important to connect the ground wire to establish a common ground. Otherwise, the collected data may be inaccurate.

  • Opening the device case, you can see jumpers are near the device terminals, corresponding to the eight channels AI1~AI8. You need to select the jumper mode based on the measurement signal; otherwise, the measurement data will be inaccurate.
    • When measuring voltage signals, the jumper wires for the corresponding channels should be disconnected.
    • When measuring current signals, the jumper wires for the corresponding channels should be connected.

Modbus RTU Analog Input 8CH-Overview.png

  • Modbus RTU Analog Input 8CH defaults to current mode with the jumper wire connected. Modbus RTU Analog Input 8CH (B) defaults to voltage mode with the jumper wires disconnected.

Version Comparision

  • Currently, there are two versions of the analog input series, one defaults to current input, and the other defaults to voltage input.

Modbus-RTU-Analog-Input-AB-Compare-01.jpg

Version Modbus RTU Analog Input 8CH Modbus RTU Analog Input 8CH (B)
Default mode 8-ch current mode, 0~20mA 8-ch voltage mode, 0~10V
Measurement range 0~5V/1~5V
0~20mA/4~20mA
0~10V/2~10V
0~20mA/4~20mA
Resolution 12-bit 12-bit
Current sampling resistance 249Ω 499Ω
Operational amplifier ratio 32.4/49.9 10/32.4
Channel 8-AI 8-AI
  • Each version has five range modes from 0 to 4.
Mode Modbus RTU Analog Input 8CH Modbus RTU Analog Input 8CH (B)
0 0~5V voltage mode 0~10V voltage mode
1 1~5V voltage mode 2~10V voltage mode
2 0~20mA current mode 0~20mA current mode
3 4~20mA current mode 4~20mA current mode
4 4096-scale code mode 4096-scale code mode
  • The scale code is the data collected by the AD converter and needs to undergo a linear transformation to obtain voltage or current data. The conversion formula is as follows.
    • Voltage = Scale Code * 3300/4095/Operational Amplifier Ratio
    • Current = Voltage/Sampling Resistor

Hardware Connection

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

Modbus RTU Analog Input 8CH-03.jpg

Software Test

SSCOM

  • Download SSCOM and open it on the computer. Open the corresponding port number, set the baud rate as 9600, and select hex to send and receive.
    For example, Send the following commands, and it will return the analog input data from 8 channels in normal operation.
01 04 00 00 00 08 F1 CC

Modbus-RTU-Analog-Input-SSCOM-test-01.jpg

  • If you need to send other commands, select SendHEX and choose Modbus CRC16 for Verify. When entering the first six bytes of the command and clicking "Send", the CRC checksum will be automatically added.
    For example, to send the following command, you can set channel 1 to 4-20mA current input mode.
01 06 10 00 00 03

Modbus-RTU-Analog-Input-SSCOM-test-02.jpg

  • For more control commands, you can refer to the development protocol.

Modbus Poll

  • It is not convenient to use the SSCOM software for observing the data, you can select Modbus Poll software to read the data. Download and install Modbus Poll software.
  • Open the software, select setup -> Read/Write Definition. Select the actual device address in Slave ID, 04 function code, 8 channels for Quantity, and click "OK" to confirm.

Modbus Poll-1.png

  • Select Connection -> Connect..., select the corresponding serial port, 9600 as the baud rate, 8 data bits for no-parity mode, and click "OK" to confirm.

Modbus Poll-2.png

  • After successful connection, channels 1-8 can analog the input data.

Modbus Poll-3.png

  • Modbus RTU Analog Input 8CH (A) displays in current by default, and the unit is uA. Modbus RTU Analog Input 8CH (B) displays in voltage by default, and the unit is mV.
  • Select File -> New to create a new window, select setup -> Read/Write Definition. Select the actual device address for Slave ID, 16 function codes, Hex for Address Mode, 1000 for Address, and 8 channels for Quantity, and then click "OK" to confirm.

Modbus Poll-4.png

  • The new window 2 can set up the measuring mode for different channels. For example, you can set the channel 1 mode as 2, that is, 0~20mA current mode, and channel 1 of the window 1 displays in current.

Note: the internal jumper wires should be modified when changing the current and voltage mode, otherwise, the measurement data will not be accurate.

Modbus Poll-5.png

Demo Test

Note: RS485 does not support the direct connection for the serial ports of the Raspberry Pi as it requires the 485 voltage level transition. Otherwise, the device may burn. It is recommended to work with RS485 CAN HAT, and NUCLEO-F103RB and Arduino require RS485 CAN Shield.

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 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 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-Input-8CH/Modbus_RTU_Analog_Input_Code.zip
unzip Modbus_RTU_Analog_Input_Code.zip
cd Modbus_RTU_Analog_Input_Code/Python3
sudo python3 modbus.py

STM32

The STM32 demos are 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 using it, ensure that the keil5 software has been installed on the computer, and just download the demo to the development board.
The serial port will output the data collected from 8 channels in normal operation.

Arduino

The Arduino demos are based on the NUO PLUS and RS485 CAN Shield modules.
Use Arduino IDE to open the demo, select the corresponding development board, and then download the demo to it.
The serial port will output the data collected from 8 channels in normal operation.

Development Protocol

Function Code

Function Code Note
03 Read holding register
04 Read input register
06 Write single holding register
10 Write multiple holding registers

Register Address

Addr (HEX) Address stored content Register value Permission Modbus function code
3x0000
……
3x0007
Channel 1 to Channel 8 input data Read the value as unsigned hexadecimal Read 0x04
4x1000
……
4x1007
Channel 1 to Channel 8 data type 0x0000~0x0004, five ranges Read/Write 0x03, 0x06, 0x10
4x2000 UART Parameters The high 8 bits as the checksum method: 0x00~0x02
The low 8 bits as the baudrate: 0x00~0x07
Read/Write 0x03, 0x06
4x4000 Device Address Directly store Modbus Address
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

Read Analog Input Commands

Send code: 01 04 00 00 00 08 F1 CC

Field Meaning Note
01 Device Address 0x00 is the broadcast address; 0x01-0xFF is the device address
04 04 Command Read input register
00 00 Register Initial Address 0x0000 - 0x0007 correspod to input channel 1~8
00 08 Register Number Read register number, up to 8 channels
F1 CC CRC16 CRC16 checksum of the first 6 bytes of data

Return code: 01 04 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 2C

Field Meaning Note
01 Device Address 0x00 is the broadcast address, 0x01-0xFF is the device address
04 04 Command Read input register
10 Bytes Number Data length
00 00
……
00 00
Register data Represent the values of analog data acquisition for channels 0 to 7.
An unsigned sixteen-bit value identifies each channel, with the high bits first and the low bits last.
The data range is determined by the output data type.
55 2C CRC16 CRC16 checksum of the first 6 bytes of data

For example:

[Device at Address 1]

Read channel 1 to channel 8: 01 04 00 00 00 08 F1 CC
Read channel 1: 01 04 00 00 00 01 31 CA
Read channel 2: 01 04 00 01 00 01 60 0A
Read channel 3 to channel 5: 01 04 00 02 00 03 11 CB

Read Channel Data Type Command

Send code: 01 03 10 00 00 08 40 CC

Field Meaning Note
01 Device Address 0x00 is the broadcast address; 0x01-0xFF is the device address
03 03 Command Read the hold register
10 00 Register Initial Address 0x1000 - 0x1007 correspond to the input channel 1~8
00 08 Register Number Read the register number, up to 8 channels
40 CC CRC16 CRC16 checksum of the first 6 bytes of data

Return code: 01 03 10 00 02 00 02 00 02 00 02 00 02 00 02 00 02 00 02 09 C3

Field Meaning Note
01 Device Address 0x00 is the broadcast address; 0x01-0xFF is the device address
03 03 Command Read the hold register
10 Byte Numbers Number of bytes containing the returned status information
00 02
……
00 02
Data type Indicate the data type of channel 0 - 7, 0x0000~0x0004 indicate five ranges
0x0000: 0~5V, output range: 0~5000mV;
0x0001: 1~5V, output range: 1000~5000mV;
0x0002: 0~20mA, output range: 0~20000uA;
0x0003: 4~20mA, output range: 4000~20000uV;
0x0004: directly output the value code, output range: 0~4096, the linear transformation is required to obtain the actual measured voltage and current.
09 C3 CRC16 CRC16 checksum of the first 6 bytes of data

For example:

[Device at Address 1]

Read the data type of channel 1-8: 01 03 10 00 00 08 40 CC
Read the data type of channel 1: 01 03 10 00 00 01 80 CA
Read the data type of channel 2: 01 03 10 01 00 01 D1 0A
Read the data type of channel 3-5: 01 03 10 02 00 03 A0 CB

Set Single-channel Data Type Command

Send code: 01 06 10 00 00 03 CD 0B

Field Meaning Note
01 Device Address 0x00 is the broadcast address; 0x01-0xFF is the device address
06 06 Command Write a single register command
10 00 Register Initial Address 0x1000 - 0x1007 correspod to the output data type of the input channel 1~8
00 03 Channel Data Type Channel data type, 0x0000~0x0004 indicates five measuring ranges
0x0000: 0~5V, output range: 0~5000mV;
0x0001: 1~5V, output range: 1000~5000mV;
0x0002: 0~20mA, output range: 0~20000uA;
0x0003: 4~20mA, output range: 4000~20000uA;
0x0004: directly output the value code, output range: 0~4096, the linear transformation is required to obtain the actual measured voltage and current.
CD 0B CRC16 CRC16 checksum of the first 6 bytes of data

Return code: 01 06 10 00 00 03 CD 0B

Field Meaning Note
01 Device Address 0x00 is the broadcast address; 0x01-0xFF is the device address
06 06 Command Write a single register command
10 00 Channel Data Type Address 0x1000 - 0x1007 correspond to the input channel 1~8 data type
00 03 Channel Data Type Channel data type, 0x0000~0x0004 indicate five measuring ranges;
CD 0B CRC16 CRC16 checksum of the first 6 bytes of data

For example:

[Device at Address 1]

Set channel 1 data type as 0~20mA: 01 06 10 00 00 02 0C CB
Read channel 2 data type as 4~20mA: 01 06 10 01 00 03 9C CB

Set Multiple-channel Data Type Command

Send code: 01 10 10 00 00 08 10 00 03 00 03 00 03 00 03 00 03 00 03 00 03 00 03 91 2B

Field Meaning Note
01 Device Address 0x00 is the broadcast address; 0x01-0xFF is the device address
10 10 Command Write multiple-register command
10 00 Register Initial Address 0x1000 - 0x1007 correspond to the input channel 1~8 data type
00 08 Register Numbers Set the register number, up to 8 channels
10 Byte Numbers Set the output byte numbers
00 03
……
00 03
Command Correspod to channel 0 - 7 data type, 0x0000~0x0004 indicate five measuring ranges
0x0000: 0~5V, output range: 0~5000, mV;
0x0001: 1~5V, output range: 1000~5000, mV;
0x0002: 0~20mA, output range: 0~20000, uA;
0x0003: 4~20mA, output range: 4000~20000, uA;
0x0004: directly output the value code, output range: 0~4096, linear transformation is required to obtain the actual measured voltage and current.
91 2B CRC16 CRC16 checksum of the first 6 bytes of data

Return code: 01 10 10 00 00 08 C5 0F

Field Meaning Note
01 Device Address 0x00 is the broadcast address; 0x01-0xFF is the device address
10 10 Command Write multiple-register command
10 00 Register Initial Address 0x1000 - 0x1007 correspond to the data type of the input channel 1~8
00 08 Register Numbers Set the register number, up to 8 channels
C5 0F CRC16 CRC16 checksum of the first 6 bytes of data

For example:

[Device at Address 1]

Read the data type of channels 1-8 as 4~20mA: 01 10 10 00 00 08 10 00 03 00 03 00 03 00 03 00 03 00 03 00 03 00 03 91 2B
Read the data type of channels 3-5 as 1~5V: 01 10 10 02 00 03 06 00 01 00 01 00 01 BE 4A

Baudrate Setting Command

Send 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 for setting the baudrate, 0x4000 is for setting the device address
00 Checksum method 0x00 is for no parity, 0x01 is for even parity, and 0x02 is for odd parity
05 Baudrate value 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 represents the broadcast address; 0x01-0xFF represents device addresses
06 06 Command Set the baudrate and the device address
20 00 Command Register 0x2000 for setting the baudrate, 0x4000 for setting the device address
00 Checksum Method 0x00 is for no parity, 0x01 is for even parity, and 0x02 is for odd parity
05 Baudrate 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:

[Device at Address 1]

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

Setting Device Address Command

Send 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 device address
40 00 Command Register 0x2000 for setting the baudrate, 0x4000 for setting 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 device address
40 00 Command Register 0x2000 for setting the baudrate, 0x4000 for setting 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:
[Device at Address 1]

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

Send 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 the command for reading the device address
40 00 Command Register 0x4000 for reading the device address, 0x8000 for reading the software version
00 01 Byte Numbers 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 is the broadcast address; 0x01-0xFF is the device address
03 03 Command the command for reading the software version and for reading 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:

[Device at Address 1]
Send: 00 03 40 00 00 01 90 1B
Return: 01 03 02 00 01 79 84 //Address 0x01

[Device at Address 2]
Send: 00 03 40 00 00 01 90 1B
Return: 02 03 02 00 02 7D 85 //Address 0x02

[Device at Address 3]
Send: 00 03 40 00 00 01 90 1B
Return: 03 03 02 00 03 81 85 //Address 0x03

Read Software Version Command

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

Field Meaning Note
01 Device Address 0x00 is the broadcast address; 0x01-0xFF is the device address
03 03 Command Read the software version and the device address
80 00 Command Register 0x4000 for reading the device address, 0x8000 for reading software version
00 01 Byte Numbers 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 is the broadcast address; 0x01-0xFF is the device address
03 03 Command Read the software version and the device address
02 Byte Numbers Return 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:

[Device at address 1]
Send: 00 03 80 00 00 01 AC 1B
Return: 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)