PROFINET & Raspberry PLC tutorial: How to set communication on Linux

Industrial Ethernet Communication Protocols
June 8, 2021 by
PROFINET & Raspberry PLC tutorial: How to set communication on Linux
Boot & Work Corp. S.L., Fernandez Queralt Martinez

Introduction

PROFINET (Process Field Networkis a network standard for Industrial Automation based on open Ethernet and non-proprietary for automation.

The industrial Raspberry PLC has two Ethernet ports, and its own OS from the Raspberry, Raspbian, Linux.

Let's go to learn how to run the p-net PROFINET device stack and its sample application on an industrial Raspberry Pi PLC.


Note: Industrial Shields does not provide Profinet libraries to control the Inputs & Outputs. You can use our libraries based on C++, Python or Node-Red that you can find in our official github

Related Links

How to trigger alarms

with PROFINET & Raspberry

Read 

Raspberry Pi

Family products

See 

Basics about

Industrial Raspberry Pi PLC Analog outputs

Read 

How tocheck Ethernet

configuration in industrial Raspberry PLC

Read 

Touchberry Pi

Family Products

See 

How to program

Raspberry PLC Interrupt inputs with Python

Read 

Explanation

Requirements

  • 1x Raspberry Pi
  • 1x Raspberry Pi based PLC
  • Ethernet/USB Hub
  • Raspberry power cable - USB-C type
  • 2x Ethernet cables

PROFINET

PROFINET is the international open Ethernet industrial standard of PROFIBUS & PROFINET (pi) for automation

  • PROFINET uses the TCP/IP and LO standards, is PROFI real-time Ethernet, and allows investment protection with the integration of fieldbus systems.
  • ProFiNet IO (Input Output): Developed real-time (RT) and real-time isochronous (IRT) communication with the decentralized periphery. The names RT and IRT are limited to describing the properties in time for communication in ProFiNet IO. 

The PROFINET concept offers modular mode structure so that users can select cascade connection themselves. They differ essentially due to the type of data exchange to meet the requirements, partly very high speed.

With PROFINET, communication without discontinuities from the management level to the field level is possible. On the other hand, it meets the great demands imposed by industry, e.g., ex. wiring and connection system suitable for industrial environment, real time, motion control in isochronous mode, non-proprietary engineering, etc.

PROFINET was developed with the aim of fostering a process of convergence between industrial automation and the information management platform for corporate management and global corporate networks. It applies to Ethernet-based distributed automation systems that integrate existing field bus systems, for example PROFIBUS, but without modifying them.

Profinet - PROFINET & Raspberry PLC tutorial: How to set communication on Linux

      Notes to advanced users

      The IO-device sample application can be running on:

      • Raspberry Pi
      • Any Linux OS
      • An embedded board running an RTOS, such as RT-kernel

      Files

      The sample_app directory in the p-net repository contains the source code for this tutorial. It also contains a GSD file which tells the IO-controller how to communicate with the IO-device. Those parts of the sample application that are dependent on whether you run Linux or an RTOS are located in src/ports.

      Install dependencies

      1. First of all, connect your Raspberry Pi to Internet via LAN or Wi-Fi to be able to download some packages.

      See how >>

      2. Then, in order to compile p-net on Raspberry Pi, you need a recent version of cmake. Install it:

      sudo apt update
      sudo apt install snapd
      sudo reboot
      sudo snap install cmake --classic

      3. Verify the installed version:
      cmake --version

      Download and compile p-net

      1. Install git to download p-net:
      sudo apt install git

      2. Create a directory called profinet:

      mkdir /home/pi/profinet
      cd /home/pi/profinet

      3. Clone the repository with submodules. Then create and configure the build:

      git clone --recurse-submodules https://github.com/rtlabs-com/p-net.git
      cmake -B build -S p-net
      cmake --build build --target install

      Notes to advanced users

      If you have already cloned the repository without the --recurse-submodules flag, then run in the p-net folder.

      git submodule update --init --recursive.

      Alternate cmake command to also adjust some settings:

      cmake -B build -S p-net -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=OFF -DBUILD_SHARED_LIBS=ON -DUSE_SCHED_FIFO=ON

      Depending on how you installed cmake, you might need to run snap run cmake instead of cmake.

      Run the sample application

      1. Go to the /home/pi/profinet/build directory:

      cd /home/pi/profinet/build

      2. Enable the Ethernet interface and set the initial IP address:
      sudo ifconfig eth0 192.168.0.50 netmask 255.255.255.0 up

      3. Execute the sample application:
      sudo ./pn_dev -v -v -v -v

      From the Raspberry PLC

      1. Configure the Ethernet interface from the Raspberry Pi industrial PLC and set the initial IP address:

      sudo ifconfig eth0 192.168.0.100 netmask 255.255.255.0 up

      2. Download the tshark package:
      sudo apt update
      sudo apt install -y tshark

      3. Add a new system group called tshark:
      sudo groupadd tshark

      4. Add current user to a tshark group:
      sudo usermod -a -G tshark $USER

      · To make changes to take effect, logout and login to Raspberry Pi. After you are reconnected, check tshark version:
      tshark --version

      · To start capturing packets on the default network interface with tshark, simply execute this command:
      sudo tshark

      · To identify which network interfaced are available to the tshark, run the following command:
      tshark -D

      You can use -i option to capture packets on specific network interface
      sudo tshark -i eth0

      Get the results

      Get the results 1 - PROFINET & Raspberry PLC tutorial: How to set communication on Linux
      Get the results - PROFINET & Raspberry PLC tutorial: How to set communication on Linux

      LLDP

      LLDP or Link Layer Discovery Protocol is used by PROFINET to determine and manage neighborhood relationships between PROFINET devices. LLDP uses the special multicast MAC address: 01-80-C2-00-00-0E and the Link layer Ethernet II and IEEE 802. 1Q and Ethertype 0x88CC (PROFINET). Finally, the port number is non relevant:

      LLDP - PROFINET & Raspberry PLC tutorial: How to set communication on Linux

      Autostart on boot

      · If you want pnet to run when the Pi is turned on, or re-booted, first enable the serial port console by writing the line

      enable_uart=1

      in the file /boot/config.txt 

      1. Go to /etc/dhcpcd.conf and include these lines to set a static IP:

      interface eth0
      static ip_address=192.168.0.100/24

      2. Then, you can enable the service to autostart by running the  following commands:

      sudo cp /home/pi/profinet/p-net/src/ports/linux/pnet-sampleapp.service /lib/systemd/system
      sudo systemctl daemon-reload
      sudo systemctl enable pnet-sampleapp.service

      Start service

      sudo systemctl start pnet-sampleapp.service

      · To see the status of the process, and the log output:

      sudo systemctl status pnet-sampleapp.service
      journalctl -fu pnet-sampleapp

      Finally, reboot to apply the changes and get your service running!

      Do you want to know more?

      Learn how to trigger alarms using PROFINET & CODESYS!

      ​Search in our Blog

      PROFINET & Raspberry PLC tutorial: How to set communication on Linux
      Boot & Work Corp. S.L., Fernandez Queralt Martinez June 8, 2021
      Share this post

      Looking for your ideal Programmable Logic Controller?

      Take a look at this product comparison with other industrial controllers Arduino-based. 

      We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.


      Industrial PLC comparison >>>