Install Raspberry Pi OS on the Raspberry Pi (by using a Linux laptop)¶
Download the Raspberry Pi OS (previously Raspbian) image from https://www.raspberrypi.org/software/operating-systems/ Use the full version with “recommended software”. Follow the instructions on the page to burn a SD-card.
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
config.txt in the boot partition:
The DHCP client daemon will adjust the network interface settings automatically.
This interferes with the p-net control of the Ethernet interface. So if you
run your Raspberry Pi as a Profinet IO-Device (NOT if you use it as a PLC)
and have a serial cable, you need to add this line to
in the root file system:
If you would like to change hostname from “raspberrypi” to “pndevice-pi”, change
the texts in the files
etc/hosts in the rootfs
To make sure that you subsequently are logging in to the correct Raspberry Pi, you can create a file in the home directory in the rootfs partition. Change name to something informative, for example:
Unmount the SD-card, and plug it in into your Raspberry Pi. Power up the
Raspberry Pi. Log in to it via a serial cable. Use the username
the default password
If you do not have any serial cable (and not have disabled DCHP), connect the Raspberry Pi to your local network. Find the IP address of it by running this on a Linux machine on the network (replace the hostname if you have changed it):
Verify that it is the correct machine by checking that is disappears when the power is disconnected.
Log in to it:
Enter the password mentioned just above.
Connect a serial cable to Raspberry Pi¶
The p-net Profinet stack will change the IP-address of the Raspberry Pi when running it as an IO-Device (as requested by the PLC), why it can be inconvenient to connect to it via ssh. Using a serial cable to connect it to your laptop can then be helpful.
Use a USB-to-serial adapter cable with 3.3 V logic levels. For example Adafruit sells a popular version of those cables.
If not already done, enable the serial port console by writing the line
enable_uart=1 in the file
The serial port within the Raspberry Pi will be named
Terminal on cable
Adafruit cable color
Use a communication program with a baud rate of 115200.
Before connecting the serial cable to your Raspberry Pi you 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. Use a communication program to verify that text that you enter is echoed back. When removing the RX-to-TX connection the echo should stop.
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 as a Profinet IO-Device).
Instead modify the file
/etc/dhcpcd.conf to include these lines:
interface eth0 static ip_address=192.168.0.100/24
You can still ping the <hostname>.local address to find it on the network.
To re-enable DHCP, remove the lines again from
Advanced users only: Autostart of sample application¶
Use systemd to automatically start the p-net sample application on startup.
Place a systemd unit file here:
An example 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 file:
sudo cp /home/pi/profinet/p-net/sample_app/pnet-sampleapp.service /lib/systemd/system/
Adapt the contents to your paths and hardware.
Enable automatic startup:
sudo systemctl daemon-reload sudo systemctl enable pnet-sampleapp.service
To see the status of the process, and the log output:
systemctl status pnet-sampleapp.service journalctl -u pnet-sampleapp -b
If using a serial cable, you might need to adjust the number of visible columns:
stty cols 150 rows 40
Advanced users only: Control of built-in LEDs¶
The Raspberry Pi board has LEDs on the board, typically a red PWR LED and a green ACT (activity) LED.
Manually control the green LED (ACT =
led0) on Raspberry Pi 3:
echo none > /sys/class/leds/led0/trigger echo 1 > /sys/class/leds/led0/brightness
And to turn it off:
echo 0 > /sys/class/leds/led0/brightness
Note that you need root privileges to control the LEDs.
Similarly for the red (power) LED, which is called