Installation and configuration of Raspberry Pi¶

This folio consists an installation guide to use if you have a Linux laptop, and a split up guide to employ with a Windows laptop.

The p-net stack and sample application has been tested with:

  • Raspberry Pi 3 Model B+

To avert problems it is recommended to showtime with a fresh Raspberry Pi Os image.

When running the Raspberry Pi as a Profinet IO-device using p-net, the network settings of the Raspberry Pi will exist changed past Profinet. Therefore it is highly recommended to use a keyboard, mouse and monitor or a series cable.

If yous use ssh yous may end upwards in a situation were you have difficulties connecting to, or recovering your device. If you lot currently do non have a suitable USB-to-serial cable you can even so build and run p-internet with the sample awarding just you might run into problem when a PLC is used for configuration.

Installation using a Linux laptop¶

Burn down a SD-bill of fare with Raspberry Pi OS, by using the "Raspberry Pi imager" software and a SD card reader. A card size of 16 - 32 GByte is recommended. Follow the instructions on the page https://www.raspberrypi.com/software/ Select the standard "Raspberry Pi OS" operating organisation.

Unplug, and reinsert your SD-card to mount it. To enable SSH logging in on the Raspberry Pi, create an empty file on the named ssh in the boot partition:

To enable the serial port console add this line to the file config.txt in the boot division:

The DHCP client daemon will arrange the network interface settings automatically. This interferes with the p-net control of the Ethernet interface. So if you run your Raspberry Pi equally a Profinet IO-Device (Non if you employ it as a PLC) and have a serial cable, you demand to add together this line to /etc/dhcpcd.conf in the root file organisation:

If you would similar to change hostname from raspberrypi to pndevice-pi , change the texts in the files etc/hostname and etc/hosts in the rootfs partition.

To make sure that you afterwards are logging in to the right Raspberry Pi, y'all tin create a file in the dwelling directory in the rootfs division. Change name to something informative, for example:

                            touch              abode              /              pi              /              IAmAProfinetDevice            

Unmount the SD-carte du jour, and plug information technology in into your Raspberry Pi. Power up the Raspberry Pi. Log in to it via a serial cable (run across beneath). Employ the username pi and the default countersign raspberry .

If yous do not have any serial cablevision (and not take disabled DHCP), connect the Raspberry Pi to your local network. Find the IP address of it past running this on a Linux machine on the network (replace the hostname if you have changed it):

Verify that it is the right machine by checking that is disappears when the power is disconnected.

Log in to information technology:

Enter the password mentioned merely above.

If you would connect your Raspberry Pi to a WiFi network, follow the guide in https://world wide web.raspberrypi.com/documentation/computers/configuration.html

You might as well desire to disable the splash screen and to expand the file system, past using the raspi-config utility.

Note

If you are following the tutorial and are setting up the IO-device, you should head back now. See Tutorial.

Installation using a Windows laptop¶

This section describes how to install the Raspberry Pi OS and how to enable ssh and serial console so that the Raspberry Pi can exist used in headless mode without a display and keyboard connected.

Step 1. Write Raspberry Pi OS paradigm to SD card using Raspberry Pi Imager.

  • Download and install Raspberry Pi Imager from https://world wide web.raspberrypi.com/software/

  • Start Raspberry Pi Imager

  • In the Select OS dialog choose total version

  • Select SD-card

  • Press Write

Stride ii. Initial configuration of Raspberry Pi Os.

  • Squirt SD-card

  • Reinsert SD-card in windows PC. The SD-card will be shown every bit external drive named boot .

  • Enable ssh by creating an empty file named ssh in the root binder of kick . The windows file explorer can be used for this. Note that the file ssh shall not accept a txt file extension.

  • Enable serial port console. Open up config.txt in root binder of boot using Notepad. Add together the line enable_uart=ane to the stop of the file. Relieve file and close Notepad.

  • Squirt SD-card

Step 3. Start Raspberry Pi

  • Insert SD-card and power on Raspberry Pi.

  • Login (preferably using serial console) with default user pi and password raspberry .

Stride 4. Network configuration.

Apply the nano editor to edit the configuration files as described beneath. For example to edit the /etc/dhcpcd.conf :

                            sudo              nano              /              etc              /              dhcpcd              .              conf            

Relieve the file in nano by pressing CTRL-X , and then Y and Enter .

The DHCP client daemon volition adapt the network interface settings automatically. This interferes with the p-cyberspace control of the Ethernet interface. So if y'all run your Raspberry Pi every bit a Profinet IO-Device (NOT if you lot utilise it as a PLC) and take a series cable, you should add the line below to /etc/dhcpcd.conf :

Optionally, to modify hostname from raspberrypi to pndevice-pi , change the configuration in the files /etc/hostname and /etc/hosts .

To make sure that you subsequently are logging in to the correct Raspberry Pi, yous can create a file in the home directory in the rootfs partition. Change name to something informative, for example:

                            touch              /              home              /              pi              /              IAmAProfinetDevice            

Reboot and the Raspberry Pi is now gear up to run the p-internet sample application:

If y'all would connect your Raspberry Pi to a WiFi network, follow the guide in https://world wide web.raspberrypi.com/documentation/computers/configuration.html

You might as well want to disable the splash screen and to expand the file system, past using the raspi-config utility.

Annotation

If you are following the tutorial and are setting upward the IO-device, you should head back now. Come across Tutorial.

Optionally connect a series cable to Raspberry Pi¶

The p-internet Profinet stack will alter the IP-address of the Raspberry Pi when running it as an IO-Device (equally requested by the PLC), why it can exist inconvenient to connect to it via ssh. You tin use a keyboard, mouse and a monitor to connect to the Raspberry Pi. Using a serial cable to connect it to your laptop tin can and so be helpful if a keyboard etc not is available.

Utilize a USB-to-series adapter cable with three.3 Five logic levels. For example Adafruit sells a popular version of those cables. Connect the USB end to your laptop and the other end to the header connector on the Raspberry Pi.

If not already done, enable the serial port console by writing the line enable_uart=1 in the file /boot/config.txt .

The series port within the Raspberry Pi will be named /dev/ttyS0 .

Pin

Proper name

Terminal on cable

Adafruit cable color

6

GND

GND

Black

8

UART0_TXD

RX

White

10

UART0_RXD

TX

Green

Use a communication program with a baud rate of 115200.

Before connecting the serial cable to your Raspberry Pi you tin can verify the functionality of the cable by connecting the USB connector to your Laptop, and connect the RX-terminal to the TX terminal of the cable. Employ a communication program to verify that text that you enter is echoed back. When removing the RX-to-TX connectedness the echo should stop.

Optionally connect LEDs and buttons to Raspberry Pi¶

You need these components:

Component

Number required

LED

2

Button switch

2

Resistor 220 Ohm

4

Connect them like:

Pin

Proper noun

Description

9

GND

11

GPIO17

Connect LED1 (application data) to GND via 220 Ohm

13

GPIO27

Connect Button1 to three.3V via 220 Ohm

15

GPIO22

Connect Button2 to 3.3V via 220 Ohm

xvi

GPIO23

Connect LED2 (Profinet signal) to GND via 220 Ohm

17

3.3V

The resistors for the buttons are to limit the consequences of connecting the wires to wrong pins.

Fix upwards the GPIO pins for the buttons:

                            echo              22              >              /              sys              /              course              /              gpio              /              export              echo              27              >              /              sys              /              class              /              gpio              /              export            

and for the LEDs:

                            echo              17              >              /              sys              /              class              /              gpio              /              export              echo              23              >              /              sys              /              class              /              gpio              /              consign              echo              out              >              /              sys              /              class              /              gpio              /              gpio17              /              management              repeat              out              >              /              sys              /              course              /              gpio              /              gpio23              /              direction            

Plow on and off a LED:

                            echo              i              >              /              sys              /              class              /              gpio              /              gpio17              /              value              echo              0              >              /              sys              /              class              /              gpio              /              gpio17              /              value            

Show land of buttons:

                            cat              /              sys              /              class              /              gpio              /              gpio22              /              value              true cat              /              sys              /              class              /              gpio              /              gpio27              /              value            

_images/RaspberryPiLedButtons.jpg

Adjust IP address if using the Raspberry Pi as a PLC¶

If running your Raspberry Pi as a PLC (Profinet IO-Controller). you would like to have a static IP address (it will not work if running equally a Profinet IO-Device). Instead alter the file /etc/dhcpcd.conf to include these lines:

                            interface              eth0              static              ip_address              =              192.168.0.100              /              24            

Yous tin can all the same ping the <hostname>.local accost to find it on the network. To re-enable DHCP, remove the lines once more from /etc/dhcpcd.conf .

Once you have prepared the IP accost etc on the Raspberry Pi intended for use every bit a PLC, it is fourth dimension to install the Codesys runtime on information technology. Run into Using Codesys soft PLC.

Advanced users only: Automated kickoff of sample application¶

Utilise systemd to automatically start the p-internet sample application at boot on a Raspberry Pi. Place a systemd unit of measurement file here: /lib/systemd/system/pnet-sampleapp.service

An instance file is available in the sample_app/ directory of this repository. It assumes that the code is checked out into /home/pi/profinet/p-net/ on your Raspberry Pi. Install the files:

                            sudo              cp              /              home              /              pi              /              profinet              /              p              -              cyberspace              /              src              /              ports              /              linux              /              pnet              -              sampleapp              .              service              /              lib              /              systemd              /              system              /              sudo              cp              /              home              /              pi              /              profinet              /              p              -              internet              /              src              /              ports              /              linux              /              enable              -              rpi              -              gpio              -              pins              .              sh              /              usr              /              bin              /              sudo              chmod              +              x              /              usr              /              bin              /              enable              -              rpi              -              gpio              -              pins              .              sh            

Adapt the contents to your paths and hardware.

Enable automatic startup:

                            sudo              systemctl              daemon              -              reload              sudo              systemctl              enable              pnet              -              sampleapp              .              service            

Showtime service:

                            sudo              systemctl              start              pnet              -              sampleapp              .              service            

To meet the status of the process, and the log output:

                            systemctl              status              pnet              -              sampleapp              .              service              journalctl              -              u              pnet              -              sampleapp              -              f            

If using a serial cablevision, you might need to accommodate the number of visible columns:

You can for instance add information technology to your .bashrc file on the Raspberry Pi.

In order to speed upward the boot time, y'all might want to disable some functionality not necessary for Profinet applications. For example:

                            sudo              systemctl              disable              cups              -              browsed              .              service              sudo              systemctl              disable              cups              .              service            

See the section "Boot time optimization" elsewhere in this documentation.

Advanced users simply: Control of congenital-in LEDs¶

The Raspberry Pi lath has LEDs on the board, typically a red PWR LED and a green ACT (action) LED.

Manually control the green LED (ACT = led0 ) on Raspberry Pi 3:

                            echo              none              >              /              sys              /              grade              /              leds              /              led0              /              trigger              echo              one              >              /              sys              /              grade              /              leds              /              led0              /              brightness            

And to plough it off:

                            echo              0              >              /              sys              /              class              /              leds              /              led0              /              effulgence            

Note that you need root privileges to control the LEDs.

Similarly for the blood-red (ability) LED, which is called led1 .

Advanced users only: Control Linux existent-fourth dimension backdrop¶

Run across the page on Linux timing in this documentation for an introduction to the subject field.

Add this to the starting time (and only) line in /kicking/cmdline.txt :

Run the sample application on a specific CPU core, by modifying the autostart file /lib/systemd/organisation/pnet-sampleapp.service (if installed):

                            ExecStart              =              taskset              -              c              2              /              home              /              pi              /              profinet              /              build              /              pn_dev              -              v              -              b              /              sys              /              class              /              gpio              /              gpio27              /              value              -              d              /              sys              /              grade              /              gpio              /              gpio22              /              value            

SD-card problems¶

If y'all take problems with the CPU freezing for a few seconds at present and then, the SD-card might be damaged. There is a SD-card exam program bachelor for Raspberry Pi:

                            sudo              apt              update              sudo              apt              install              agnostics            

Start the test program:

              pi@raspberrypi:~$ sh /usr/share/agnostics/sdtest.sh            

Example output for a damaged SD-menu:

                            Run              i              prepare              -              file              ;              0              ;              0              ;              2029              ;              3              seq              -              write              ;              0              ;              0              ;              2944              ;              v              rand              -              4              yard              -              write              ;              0              ;              0              ;              705              ;              176              rand              -              4              k              -              read              ;              7444              ;              1861              ;              0              ;              0              Sequential              write              speed              2944              KB              /              sec              (              target              10000              )              -              Fail              Note              that              sequential              write              speed              declines              over              fourth dimension              equally              a              menu              is              used              -              your              card              may              require              reformatting              Random              write              speed              176              IOPS              (              target              500              )              -              FAIL              Random              read              speed              1861              IOPS              (              target              1500              )              -              Pass