SmartPi 3.0 Modbus RTU and Modbus TCP settings

Modbus

From software version 1.0.0 -3.0.0 (from June 2019), the SmartPi has the option of being read out via Modbus RTU and Modbus TCP (slave).

  • With Modbus TCP, communication takes place via the network interface.
  • With Modbus RTU the communication takes place via the RS485 interface of the SmartPi.

Currently, the Modbus settings must still be made manually in the configurationsfile /etc/smartpi.

Own installation vs ready image

 
We recommend to use our ready-made image when using Modbus RTU,
because for a smooth operation some settings have to be done at the serial ports of the Raspberry Pi.
If you have your own image, please proceed as follows:
Please log in to the SmartPi via SSH.
 

sudo nano /boot/cmdline.txt

there remove console=/dev/serial1 and console=serial0,115200

 

save CTRL+O and close CTRL+C

sudo nano /boot/config.txt

at the end insert the two lines

dtoverlay=pi3-miniuart-bt
enable_uart=1
core_freq=250

save CTRL+O and close CTRL+C

sync
sudo reboot

Now you can use the RS485 bus via /dev/serial0.

 

 

Modbus RTU

Connect the SmartPi via the RS485 terminals A and B to the Modbus master you are using. Please make sure that the polarity of the terminals A and B is correct. If A and B are reversed, no communication can take place.

The terminating resistor can be activated and deactivated via the jumper. If the SmartPi is at the beginning or at the end of the RS485 bus or if only master and slave are connected, the jumper must be set. If the SmartPi is in the middle of the bus, the jumper should be pulled out.

Konfiguration

You can set the Modbus configuration via the configuration file /etc/smartpi.

[modbus]
modbus_rtu_enabled=0
modbus_tcp_enabled=0
modbus_rtu_address=1
modbus_rtu_device_id="/dev/serial0"
modbus_tcp_address=":502"

If the entry does not exist in the configuration file, you can simply create the entry at the end of the file.
To enable Modbus RTU, set the value of modbus_rtu_enabled to 1. With the help of the value modbus_rtu_address you can set the SlaveID. A SlaveID may only occur once in a bus. For example, if you operate several SmartPi on one Modbus, change the SlaveIDs accordingly. The value modbus_rtu_device_id can be used to select the corresponding serial interface. This value actually does not have to be changed.

RS485-Anschluss für Modbus RTU
Image 1: RS485 connection for Modbus RTU
RS485-Anschluss für Modbus RTU
Image 2: RS485 connection for Modbus RTU

Modbus TCP

With Modbus TCP the communication takes place via the network interface (LAN or WLAN) in the network.
Also for Modbus TCP you find the settings in the configuration file /etc/smartpi.

[modbus]
modbus_rtu_enabled=0
modbus_tcp_enabled=0
modbus_rtu_address=1
modbus_rtu_device_id="/dev/serial0"
modbus_tcp_address=":502"

If the entry does not exist in the configuration file, you can simply create the entry at the end of the file. To enable Modbus TCP, set the modbus_tcp_enabled value to 1. The only other parameter is modbus_tcp_address. This value can be used to set the IP address and port that the SmartPi listens on. Default is that on all IP addresses of the SmartPi on port 502 is listened.

Modbus Register

Datatyp: IEEE-754 Floating Point

Register Value  
0 I1 MSB
1   LSB
2 I2 MSB
3   LSB
4 I3 MSB
5   LSB
6 I4 MSB
7   LSB
8 U1 MSB
9   LSB
10 U2 MSB
11   LSB
12 U3 MSB
13   LSB
14 P1 MSB
15   LSB
16 P2 MSB
17   LSB
18 P3 MSB
19   LSB
20 CosPhi 1 MSB
21   LSB
22 CosPhi 2 MSB
23   LSB
24 CosPhi 3 MSB
25   LSB
26 F1 MSB
27   LSB
28 F2 MSB
29   LSB
30 F3 MSB
31   LSB
32 Balanced MSB
33   LSB