GPIO hardware controls
#1
Hi!

(I'm very new to xbmc, python and programming in general, so I may say very stupid things. Please help me learn!)

The plan for my raspberry pi is a media center that can run, and be controlled, headless. Like a stereo set. I have an lcd working, now I want controls, and I want to use buttons hooked up to the gpio pins. The buttons work, but I can't get them to work with an xbmc python script.

The problem seems to be the permissions; the python plugin xbmc uses doesn't have root acces, which is required to use the RPi.GPIO python module.
Here's the code I've been using to check for button presses:
Code:
import RPi.GPIO as GPIO
import time
GPIO.setmode(BCM)
GPIO.setup(22, GPIO.IN)
while True:
    if ( GPIO.input(22) == False )
             print("Button pressed")
    time.sleep(0.1); #so I don't have to keep it pressed for too long.
which works if I run it through SSH. The 'print...' bit is a placeholder.
Say I want this button to mean 'navigate right', I figured my code should be:
Code:
import xbmc

xbmc.ExecuteBuiltin("right")
So my question is, how do I get this to work? That is, (I think,) how do I get xbmc the correct permission to do this? Or if someone has a different idea on how to do this, I'm all ears.
Reply
#2
I think they might be able to help you in the Development subforum as it has a lot to do with the way XBMC works internally.
Reply
#3
Okay thanks, I'll try that.
Reply
#4
os.system("sudo python /path/to/your/gpio/script")
Reply
#5
(2013-02-01, 00:17)s7mx1 Wrote: os.system("sudo python /path/to/your/gpio/script")

so I now have one script, default.py:
Code:
import os
os.system("sudo python /home/pi/.xbmc/addons/script.service.hardware.buttons/buttons.py")

and buttons.py:
Code:
import time
import RPi.GPIO as GPIO
import xbmc

GPIO.setmode(BCM)
GPIO.setup(22, GPIO.IN)
while True:
    if ( GPIO.input(22) == False )
             xbmc.executebuiltin("Right")
    time.sleep(0.1);

It doesn't give the 'fail to execute script' message on startup that it did before, but it doesn't do anything either. Wrong 'if' bit maybe?
Reply

Logout Mark Read Team Forum Stats Members Help
GPIO hardware controls0