[HowTo] Scripts for using Xbox Controller in RetrOSMC


I tried it with 0.006 and every thing worked fine.
With 0.007 i have problems with more than one controller.

In OSMC I turn both xbox360 controllers on. Only the first controller is working and the led is on 1. On the second controller every leds are flashing and buttons not working (this is right behavior).

Then i start the retropielauncher addon. The led from first controller is going on 3 and the leds from the second controller ends flashing and go on 1. Now the second controller is working in Emustation and in all games, the first controller do nothing. Only one controller is recognized by Emustation.

Any sugestion how to solve this problem?


Hi, can you copy here your retropie_watchdog.sh and retropie.sh files. I have problem to use xbox controller when retropie is on.


I just wanted to keep this thread alive. I just followed the instructions from Yggdrasil in the OP on retrosmc 0.007 and the latest OSMC with Kodi/Jarvis using a new RaspberryPi 3. As a couple people mentioned, the config would work to control the emulation station menus, but not in the games themselves. I was getting the following error when the switchtoxpad.sh script would run.

Error couldn’t claim the USB interface: LIBUSB_ERROR_BUSY

This would block the first controller from working in RetroPie. After a lot of tinkering, I got things working. I saw in other posts people blacklisted xpad on boot, which may or may not be needed.

sudo nano /etc/modprobe.d/raspi-blacklist.conf

Add the text:

blacklist xpad

Reboot. With this out of the way I could remove the calls to “rmmod xpad”.

I then added a long sleep to my switchtoxpad.sh after the kill command.

sudo kill -9 `ps -ef | grep xboxdrv | grep -v grep | awk '{print $2}'`
sleep 6
sudo xboxdrv --wid 0 --led 3 --alt-config /home/osmc/buttonswap.ini & sleep 2
sudo xboxdrv --wid 1 --led 4 --alt-config /home/osmc/buttonswap.ini & sleep 2

I was using the xboxdrv bin installed by retrosmc in /opt/retropie/… (I don’t have the full path handy) rather than the apt-get binary shown above (again, this might not matter). With these changes in place the switchtoxpad.sh and switchtoxboxdrv.sh scripts seemed to hand off ok, which you can check with :

ps aux | grep xboxdrv

In the original directions the first controller (wid 0) wouldn’t be running. With these in place I was able to configure the button mapping in the RetroPie GUI where you map every button on the xbox controller. I managed to do this for two controllers and verify they worked in a couple SNES games. Victory! I did a couple reboots and switched between Kodi and RetroPie a few times, showing the controller settings persist. I have a new SD card coming soon, so I get to do this all over again on a fresh install. Hopefully I can follow my own instructions. I think adding the long sleep was the crux of getting this working, though I didn’t seem to need it in my switchtoxboxdrv.sh script.

Thanks to Yggdrasil and everyone who contributed to this thread. We may not get world peace, but at least we can have Mario with wireless controllers.


I’m having trouble getting this to work with Rpi3, wireless dongle and 2 xbox 360 controllers.
If I SSH in an manually run the scripts then it works. i.e run start.sh and it works in OSMC, then switch to RetroPi and xboxdrv stops, but doesn’t seem to restart with the retropie config. If I run the switchtoxpad.sh script it works for MegaDrive but not for Dreamcast (only 2 emulators I tried). Then when I exit back to OSMC again xboxdrv stops but doesn’t restart with OSMC config.

It seems the scripts are running when you start/leave retropie as it kills the last xboxdrv process, but can’t seem to start the new one unless I manually do it via SSH. Anyone know why this might be the case? permissions error?
Also, is there anything I need to do to get the controller to work with Dreamcast?



Hi jay

Any chance you could do a step by step process from the start as it seems you got it working correctly.



Got exactly the same situation, previously I used to have the very same setup running with Xbox 360 controller (non wireless) and it was working without any issues (besides the fact that from time to time when I reboot OSMC it does not respond, had to go into retropie to be able to use the pad, this was not an issue as I used the pad only for emulators, not XBMC itself). Today I received “Microsoft Xbox 360 Wireless Controller (PC)” , changed the config to reflect the new device name and apparently the behavior is exactly the same as in your case, if I run the script or the commands via SSH it works, also from time to time when I reboot kodi the controller is working there as well, yet, after launching retropie the very same LED stays lit (#1, top left), and cannot get controller to respond, after running switchtoxpad scripts it is working as expected. Interesting is that if I force the pad to work with the script and I go back to OSMC the pad is still working and LED #2 stays lit, then when I launch retropie again there are no changes to the LEDs (still #2 lit) and controller is not working.


Ok got it to work (more or less):

switchtoxpad < works, (does not necessarily always work in OSMC after start, but after I launch retropie it switches led from 1 to 2 (also restarts xboxdrv) and I can use the pad both in games and in emulation station)

sudo kill -9 $(pidof xboxdrv)
sleep 6
sudo xboxdrv --wid 0 --led 3 --alt-config /home/osmc/scripts/buttonswap.ini & sleep 2

switchtoxboxdrv < somehow still doesnt work, doesnt change led from 2 to 1, BUT, even on led 2 controller works flawlessly in OSMC after quiting emulation station.
sudo pkill xboxdrv #kill Xboxdrv Process
sleep 6
sudo /usr/bin/xboxdrv --config /home/osmc/scripts/xbmc.ini --wid 0 --led 2 --silent --autofire RT=25 --autofire LT=25 --autofire du=200 --autofire dd=200 --autofire dl=500 --autofire dr=500 #restart Xboxdrv with Kodi config


Thanks Sparta

I’ll try your scripts.

Would you know by any chance how to autofire the thumbs sticks like the dpad.



Hi sparta again

I can only get my xbox 360 controller working on retropie.

Doesnt work controlling osmc although the led 1 is on signalling its connected.

Im getting errors running it in ssh though.

osmc@osmc:~$ sudo xboxdrv
xboxdrv 0.8.5 - http://pingus.seul.org/~grumbel/xboxdrv/
Copyright © 2008-2011 Ingo Ruhnke grumbel@gmx.de
Licensed under GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it under certain conditions; see the file COPYING for details.

Controller: Microsoft Xbox 360 Wireless Controller
Vendor/Product: 045e:0291
USB Path: 001:004
Wireless Port: 0
Controller Type: Xbox360 (wireless)

– [ ERROR ] ------------------------------------------------------
Error couldn’t claim the USB interface: LIBUSB_ERROR_BUSY
Try to run ‘rmmod xpad’ and then xboxdrv again or start xboxdrv with the option --detach-kernel-driver.

I have blacklisted xpad as tried detach kernel option.

Do you get these errors?

Thanks for any info



my understanding is that this is expected behavior since the pad is already connected and running (led lit). You still cannot control OSMC AFTER leaving retropie with start -> quit -> restart (first option from top, this is the option that should be ran)?

BTW, got it to work fully:

1)Once I reboot PI in OSMC its flashing all the time (no led lit, yet its working as expected)
2)When I go into retropi LED #2 stays lit and its working (no gamepads detected message is displayed, wait couple of seconds and press right trigger)
3) When I quit to OSMC wait couple of seconds and its working ( led #1 lit)

Tested couple of times in and out


sudo rmmod xpad
sleep 6
sudo pkill xboxdrv #kill Xboxdrv Process
sudo /usr/bin/xboxdrv --config /home/osmc/scripts/xbmc.ini --id=0 --led=2 --silent --autofire RT=25 --autofire LT=25 --autofire du=200 --autofire dd=200 --autofire dl=500 --autofire dr=500 & sleep 2


sudo kill -9 $(pidof xboxdrv)
sleep 3
sudo xboxdrv --wid 0 --led 3 --alt-config /home/osmc/scripts/buttonswap.ini & sleep 2


sudo pkill xboxdrv #kill Xboxdrv Process
sleep 6
sudo /usr/bin/xboxdrv --config /home/osmc/scripts/xbmc.ini --wid 0 --led 2 --silent --autofire RT=25 --autofire LT=25 --autofire du=200 --autofire dd=200 --autofire dl=500 --autofire dr=500 #restart Xboxdrv with Kodi config


So after a waaay too long break I wanted to give this another go with a single wireless 360 controller. To prevent any old stuff getting in the way, I started with a fresh installation of the 2016.07-1 image (Raspi 2). Installed the updates, changed as little as possible (disabled CEC and HDMI audio due to CRT TV, switched to classic Kodi skin) and rebooted. SSH’d into the RPi and went through steps 1 to 4 word by word, command by command from Yggdrasil’s initial post, as I first wanted to get the wireless 360 controller working reliably in OSMC before even trying out retrosmc.

Result: It’s still a mess. And the infuriating thing is that I can’t tell what going wrong when. Sometimes the LED keeps flashing, sometimes it stays in position 1 as it is supposed to, sometimes no button or dpad works at all, sometimes they work if I press the dpad as soon as the home screen shows up after a reboot, sometimes I have to let it sit for a few seconds after reboot and then press the dpad. Same for reconnecting the controller once it goes into standby: half of the time it works flawlessly, I can take out the battery, put it back in and let it reconnect as often as I want; the other times it’s dead after disconnecting once.

I’ve played around with different values for sleep in /home/osmc/start.sh and /etc/rc.local.
I’ve blacklisted xpad in /etc/modprobe.d/raspi-blacklist.conf.
I’ve changed device-name = "Microsoft Xbox 360 Controller" to device-name = "Microsoft Xbox 360 Wireless Controller (PC)" in /home/osmc/xbmc.ini in step 2.
I’ve even tried different options from the xboxdrv manual like --type xbox360-wireless and --daemon.

No avail. And I hadn’t even touched steps 5 and 6!

sudo xboxdrv just says its old Error couldn't claim the USB interface: LIBUSB_ERROR_BUSY, no matter if the controller is working right now or not.

Is this due to a change in the kernel that came with the April update?

Is it any use trying to figure out why it doesn’t work, or should one just wait until OSMC incorporates RetroPlayer with v18?


strace xboxdrv and find out why it can’t get a handle.


Thanks for the reply and advice, Sam! I installed strace, here are the logs:

working dpad and buttons, LED blinking

dpad and buttons not working, LED staying lit on position 1

I tried to compare the two via Notepad++. Apart from the obvious different random hex addresses and empty lines I could only identify the line

futex(0x76785448, FUTEX_WAIT, 490, NULL) = -1 EAGAIN (Resource temporarily unavailable)

appearing ONLY in the working version (thirteenth to the last line) and NOT in the non-working version. While I do have basic knowledge of programming microcontrollers in ASM, this is way above my head, even reading the manpage of futex didn’t clear things up. I’d really like to be able to solve this on my own, but I lack the knowledge where to even start looking. Can anybody read what’s going on from the logs?


Your real problem is:

open("/dev/bus/usb/001/004", O_RDWR)    = -1 EACCES (Permission denied)

You shouldn’t have this problem with sudo though. What does ls -l /dev/bus/usb/001 show. You can also try chown -R osmc:osmc this path. If that works, then we need to set up a udev rule.

futex() is just a fast (userspace mutex) implementation. It locks until it gets access to a resource.

Edit: also check xpad stuff definitely isn’t loading with lsmod


The USB device belonged to root:

osmc@RASPI2:~$ ls -l /dev/bus/usb/001
total 0
crw-rw-r-- 1 root root 189, 0 Aug 18 13:51 001
crw-rw-r-- 1 root root 189, 1 Aug 18 13:51 002
crw-rw-r-- 1 root root 189, 2 Aug 18 13:51 003
crw-rw-r-- 1 root root 189, 3 Aug 18 13:52 004

so I changed its ownership by sudo chown -R osmc:osmc /dev/bus/usb/001 as you suggested. xpad is definitely not loaded, it never shows up in lsmod, neither when working nor when not-working:

Output of lsmod
osmc@RASPI2:~$ lsmod
Module                  Size  Used by
8021q                  22147  0
garp                    7622  1 8021q
stp                     2430  1 garp
llc                     6031  2 stp,garp
joydev                  9585  0
evdev                  13192  2
uinput                  9818  2
snd_bcm2835            24938  0
snd_pcm               115812  1 snd_bcm2835
snd_timer              25966  1 snd_pcm
snd                    78512  3 snd_bcm2835,snd_timer,snd_pcm
bcm2835_gpiomem         4026  0
bcm2835_thermal         2541  0
bcm2835_wdt             4081  0
lirc_rpi                9315  3
lirc_dev               11576  1 lirc_rpi
rc_core                25745  1 lirc_dev
uio_pdrv_genirq         3885  0
uio                    10428  1 uio_pdrv_genirq
fuse                  107913  1
ipv6                  447942  42

Here’s a log after the ownership change and when working. A little different, now the old

write(1, " Error couldn’t claim the USB in"…, 59 Error couldn’t claim the USB interface: LIBUSB_ERROR_BUSY
) = 59
write(1, “Try to run ‘rmmod xpad’ and then”…, 104Try to run ‘rmmod xpad’ and then xboxdrv again or start xboxdrv with the option --detach-kernel-driver.
) = 104

turns up again in the last lines. xpad isn’t loaded then, either, I checked again via lsmod.

ioctl(12, USBDEVFS_CLAIMINTERFACE, 0x7e95e08c) = -1 EBUSY (Device or resource busy)

Something is holding the device. You don’t have xboxdrv running as a daemon (systemd or init.d service) do you?


Nope, no -D or --deamon option, neither in /home/osmc/start.sh, /home/osmc/xbmc.ini or /etc/rc.local. Just as in step 2 of Yggdrasil’s initial post. Also deleted the /home/osmc/buttonswap.ini because it has [xboxdrv-daemon] in it, although I had no call to it at this point, just to make sure. No change in behaviour.


Without the hardware, I am not sure, sorry. I would try building a kernel without xpad module


I’m actually playing around with the idea of sending you a 360 wireless controller via [amazon.co.uk] (https://www.amazon.co.uk/Official-Xbox-Wireless-Controller-Windows/dp/B004JU0JSA/). :smiley: If you’d like to, I’d be happy to contribute to the project in this way. Please PM me the address to which to ship (the address given here also turns up on an internet fraud site, so I’d like to play it safe).

As for kernel building: Does this post by DBMandrake contain everything needed, or is there anything else I need to prepare, know, read besides the development entries in the wiki?


I have a Wired Xbox 360 Controller. If you have a wired one and can replicate the problem with that I can try and look at this.

Hehe. I formed the company using a website that does it all for you and they set up a mail forwarding address for anonymity. I need to update that as we have an actual office now.

Hold off for now on spending money, because even if I get one, I may not necessarily be able to fix the problem.

That’s it. But you want to disable the xpad modules from being built, so you need to check for CONFIG_XPAD (may not be exact option name) in patches/rbp2-000-add-kernel-config.patch and remove it. Ideally you want to set to IS NOT SET or use make menuconfig to properly generate the kernel configuration.

Then sudo dpkg -i rbp2-image… after.