[HowTo] Scripts for using Xbox Controller in RetrOSMC

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.

#!/bin/bash
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
exit

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.