Lakka on Raspberry Pi 2 with Dualshock4 Wireless Controller

After my last blog post I’ve had a few people contact me about whether the Playstation 4 Dualshock controller can be used. I started to research this and found that a lot of people were using them with a USB cable but I could not find anyone using them via bluetooth in Lakka – only people using them with complicated connection methods for RetroPie.

However – after doing some research this morning I’ve managed to pair and configure a Dualshock 4 controller via bluetooth with Lakka and  a Raspberry Pi 2 – here’s how to do it:

Step 1:
SSH into the device using this command ssh root@IPADDRESS. The password you will need to connect is just root.

Step 2:
Start the program bluetoothctl

Step 3:
In bluetoothctl issue the following commands:
– discoverable on
– pairable on
– scan on

Step 4:
This is important, I had no idea of this as I don’t have a PS4 I simply borrowed the controller off a friend. To put the PS4 controller into Pair mode you need to press the Share button and the PS Home button together – the LED will then continuously flash indicating it is in pair mode

Step 5:
As with the Dualshock 3 instructions, watch the screen for device connection/announcement messages. It should say something like the message below

[NEW] Device D0:27:88:27:CB:CD D0-27-88-27-CB-CD

Once you see that, you can now use the connect command to connect and bind to the Mac address

connect MACADDRESSGOESHERE

After you issue this command, you will see a line that says Name: Wireless Controller – this name you need to write down, or screenshot/copy paste as we will need it later. See the screenshot below for what I am referring to.

Screen Shot 2016-02-13 at 8.00.55 AM

Dont forget to issue the trust MACADDRESS command after you have a successful connection.

You should now see the controller has a solid light indicating it is connected and paired.

If you are like me you probably thought, great this will be exactly like the DS3, Lakka will just figure this out and autoconfigure. Well – unforunately it doesn’t.

Fortunately… there is a way to make it work – and it really isn’t that difficult – if you’ve been able to do the commands above and have a basic understanding of linux commands you should be able to get this all to happen.

First of all…

Why does the controller not autoconfigure? This took me a little bit of reading and cycling through the directory structure of Lakka to understand – but here’s the why.

In the retroarch.cfg file (/storage/.config/retroarch/retroarch.cfg) there is a setting joypad_autoconfig_dir that tells retroarch where to look for files that autoconfigure a controller when you plug it in/connect the controller via bluetooth. Currently in that directory there is no file that will link up to your bluetooth connected DS4 – so as far as Lakka is concerned it has no idea what you’ve connected and therefore will not try to autoconfigure the controller. The default location for the joypad autoconfigure files is /tmp/joypads

Do you remember how earlier I said make sure you record the line Name: from bluetootchctl ? If you didn’t start from the beginning of this post again because if you don’t have that theres no point proceeding on to the next steps.

Special Notes

OpenELEC that Lakka is built on has certain parts of the file system that are deliberately completely unable to be written to. Unfortunately the default joypad folder happens to be one of these places. Luckily there is a simple way around this.

Step 1:

Hold down Share and the PS Home button until the controller turns itself off i.e. the LED light goes out

Then…

Download this file Sony-PlayStation4-DualShock4-Controller-Bluetooth

Step 2:

For the sake of simplicity all I did was copied that file to the joypad directory that you can access by browsing the Lakka network shares from another computer – I’d suggest doing it the same way

Step 3:

We need to edit retroarch.cfg – now to do this you first need to stop the retroarch service. Refer to http://www.lakka.tv/doc/Configuring-Lakka/ as to how to do this. Once you have stopped the service move on to step 4

Step 4:

Now the service is stopped we can edit the file:

nano /storage/.config/retroarch/retroarch.cfg

The line we want to edit currently reads:

joypad_autoconfig_dir = “/tmp/joypads”

Edit this line so it says this:

joypad_autoconfig_dir = “/storage/joypads”

**Tip – in nano to find a word press Ctrl + W then type in the word you are looking for and press enter

Once the line has been edited press Ctrl + x – nano will warn you changes have been made – type y to confirm the changes, press enter and the file will be saved.

Step 5:

Restart retroarch by typing:

systemctl start retroarch

Step 6:

You should be back on the main Lakka Screen (the orange coloured one) all you should need to do now is press the PS Home button once and the controller should pair again, and then you should see a message saying that it has autoconfigured and you can now use the controller. The controller should also show its status light as a solid colour.

Step 7 (Here if Step 6 didn’t get your controller working and some special notes):

If you need autoconfiguration of other controllers make sure you copy the relevant files from /tmp/joypads to /storage/joypads  – otherwise all you’ll be able to pair up or use is your DS4. For me I only have a DS3 and a DS4 paired so I just copied those files from the original directory.

If your controller still did not autoconfigure:

If you open up any of the autoconfigure files you will see the first line says:

input_device=”Some Controller Name”

Lakka uses that name to match up to the device you are using for autoconfigure. In my setup the controller when paired was simply called “Wireless Controller” (which is how the file your downloaded has been configured) – I’m not sure if this will be the same for everyone hence telling everyone to get this important detail from bluetoothctl.

If your controller does not autoconfigure make sure that you have edited the first line of the *.cfg file you downloaded earlier to match the name you got from bluetoothctl

For me the DS4 controller actually had force feedback whereas the DS3 did not so it was a nice extra feature. If your controller name was different if you could leave a comment to let me know what it is that would be great as we could pass that on to the Lakka development team so they can include these files in future releases.

I am using the following bluetooth adaptor (mentioned in my previous blog post is where to buy):

Bus 001 Device 004: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)

I am running this version of Lakka:

Linux Lakka 4.1.13 #1 SMP Tue Dec 22 09:40:55 CET 2015 armv7l GNU/Linux

Here is a video showing me using both the PS3 and PS4 controllers in game on my setup

Turn a Raspberry Pi 2 into a Retro Games Emulator

I recently bought 2 new Raspberry Pi 2’s for different projects. The first project was to make a Retro Game emulator using the Raspberry Pi 2 as I’d tried to do this previously on an Odroid C1 and a Raspberry Pi 1 but each had their own issues that made me look to the 2nd model Raspberry Pi.

To do this you will need the following:

– Raspberry Pi 2 (http://au.rs-online.com/web/p/processor-microcontroller-development-kits/8326274/) $48AUD
– Suitable MicroSD Card (8gb or Above) I used one of these (http://www.officeworks.com.au/shop/officeworks/p/sandisk-16gb-ultra-sdhc-memory-card-br190829) $14.95AUD
– Digitech USB2.0 Bluetooth® V4.0 Class 2 Dongle (http://www.jaycar.com.au/p/XC4956) $19.95AUD
– Sony Sixaxis Dualshock 3 controller mine was purchased from Playhard Gaming Greenhills $34.95
– Micro USB Cable (A-B  Type) – Did not purchase as I already had one
– Mini USB Cable (A-B  Type) – Did not purchase as I already had one
– 5VDC 2A USB Power Supply (Or use a 10W Apple one, or Intel Compute Stick Power Adaptor, or Samsung Note 3 Adaptor)
– A monitor/TV with a HDMI input

For me the total cost of this project ended up being $121.50AUD (if you include the RPI case) as everything else I had available so did not need to buy. If you needed to buy a power supply and the USB cables, the whole thing should still come in under $150.

Step 1 – Download the Raspberry Pi 2 Lakka.tv Image

CAUTION: Using the dd command listed in step 1 can have severe consequences if you use the wrong disk number, how severe you ask? Loss of all your data… so please read and understand before you use the command

You can obtain the Lakka image by going to here http://www.lakka.tv/get/linux/rpi2/ and downloading the file. Once it is downloaded on that site if you click next it will explain how to flash the image to your SD card. I’ve linked to the rpi2 page as they update the downloads frequently with bug fixes.

Once downloaded make sure you unpack the *.gz file, as we want just an *.img file for doing the image to SD card.

The next thing you will need to do is determine what disk number your SD card has. The instructions below are for OSX. If you are using windows you should follow these instructions: http://www.lakka.tv/get/windows/rpi2/install/

In terminal run the command diskutil list BEFORE you insert your SD Card. Then, insert your SD card and run the same command again. You should be able to compare the two results of the command and determine what disk number your SD card actually is.

Screen Shot 2016-01-31 at 4.01.09 pm

Once you know your SD cards disk number the commands to run are as follows:

Unmount the SD Card:

sudo diskutil unmountDisk /dev/diskX <—where X is the disk number

You should then see this

Unmount of all volumes on disk2 was successful

You can now image the sd card using the command below:

sudo dd if=pathtolakkafile of=/dev/diskX <—-where X is the disk number of the SD card

Then its best to leave the computer for a good while, because the dd command doesn’t actually give any progress indicators. It simply shows when it is completed. Below is a screenshot of me running each command above.

Screen Shot 2016-01-31 at 4.01.09 pm

Once the disk is imaged – the terminal will return to a standard prompt. At this point you can now eject the SD card using finder or run the diskutil unmountDisk /dev/diskX command again so that you can safely remove the card.

Note: if you read the top of the post you would of seen the caution message about using the dd command like this. If you get the disk number wrong dd will not stop and the command is not reversible it will write over the top of whatever disk you said to write to no questions asked – so please be ultra careful when using this command and make sure you are using the right disk number before pressing enter.

Step 2 – Booting up for the first time

Plug the MicroSD card into the Raspberry Pi 2, connect it to your HDMI screen, plug in the bluetooth USB dongle and connect the Pi to your network using an ethernet cable. When all of those things are connected it’s time to power up the device – so plug that USB cable into the Pi to fire it up.

If you watch the screen you will notice on first boot in the top left of the screen there will be information about the file system expanding, make sure you let the system go through this entire process then reboot. This basically is the system expanding the filesystem on the SD card to allow you to be able to use the full amount of storage space on the MicroSD card.

Once the system as rebooted you should first see the Lakka.tv logo then when fully booted you will see the orange Lakka.tv menu. If you’ve got this far thats great, your system is likely to work as expected!

Step 3 – Find the network address of your device if necessary

Lakka uses the avahi-daemon to allow network discovery via the name LAKKA however trying to connect to a device called LAKKA does not always work. If it does not I suggest reviewing your DHCP clients list on your network to determine what IP was given to the system – this is beyond the scope of this tutorial so I will not go into that process here (tweet me/DM me and I’ll explain it if you need it). You will need to do this so that you can complete the next step

Step 4 – Log into the device using SSH

To login to the device the command is as follows:

ssh root@lakka.local

if that does not work the command is:

ssh root@IPADDRESS e.g. ssh root@192.168.1.16

You will be asked for the password, the password is root.

Step 5 – Pair your Sony Playstation controller

At this step I assume you are already logged into the device by SSH – if you are you should now follow the instructions on pairing the controller here: http://www.lakka.tv/doc/Wireless-Dualshock/ 

Follow the instructions carefully, particularly the part about plugging the controller in by USB – if you don’t do this the controller will never pair.

A few things to note, for me the once I pressed the PS Home button the controller showed its MAC Address but I did not get a message to authorise the controller. If this happens, unplug the controller and press the PS Home button again and you should see the authorise message. Once you have seen that you can simply continue on with the rest of the commands. Make sure you add the local rules so that bluetooth stays on after a reboot.

Once the controller has been paired you should be able to move around in the Lakka menu simply using the controller – it will autoconfigure itself. Your controller should have the number 1 LED lit to show it is connected.

I’ve not tested adding a second controller but have been told that you basically follow the same process for controller number 2 – and the second controller will light the number 2 LED to show it is in fact, controller number 2.

Below is a screenshot of me going through this process, unfortunately my connection dropped during the SSH connection so theres a reconnection in there as well:

Screen Shot 2016-02-01 at 7.06.46 AM

Step 6 – Add your games to the system

Now that you’ve got your controller and everything else ready to go you just need to add games to the system. This part is quite simple, in Finder you should see a device called LAKKA – click on this then open the ROMS folder, you can now simply drag and drop your games into this folder from your computer. Remember LAKKA needs the files unzipped or it can not open them so make sure you unzip your roms before you copy them across.

Remember for certain consoles you will also need a BIOS file (e.g. Sony Playstation) the BIOS files need to be added to the System folder using the same method above to access the folder (click Lakka in Finder, then click the System folder and then drag and drop your BIOS files to it)

I found it was better to do small amount of data at a time instead of a large file transfer of everything at once.

Step 7 – Play!

I found the easiest way to get started was go to load content then press the circle button on the controller, you should then get a list of all the games you added in step six – highlight the one you want to play then press circle again and it should begin to load.

If you want to change games, simply press the PS Home button, then goto close content. In the LAKKA menu’s the circle button is select/next and the X button is go back.

Notes:

I’ve only tested Sega Master System, Nintendo 64 and Playstation one at this point. So far the only games that did not work well were Nintendo 64 – they were a little too laggy to play but everything else worked quite well. Below is a video of me testing PSX with the Sixaxis controller – works quite well!

Once you’ve loaded everything on to the Raspberry Pi you don’t really need network access to it any more so you should be able to safely move it to another device, or take it somewhere else to play.

 

 

Automating Downloading with a Raspberry Pi

I jumped on the bandwagon when the Pi was released as just about every other tech/nerd did as well.

After the long wait, when the unit finally arrived I was unsure of what to do with it – until a friend of mine introduced me to Sick Beard, Couch Potato and Sabnzbd Plus.

I had already set up my Pi to run Raspbmc for XBMC but found it was slow and I did not need it to be my media center as I already have 2 Apple TV’s running Firecore.

Being lazy, instead of reinstalling Raspbmc with another OS I decided to adjust it so I didnt have to take the SD card out of the Pi and could just use SSH to configure everything.

This isnt a full guide it is just a list of what to be aware of.

Booting – Raspbmc loads xbmc automatically on boot, it is loaded by a script in /etc/init.d, if you dont want xbmc to run on boot any more delete these scripts and it wont, i think it would be nearly impossible to run everything and xbmc so I would suggest deleting the init.d scripts for it

Performance – Raspbmc is set to have a significant ammount of ram used for the GPU, if you dont change this (like I did not to begin with) Sick Beard and SabNZBPlus will crash. To change these settings use:

sudo nano /boot/config.txt
change gpu_mem_256=256 to gpu_mem_256=64
change gpu_mem_512=512 to gpu_mem_512=128

Reboot and run free -m or run top and you will notice a significant increase in available RAM, enough for Sab and Sick Beard to run, I decided not to run couchpotato but it should be enough for it as well.

Directories – It is best to make a directory structure that is easy to mange, most people make an incoming folder for incoming downloaded then completed/category (e.g. TV) for completed downloads. Keeping this structure will make it easier for Sick Beard to scrape and easier to configure.

Storage – There are a few options for this, some people run USB hubs with Storage drives attached to the Pi. Most people I assume will be using Samba shares.

***You need to istall cifs-utils or mounting samba will not work, you will most likely need to edit /etc/apt/source.list to install packages from apt***

___________________________________________________________
These are the lines from my sources.list

deb http://archive.raspbian.org/raspbian wheezy main contrib non-free
deb http://ftp.de.debian.org/debian squeeze main contrib
deb-src http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi
——————————————————————————–

I made mount points for the samba shares I have, mapped them in fstab but then found that sab could not write even though from the command line I could make directories and files as the user sab ran as. I found that I needed to add the user uid to the fstab line and then writing worked fine. Here is an example:

//192.168.1.254/completed /mnt/completed cifs defaults,uid=1000

uid=1000 on my pi is the user that sab runs as, I suggest you use the uid that your sabnzbdplus install works under.

Once you edit fstab, instead of rebooting you can run sudo mount -a to reload fstab and it will tell you if there are any errors.

To check your mount points are owned by the right user run ls -al in the /mnt directory (if thats where you made your mount points, you should have made them there). The third column will show the user the share was mounted by, if this is not your sab user, you have your uid wrong in fstab.

I hope this helps the people that have had the same issues I have, I ended up reading through many different sites and brushing up on a lot of linux commands to get this all running so I thought brief explanations in one place would make it easier for other people attempting the same thing.