SmartPi 2.0 Modbus RTU and Modbus TCP Configuration

Modbus

As of software version 1.0.0 - 3.0.0 (from June 2019), the SmartPi can be read out via Modbus RTU and Modbus TCP (slave).
With Modbus TCP, communication takes place via the network interface.
With Modbus RTU, communication takes place via the RS485 interface of the SmartPi.
Currently, the Modbus settings must still be made manually in the /etc/smartpi configuration file.

Own installation vs prepared image

When using Modbus RTU, we recommend that you use our ready-made image, as some settings must be made on the serial interfaces of the Raspberry Pi to ensure smooth operation.

If you have your own image, please proceed as follows:
Please log in to the SmartPi via SSH.

sudo nano /boot/cmdline.txt

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

 

save STRG+O and close STRG+C

sudo nano /boot/config.txt

insert the following lines at the end

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

save STRG+O and close STRG+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 terminals A and B have the correct polarity. 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 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 removed.

Configuration

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 activate 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. If, for example, you operate several SmartPi on one Modbus, change the SlaveIDs accordingly.
The corresponding serial interface can be selected via the value modbus_rtu_device_id. This value does not actually have to be changed.

RS485 connector for Modbus RTU
Figure 1: RS485 connector for Modbus RTU
RS485 connector for Modbus RTU
Figure 2: RS485 connector for Modbus RTU

Modbus TCP

With Modbus TCP, communication takes place via the network interface (Ethernet or Wifi) in the network.
The settings for Modbus TCP can also be found in the /etc/smartpi configuration file.

[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 activate Modbus TCP, set the value modbus_tcp_enabled to 1.
The only other parameter is modbus_tcp_address. With this value the IP address and the port on which the SmartPi listens can be set.
The default is to listen on port 502 on all IP addresses of the SmartPi.

Modbus Register

Register Wert  
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