# Getting Started with Python

The `synergy_logic` package drives the SLM backplane from Python. The companion `slm_rp4_helpers` package reads the SLM-RP4's toggle switch; the RGB LED is driven with the Adafruit NeoPixel library. Both packages, along with their Adafruit Blinka dependency, are preloaded on the device.

```{admonition} Stop the PLC first
:class: danger

Stop the PLC, or stop the OpenPLC Runtime, before running any Python program that accesses the backplane. See [Sharing the Hardware](../shared-hardware-rules.md).
```

## Where the library is

Preloaded on the desktop of the `slm-rp4` user:

```text
~/Desktop/synergy_python/
├── synergy_logic/        the backplane library
├── slm_rp4_helpers/      toggle switch helper
└── examples/             worked examples for each module type
```

Run programs from this directory so the libraries are on the import path:

```bash
cd ~/Desktop/synergy_python
python3 examples/discrete_output.py
```

The simplest way to start a new program is to create it in this directory alongside the examples.

```{admonition} Working from another directory
:class: note

`import synergy_logic` resolves only when the interpreter can find the package. If the program lives elsewhere, add the library directory to `PYTHONPATH`:

    export PYTHONPATH=/home/slm-rp4/Desktop/synergy_python

Set the same variable in the service definition when running the program at boot. See {doc}`../running-on-boot`.
```

## Confirming the installation

From an SSH session:

```bash
cd ~/Desktop/synergy_python
python3 -c "import synergy_logic; print('synergy_logic ok')"
python3 -c "import slm_rp4_helpers; print('helpers ok')"
```

Both imports succeeding confirms the device is ready. Continue to {doc}`first-program`.

## Permissions

The `slm-rp4` user is already a member of the `spi` and `gpio` groups required to access `/dev/spidev6.0` and `/dev/gpiochip0`. No `sudo` is required for backplane operations.

```{admonition} The RGB LED requires sudo
:class: note

Driving the front-panel RGB LED requires root. The signalling protocol is timing-critical and the NeoPixel library needs direct hardware access. Run programs that control the LED with `sudo` or as a service running as root.
```

The SPI interface and other Raspberry Pi configuration are already set. See [Raspberry Pi / Device Setup](../../hardware/raspberry-pi-setup.md) for verification and recovery steps if the configuration is lost after a system update.
