GPIO control - fcorthay/xPL GitHub Wiki

Table of Contents

GPIO control

The RPi has a 40-pin General Purpose Input/Ouput (GPIO) connector whose pins can be individually watched or controlled. Some are specified to be binary outputs and all others are considered as binary inputs.

Installation

The GPIOs are controlled via the GPIO Zero Python interface.

The service allows even non-sudoer users to control the pins through the pigpio service. Activate it:

sudo systemctl enable pigpiod
sudo systemctl start pigpiod

Test

Start the script in a terminal:

XPL_BASE_DIR=~/Controls/xPL
GPIOZERO_PIN_FACTORY=pigpio $XPL_BASE_DIR/utilities/xpl-RPi_GPIO.py -o 20,21,23,24,25,26 -v

The -o parameters specifies which are the output pins.

In a second terminal, start an xPL monitor:

XPL_BASE_DIR=~/Controls/xPL
$XPL_BASE_DIR/xPL-base/xpl-monitor.pl -vf

In a third terminal, send commands:

XPL_BASE_DIR=~/Controls/xPL
GPIO_SERVER='dspc-gpio.lachesis'
$XPL_BASE_DIR/xPL-base/xpl-send.pl -d $GPIO_SERVER -c gpio.basic led=23 set=on
$XPL_BASE_DIR/xPL-base/xpl-send.pl -d $GPIO_SERVER -c gpio.basic led=23

The LED attached to GPIO pin 23 should reflect the command. The monitor shows what happens.

Service

Edit the service specification file:

XPL_BASE_DIR=~/Controls/xPL
SERVICE='xpl-RPi_GPIO'
nano $XPL_BASE_DIR/services/$SERVICE.service

Update the output pins list specified by the -o parameter.

Copy the file to the system directory:

sudo cp $XPL_BASE_DIR/services/$SERVICE.service /lib/systemd/system/

Start the service:

sudo systemctl enable $SERVICE.service
sudo service $SERVICE start
sudo service $SERVICE status | cat

Integration

The central control service and its configuration file allow to pipe the press of a button to an actuation.

Pressing and releasing a button will trigger 2 xPL messages. If one wants to emulate an on-off switch button, the trigger messages also provide a toggle value which changes at each button press.

⚠️ **GitHub.com Fallback** ⚠️