Temperature Measurements with RevPi as Modbus TCP Master

This tutorial is valid from the Image Jessie. Unfortunately, it doesn’t apply to Wheezy.

In the following example we measure the temperature with a sensor and use our RevPi as Modbus TCP Master.

Requirements:

  • RevPi base module and Modbus-TCP slaves are located in the same network
  • Modbus-TCP slaves have static IP addresses.

Connecting the Slave to the RevPi

  • Connect the slave to your RevPi base module via the RJ45 jack.
  • Connect your RevPi base module to the power supply.

Determine Modbus TCP network data

To configure the slave, we need some data beforehand so that we can address the sensor via our RevPi. We find this data in the user manual of our slave.

In this example, we use the temperature sensor “Inveo NANO TEMP” as slave.

  • Note the following data from the manual of your slave:
Name Value
IP adress 192.168.0.103
Port 502
Modbus register temperature x10 4004
Modbus function „Read Holding Registers“
Slave adress 1

Enable Modbus-TCP Master function

  • Start RevPi Status.
  • Click tab SERVICES.
  • Enable Modbus Master.
  • Click button Save All.

You can also activate the Master function on the command line.
Enter the following command: sudo revpi-config enable pimodbus-master.

Modbus-TCP Master Configuration

  • Start PiCtory.
  • Open the folder Virtual Devices in the device catalog.
  • Select Modbus-TCP Master.
  • Hold down the left mouse button and drag the Modbus TCP Master to your RevPi Connect.

Your Modbus-TCP Master will now appear on the far right of the Configuration Board.

  • Set the basic settings for your adapters in the “Device Data” window. This entry is optional.  If you use a lot of devices and want to process the data later in another program, this input can be very helpful.
PLEASE NOTE
For each slave you want to use, you need a virtual master.
  • In the “Value Editor” we define the settings for the TCP connection.  We’ve already determined the values from the sensor’s instruction manual::

 

  • Right-click on the Modbus-TCP Master on the Configuration Board.
  • A context menu opens.
  • Select the entry “Extended Data”.

An input mask opens.

This is where we set the Modbus commands. In this example, we need a command to read the temperature values of the sensor. We have already gathered the necessary information from the sensor’s operating instructions:

    Slave Addr.: 1
    Function Code: READ_HOLING_REGISTERS
    Register Addr.: 4004
    Quantity of Registers: 1
    Action Interval (ms): 1000
    Device Value: Input_Word_1

Save configuration

  • Click on „File>Save“ to save the file.
  • Click on “Tools>Reset Driver”. This activates the changes for the adapter.

Query values in the process image

  • Open command line and enter following command:
piTest -r Input_Word_1

You receive the data of your slave:  

 2 Byte-Value of Input_Word_1: 284 dez (=011c hex)

In our example, we get the temperature data. The value 284 corresponds to 28.4 °C