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.
Stop the PLC first
Stop the PLC, or stop the OpenPLC Runtime, before running any Python program that accesses the backplane. See Sharing the Hardware.
Where the library is#
Preloaded on the desktop of the slm-rp4 user:
~/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:
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.
Working from another directory
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 Running on Boot.
Confirming the installation#
From an SSH session:
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 Quick Start: Python.
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.
The RGB LED requires sudo
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 for verification and recovery steps if the configuration is lost after a system update.