Currently working on a script for XBMC (raspbmc)
I have several pushbuttons connected to the GPIO (model B)
I have a working script that detects the button presses, and also a working script that will command XBMC to play a playlist. (shown below)
where I run into problems is that XBMC seems to have it's own python interpreter with it's own set of modules.
So say if I try to "import xbmc" using python over SSH - it fails, stating no module found.
however launching this from /home/pi/.xbmc/usedata/autoexec.py on boot,
finds the module and works just fine.
likewise "import RPi.GPIO" fails from autoexec.py, and does not on python over SSH.
As I understand it, I must run "xbmc.executebuiltin" commands from within xbmc, and not externally (such as over SSH)
so.... how do I load the GPIO module in such a way that I can import it from within xbmc's python interpreter?
Code examples below:
My working GPIO detection script (working over SSH but NOT from XBMC)
Code: Select all
import RPi.GPIO as GPIO
import time
import os
GPIO.setmode(GPIO.BCM)
#GPIO.setup(18, GPIO.OUT)#indicator light on relay card
GPIO.setup(15, GPIO.OUT)#screen power button
GPIO.setup(8, GPIO.IN,pull_up_down=GPIO.PUD_UP)#front panel button
GPIO.setup(9, GPIO.IN,pull_up_down=GPIO.PUD_UP)#front panel button
GPIO.setup(10, GPIO.IN,pull_up_down=GPIO.PUD_UP)#front panel button
GPIO.setup(11, GPIO.IN,pull_up_down=GPIO.PUD_UP)#front panel button
#GPIO.setup(17, GPIO.IN,pull_up_down=GPIO.PUD_UP)#power button
while True:
# print "Waiting!"
time.sleep(0.5)
if (GPIO.input (8) == False):
print "Detected GPIO 8!"
GPIO.output(15, True)
time.sleep(0.1)
GPIO.output(15, False)
if (GPIO.input (9) == False):
print "Detected GPIO 9!"
if (GPIO.input (10) == False):
print "Detected GPIO 10!"
if (GPIO.input (11) == False):
print "Detected GPIO 11!"
Note the disabled lines. the script "fails" if I enable these lines.
Code: Select all
import xbmc
#import RPi.GPIO as GPIO
#import time
#import os
xbmc.executebuiltin( "PlayMedia(/home/pi/.xbmc/userdata/playlists/video/all.m3u)" )
xbmc.executebuiltin( "PlayerControl(repeat)" )