Is there a way to use raspi-gpio command?

I have a Python script inside the snap application that tries to run raspi-gpio command:

import subprocess

subprocess.run(['raspi-gpio', 'set', '18', 'ip', 'pd'])

but due to confinement this command can’t be run, because it doesn’t exist for snap container. Is there a way to do/enable it? I’m using gpiozero Python package for other things and I have gpio, gpio-control plugs enabled (I don’t know how they work tho).

is there any reason to not use

https://pypi.org/project/RPi.GPIO/
?

I have no idea, we switched from RPi.GPIO to gpiozero, but the reasons are unclear to me.

well, either is better than shelling out to raspi-gpio … thats why i asked :slight_smile: (i believe @waveform plans to backport raspi-gpio eventually though, so you should eventually be able to stage it in a snap and use it like above if you really need/want to)

1 Like

Oh, sorry, i seem to have totally missed the point of the question, being focused on the highlighted python code …

to use the gpio interfaces you need to connect them to the respective gpio slots provided by the gadget snap on Ubuntu Core:

ogra@CM4:~$ snap connections pi
Interface    Plug  Slot            Notes
gpio         -     pi:bcm-gpio-0   -
gpio         -     pi:bcm-gpio-1   -
gpio         -     pi:bcm-gpio-10  -
gpio         -     pi:bcm-gpio-11  -
gpio         -     pi:bcm-gpio-12  -
gpio         -     pi:bcm-gpio-13  -
gpio         -     pi:bcm-gpio-14  -
gpio         -     pi:bcm-gpio-15  -
gpio         -     pi:bcm-gpio-16  -
gpio         -     pi:bcm-gpio-17  -
gpio         -     pi:bcm-gpio-18  -
gpio         -     pi:bcm-gpio-19  -
gpio         -     pi:bcm-gpio-2   -
gpio         -     pi:bcm-gpio-20  -
gpio         -     pi:bcm-gpio-21  -
gpio         -     pi:bcm-gpio-22  -
gpio         -     pi:bcm-gpio-23  -
gpio         -     pi:bcm-gpio-24  -
gpio         -     pi:bcm-gpio-25  -
gpio         -     pi:bcm-gpio-26  -
gpio         -     pi:bcm-gpio-27  -
gpio         -     pi:bcm-gpio-3   -
gpio         -     pi:bcm-gpio-4   -
gpio         -     pi:bcm-gpio-5   -
gpio         -     pi:bcm-gpio-6   -
gpio         -     pi:bcm-gpio-7   -
gpio         -     pi:bcm-gpio-8   -
gpio         -     pi:bcm-gpio-9   -
i2c          -     pi:i2c-0        -
i2c          -     pi:i2c-1        -
i2c          -     pi:i2c-2        -
serial-port  -     pi:bt-serial    -
spi          -     pi:spidev0      -
spi          -     pi:spidev1      -

here is an application snap connected to gpio 14 of the pi gadget:

ogra@pi4:~$ snap connections pi-fancontrol|grep gpio
gpio              pi-fancontrol:gpio              pi4-devel:bcm-gpio-14  manual

And a blog post about that snap and the gpio connection:

2 Likes

Yeah, but for me LEDs are working until shutting down, it seems they’re somehow getting reset to the state before running the snap app. So, even if I turn off all LEDs in Python, after stopping snap it gets back and I have all LEDs on again. The code I posted earlier is my workaround for this problem, ugly but it works for me.