2

I'm having great trouble trying to build a snap for a simple python code for Rpi2.

Code I would like to put into a Snap is:

# External module imports
import RPi.GPIO as GPIO
import time

print("Hello LED")

ledPin = 9

print("Setting Broadcom Mode")
# Pin Setup:
GPIO.setmode(GPIO.BCM) # Broadcom pin-numbering scheme

GPIO.setup(ledPin, GPIO.OUT) 

print("Here we go! Press CTRL+C to exit")
try:
while 1:
        print ("OFF");
        GPIO.output(ledPin, GPIO.LOW)
        time.sleep(1.00)
        print ("ON");            
        GPIO.output(ledPin, GPIO.HIGH)
        time.sleep(1) 
except KeyboardInterrupt: # If CTRL+C is pressed, exit cleanly:
   GPIO.cleanup() # cleanup all GPIO

The thing is that I don't seem to find in the documentation how to import rpi.GPIO Is this even possible?

Searched in https://github.com/ubuntu/snappy-playpen with no results

Thats the hard question. Easier question is.. How do I execute a python script with a snap? I tried putting in:

apps:
  helloLed:
      command: sudo python helloLed.py 

and without the sudo, after it triggered error for permission.

Thank you in advance! Will be posting full example tutorial when complete!

1
  • You need to include RPi.GPIO in your snap, perhaps with a requirements.txt. – kyrofa Dec 13 '16 at 18:42
0

Add it using Python3 plugin, OP included partial snapcraft.yaml, may be need only an edit:

...
parts:
  plugin: python3
  python-packages:
    - RPi.GPIO
...

Also it needs an access interface:

...
apps:
  ...
  plugs:
    - physical-memory-control
...

Then after installation the user should connect it, because that interface is not auto

sudo snap connect helloLed:physical-memory-control

Reference: Your first robot: Sharing with others [5/5]

Note

I still have some doubts: if RPi.GPIO building from source needed. If that was the case, that it should be declared in snapcraft.yaml as a part. See the linked reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.