28 December 2012

RetroPie & a SIXAXIS over bluetooth

So after I got Raspbmc up and running without any issues I decided to go straight for the retro games emulator.

For this I used the following:

So from a fresh boot of Raspbian we need to tweak a few things first.
From the raspi-config screen you need to do:
  • Expand the filesystem to fill the SD card.
  • Change the memsplit to 128 or 192.
  • Change the password for user pi.
  • Overclock (optional and at your own risk)
Once that has been done and the Pi has rebooted, log in and run the following commands:

sudo apt-get update
sudo apt-get upgrade -y

Now we can move on to setting up RetroPie.

First we need to install some dependencies:

sudo apt-get install git dialog -y

And now to download and run the RetroPie setup script:

git clone git://github.com/petrockblog/RetroPie-Setup.git
cd RetroPie-Setup/
chmod +x retropie_setup.sh
sudo ./retropie_setup.sh

Now you have 2 options to install RetroPie - Binaries and Source.
I prefer to use Source so let's select that option.
Now we can choose what to install. If you want everything just leave it as is, but if there are some emulators you'll never use, untick them now to save time and space.
Run the install. Wait 3-4 hours to RetroPie to compile.

Once that is completed you'll have a debug output with any issues encountered (hopefully none).
Reboot your Pi.

Now you have RetroPie installed and you can run it with:

But we're not done yet. I have a PS3 controller I want to use with both EmulationStation and RetroArch over bluetooth.

So to get that working we need the following dependencies:

sudo apt-get install bluez-utils bluez-compat bluez-hcidump libusb-dev libbluetooth-dev joystick checkinstall -y

Give it a few minutes to install.

Once that has completed, let's see if our Bluetooth dongle is detected (for mine I had to make sure it was plugged into one of the Pi's USB ports - not a USB hub).


You should get something similar to this output:

pi@raspberrypi ~ $ hciconfig
hci0: Type: BR/EDR Bus: USB
BD Address: 00:02:72:BF:BC:8F ACL MTU: 1022:8 SCO MTU: 121:3
RX bytes:16777722 acl:289271 sco:0 events:116 errors:0
TX bytes:2561 acl:53 sco:0 commands:56 errors:0

The key thing we're looking for here is the UP RUNNING PSCAN. If it says DOWN - you've got an issue with your dongle's chipset - or as in my case you've plugged it into a USB hub.

Now we can pair the dongle with the controller using Sixpair.

wget http://www.pabr.org/sixlinux/sixpair.c
gcc -o sixpair sixpair.c -lusb

With your controller plugged in, run the following:

sudo ./sixpair

You'll get something similar to the following output:

Current Bluetooth master: 00:02:72:BF:BC:8F
Setting master bd_addr to: 00:02:72:BF:BC:8F

(Note: When you first run sixpair, the two addresses above will be different - mine are the same because I've already paired the dongle with the controller.)

Now we just need SixaD to manage the controller.

wget http://sourceforge.net/projects/qtsixa/files/QtSixA%201.5.1/QtSixA-1.5.1-src.tar.gz
tar xfvz QtSixA-1.5.1-src.tar.gz
cd QtSixA-1.5.1/sixad
sudo mkdir -p /var/lib/sixad/profiles
sudo checkinstall

I've used checkinstall here as it creates a Deb package to help you uninstall it later on. Just hit enter at the prompts and it'll install.

We'll need to start the sixad daemon at startup:

sudo update-rc.d sixad defaults

And start the service now:

sudo service sixad start

Now unplug the controller and press the PS button. You should see the lights go back and forth and it'll rumble for a second or two. Congrats - it works!

(NOTE: As of the latest Raspbian image (2012-02-22), your controller will probably keep flashing and not rumble. The controller has connected but isn't reading the SixaD profile correctly. You can continue to complete this guide but you'll need to create and use my controller configs manually. Looking into a fix for this.)

But we're not finished yet. We need to set up the controller to work inside EmulationStation and RetroArch.

First off let's create a sixad profile for the controller.

sudo nano /var/lib/sixad/profiles/default

Add the following content:

enable_leds 1
enable_joystick 1
enable_input 0
enable_remote 0
enable_rumble 1
enable_timeout 0
led_n_auto 1
led_n_number 1
led_anim 1
enable_buttons 1
enable_sbuttons 1
enable_axis 1
enable_accel 0
enable_accon 0
enable_speed 0
enable_pos 0

Now reboot with the following:

sudo reboot

Once you've logged in, press the PS button again on the controller. It should rumble like before.
This time we've disabled the motion controls as they have some screwy behaviour when setting up controllers in EmulationStation.

Now run emulationstation - you should get the option to configure you're controller.
When you've entered your controls and pressed a keyboard key to save, press F4 to exit emulationstation.
This will have written a file called es_input.cfg to ~/.emulationstation/
You can delete this file if you need to reconfigure your controller, or edit it to do it manually.

My es_input.cfg contains the following:

JOYNAME PLAYSTATION(R)3 Controller (00:24:33:62:62:5A)
BUTTON 10 10

(Note: If you are going to copy this file make sure you change the MAC address at the top. You can get your controllers MAC address using hciconfig after you've paired it.)

Now to configure RetroArch for the controller.

Run the following command:

retroarch-joyconfig >> ~/RetroPie/configs/all/retroarch.cfg

Configure your controls - this will append the configuration to the end of ~/RetroPie/configs/all/retroarch.cfg.

The end of my config file has the following:

input_player1_joypad_index = "0"
input_player1_a_btn = "13"
input_player1_b_btn = "14"
input_player1_x_btn = "12"
input_player1_y_btn = "15"
input_player1_l_btn = "10"
input_player1_r_btn = "11"
input_player1_l2_btn = "8"
input_player1_r2_btn = "9"
input_player1_l3_btn = "1"
input_player1_r3_btn = "2"
input_player1_start_btn = "3"
input_player1_select_btn = "0"
input_player1_left_btn = "7"
input_player1_up_btn = "4"
input_player1_right_btn = "5"
input_player1_down_btn = "6"
input_player1_l_x_plus_axis = "+0"
input_player1_l_y_plus_axis = "+1"
input_player1_l_x_minus_axis = "-0"
input_player1_l_y_minus_axis = "-1"
input_player1_r_x_plus_axis = "+2"
input_player1_r_y_plus_axis = "+3"
input_player1_r_x_minus_axis = "-2"
input_player1_r_x_minus_axis = "-3"
input_exit_emulator_btn = "16"

I added in the last line to exit the emulator using the PS button.

Now we're on the home stretch! We just need to add some roms in.
I copied mine from my PC with a USB pen.
The roms need to go in the following folder: /home/pi/RetroPie/roms
Each emulator has a separate folder. You can use startx if you find that easier to manage the files -but make sure you log out before running emulationstation.

Run emulationstation now and test some games out. All should be working fine!

Special thanks go to:
Florian - http://petrockblog.wordpress.com/retropie/
Themaister - http://themaister.net/retroarch.html
Aloshi - http://aloshi.com/emulationstation
falkTX - http://qtsixa.sourceforge.net/
Pabr - http://www.pabr.org/sixlinux/sixlinux.en.html
Stanislav Kopp - http://booting-rpi.blogspot.co.uk/

27 December 2012

First Steps

So my fiance got me a Raspberry Pi for Christmas!

I already had 2 projects in mind for when I got one.

  1. Media Streaming
  2. Retro gaming emulator
So I thought I'd start with the first and (most likely) easiest - creating a media center.

I've done a bit of research and decided to go for Raspbmc as everything is a straight forward process. Which is great for my first project.

So to start with I downloaded their handy installer for Windows (here).

When you launch it you get the following screen:

Since the SD card I'm using for this is an old one robbed out of a DSi XL, I ticked the SD card, accepted the license agreement and hit Restore device for formatting. Can't hurt right?

After it restored (wipes all partitions and leaves you the RAW partition), I reformatted to FAT32. Once that was done I just hit the Install button.

What this does is install a minimal OS to the card that when plugged into the Pi and turned on, automatically connects to the Raspbmc servers to download the full XBMC packages. It took around 20 minutes on my connection and once it was done everything was setup and ready to go.

So...how do I play my videos?

I have a NAS set up with a few movies and TV shows so just needed Raspbmc to see it.

After fumbling through the menus (never used XBMC before), I found where to add UPnP devices, pointed it at the NAS and it found all my videos. Sweet.

It plays all the HD content with no issue. But it does seem to have a couple of problems with some xvid files - namely the audio is way out of sync and the video seems to be playing at a slower rate. I'll work on this..

And finally to show off to the missus, I downloaded the XBMC remote app on my iPhone (which is fekkin' awesome btw!) and showed her how I can now control the TV with my phone. She promptly told me to get a life :(