EDIT
See RPi3 GPIO confinement from a SNAP called from another SNAP
This won’t work until snapd 2.31, and exposes the “gpio-memory-control” slot
Also your program will have to run as a daemon (which should not be a problem)
I’ve edited my OP to reflect these changes, minding any errors as this is untested.
I will also make a full example and edit this post again.
OP
Hello
The easiest way (imo) is to use the RPI.GPIO python package;
In your snapcraft.yaml, define a part such as:
parts:
setup:
plugin: python
python-version: python3
python-packages: [RPi.GPIO]
Now you can have an app which has the gpio gpio-memory-control plug:
apps:
myprogram:
command: bin/myprogram
daemon: simple
plugs: [gpio-memory-control]
Your “myprogram” script daemon could look like this:
#!/usr/bin/env python3
import RPi.GPIO as GPIO
import time
# Set up PIN 0 as output
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(0, GPIO.OUT)
on = True
# Every second toggle output
while True:
GPIO.output(0, on)
on = not on
time.sleep(1)
Do not forget to connect the slot/plug!