v16 Controll Kodi from Rpi gpio buttons [SOLVED]
#31
I think OSMC has a different implementation of RPI.GPIO that you can install, as I think RPi.tools is designed for LibreElec.

But if you do that then you will need to change the script to point to its new location (similar to post #26 above, but it will probably be in a different place again).

Aside from that you may need to ask on the OSMC forum (or ask Sam here) as OSMC seems to handle things differently from LE in terms of its user on which everything runs (LE runs things as root by default). The script may need to be run with root or sudo priv's to allow access to the GPIO, if the OSMC implementation of GPIO doesn't take care of that by default.

I'm not a great expert on OSMC as I've only installed it a couple of times for various testing - all of my active Pi's use LibreElec and the add-on was designed for its needs.
|Banned add-ons (wiki)|Forum rules (wiki)|VPN policy (wiki)|First time user (wiki)|FAQs (wiki) Troubleshooting (wiki)|Add-ons (wiki)|Free content (wiki)|Debug Log (wiki)|

Kodi Blog Posts
Reply
#32
Sorry for the grave dig...

I've tried Darren's add on and it installs just fine via the add on.
However, I only want to adjust volume via 2 GPIO's (one up, one down)
I've edited the py script to change the function of 2 buttons, but I cannot get the zip to install.
Kodi keeps coming up with an error.
I thought it might have been an issue with Windows and the compression tool, so tried 7zip and the compress tool within Raspian.
no luck Sad
Reply
#33
Ok, so I've solved my issue.
When I was re-zipping the script and XML it was creating another level of sub folders.
fixed that and its working !!
Reply
#34
(2016-05-13, 23:08)DarrenHill Wrote: OK, you should be able to download the current (final) version of my script, set up as a service add-on so that it runs at start-up - click here.

Just install that zip file like a normal add-on, and it should set itself up and run on Kodi start-up (you can enable and disable it if you need to as a service add-on). You will also need to install RPi.GPIO, which should be available from the built-in repositories (it depends on quite what you are running on your Pi, OSMC or LibreElec/OpenElec).

The hardware set-up I use is 6 push buttons on GPIO 17, 27, 22, 6, 13 and 19 (pins 11, 13, 15, 31, 33 and 35). One side of each button is connected to ground, the other side to the GPIO pin. They act as up, down, left, right, select and shift respectively, with shift switching the other buttons action to back (up), info (down), stop (left), pause/play (right) and context menu (select) respectively.

My hardware is wired up on a protozero board, hence why I only use 6 buttons (it's all that will fit) and use the shift button to give 10 input options. The board also has an IR receiver diode on it, wired up to the usual GPIO pins (data on GPIO18 (pin 12), ground to pin 6 and 3V3 power to pin 1). So I can run my zero either with an old IR remote or via the buttons.

thanks for the addon. I changed the pins to what i need and works fine. But i wanted to add a second button for play/pause, because using shift + right was a bit annoying. So what i did is create a new button variable, a new detect event, remove event etc. But i got a little confused at the region where you defined the callback stuff. Could you give me some help?
Reply
#35
The callback is the code that actually gets run when the button is pressed. For example, if I pull the code for one of the pins out of the script (don't try and run it, I've just pulled lines for upPin out of the script as an example):

Code:
upPin = 17        # board pin 11

...

def up_callback(channel):
    if(GPIO.input(shiftPin)):
        xbmc.executebuiltin("Action(Up)")
    else:
        xbmc.executebuiltin("Action(Back)")

...

GPIO.setup(upPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

...

GPIO.add_event_detect(upPin, GPIO.FALLING, callback=up_callback, bouncetime=300)

...

GPIO.remove_event_detect(upPin)

We are defining the up pin as GPIO 17 (first section of code), setting it up as an input with pull-out enabled (third section) and then adding the event (fourth section). In that event definition, we are saying that if a falling edge (GPIO.FALLING) is detected, then call the code block "up_callback" and ignore any further presses for 300ms.

The actual code run on buttonpress is "up_callback" (the second code block above) which in this case either calls xbmc built-in action "Up" or "Back" depending on the status of the shift pin (if GPIO.input(shiftPin) is true or not, ie if the pin is high or low, basically if the button connected to it is pressed or not).

A list of the available built-in functions is here in the Kodi Python documentation. Action is the simplest one, as it basically just ties in with the keymaps to trigger a button press action.

For play/pause, you want either xbmc.executebuiltin("Action(PlayPause)") (all the actions are from the keymap actions) or xbmc.executebuiltin("PlayerControl(Play)") from the player plugins.
|Banned add-ons (wiki)|Forum rules (wiki)|VPN policy (wiki)|First time user (wiki)|FAQs (wiki) Troubleshooting (wiki)|Add-ons (wiki)|Free content (wiki)|Debug Log (wiki)|

Kodi Blog Posts
Reply

Logout Mark Read Team Forum Stats Members Help
Controll Kodi from Rpi gpio buttons [SOLVED]0