# Raspberry Pi / Device Setup

The SLM-RP4 runs Raspberry Pi OS on an SD card. The sections below cover the operational practices required to keep the device reliable in the field.

(clean-shutdown)=
## Clean shutdown

Removing power while the filesystem is being written can corrupt the SD card. The journaled filesystem recovers from most interruptions, but a clean shutdown is preferred.

The preferred method, when SSH or local shell access is available, is:

```bash
sudo shutdown -h now
```

Wait for the green activity LED next to the SD card slot to go dark before removing power. See {ref}`raspberry-pi-status-leds`.

If no shell access is available, stop the PLC application before cutting 24 VDC, either with the OpenPLC Editor's **Stop** button or by moving the toggle switch to **F**. Removing power with the OpenPLC Runtime in stop mode is normally safe.

## Network configuration

The device requests an IP address over DHCP on first boot. The current address is reported by:

```bash
hostname -I
```

To assign a static address, use `nmtui` or edit the NetworkManager connection directly. See the [Raspberry Pi networking documentation](https://www.raspberrypi.com/documentation/computers/configuration.html#configure-networking) for the full procedure.

The default hostname is `slm-rp4`. Networks that resolve `.local` hostnames reach the device at `slm-rp4.local`.

## SSH access

The device accepts SSH connections on port 22.

| | |
|---|---|
| Username | `slm-rp4` |
| Password | `slm-rp4` |
| Hostname | `slm-rp4` |

```bash
ssh slm-rp4@<device-ip>
```

Change the password on every unit before deployment:

```bash
passwd
```

For long-term use, configure key-based authentication and disable password authentication in `/etc/ssh/sshd_config`. See [Accessing the Device](../advanced/accessing-the-device.md) for the full procedure.

## SPI interface

The backplane uses `/dev/spidev6.0`, enabled by an overlay in `/boot/firmware/config.txt`:

```text
dtoverlay=spi6-2cs,cs0_pin=9,cs1_pin=10
```

```{admonition} Verify SPI after system updates
:class: warning

A Raspberry Pi OS update may reinstate the default SPI configuration and disable the backplane. After `apt upgrade` or any change to `/boot/firmware/config.txt`, verify that `/dev/spidev6.0` is present:

    ls -l /dev/spidev6.0

If the device is missing, confirm the overlay line above is still in `config.txt` and reboot.
```

Do not enable **Interface Options → SPI** in `raspi-config`. That toggle sets `dtparam=spi=on`, which enables SPI0 on GPIO 7–11 (CE1, CE0, MISO, MOSI, SCLK). GPIO 9 and 10 are the chip selects of the backplane's SPI6 overlay (`cs0_pin=9,cs1_pin=10`), so enabling SPI0 disables backplane communication.

(reserved-gpio-pins)=
## Reserved GPIO pins

The backplane uses the following GPIO pins. Driving any of them from user code breaks backplane communication for both OpenPLC Runtime and the direct libraries.

| Pin | Function |
|---|---|
| GPIO 19 | SPI6 MISO |
| GPIO 20 | SPI6 MOSI |
| GPIO 21 | SPI6 SCLK |
| GPIO 9, 10 | SPI6 chip selects assigned by the overlay (`cs0_pin=9,cs1_pin=10`) |
| GPIO 27 | Base controller chip select |
| GPIO 25 | Base controller acknowledge |
| GPIO 17 | Base controller enable |

The front-panel controls also use fixed pins:

| Pin | Function |
|---|---|
| GPIO 13 | T/F toggle switch |
| GPIO 18 | RGB LED |

Check pin assignments before claiming additional GPIO:

```bash
pinctrl
```

(timekeeping)=
## Timekeeping

The SLM-RP4 has no battery-backed real-time clock. The system clock is set over the network through NTP and is accurate whenever the device has network access.

A device that boots without network access starts with an approximate time until synchronisation completes. Record an elapsed counter alongside timestamps if timestamp accuracy at boot matters.

```bash
timedatectl
```
