Monday, October 31, 2016

The first nightmare! (Controllers)

So, I'm not starving, but I'm also hoping to make this cost more like a weekend activity than a Christmas. Looking for controllers online that had decent reviews, I decided to go with some knockoff PS3 wireless controllers from a company called NewBull. They were only $10 each which was about as cheap as any I could find with more than 3 stars on Amazon. I think because the PS3 is an older high volume device there are lots of these knock-off controllers that they are basically trying to get rid of, whereas a dedicated bluetooth controller for PC or android is still valuable and costs a bit more even for poor quality ones.

The controllers came and I charged them up. They seem like pretty decent build quality, not too flimsy or cheap feeling buttons (keep in mind though that I haven't held a real PS-any-number controller for probably 15 years). That evening I excitedly plugged them into my work laptop which will be the test platform for a while until I have another machine to dedicate to the task. This has the side benefit that the kids CAN'T play without me. We can ease into it, only playing every couple weeks or so when I bring the laptop home.

Well I plug them into the laptop running Ubuntu 16.04 and suddenly they start vibrating. And basically I was able to check that it was working and sending button messages using the tool jstest-gtk which identified it as a "Shanwan PS3 Controller" or something. Long story short, I never got it to stop buzzing while plugged in.

Luckily it has bluetooth support so I didn't really plan to use it plugged in anyway. Unluckily, ubuntu's bluez package only supports official PS3 controllers which cost some 4x as much. It sees the devices, tries to connect but each time it tries to set up the connection to the controller it fails and you are left there with blinking leds until the controller times out.

There are tons of threads from 2012 or older that describe how to connect your sixaxis" PS3 controller to ubuntu, but I figured none of them applied. But after much frustration and seeing a few posts suggesting only official controllers are currently supported, I decided to give the alternative method a try. Its called qtsixa.

It was actually developed by a friend of mine who is a very active member of the linux audio community back in 2009 (before I knew him), but he has since become way to busy to support this project. In true open source fashion, there are 34 forks of it on github. Selecting which fork to try took some careful reading but it seemed the one including the most patches since falktx stopped maintaining the original (most importantly the patch to support Shanwan knock-offs) was by free5ty1e which was a fork for a special playstation emulator distribution it looks like.

Once I'd cloned it (just download it if you aren't git savvy) I actually edited the makefile to only install sixad and sixad-tools, since I'm kind of a command line guy anyway. If you want more guidance on how to build from source, I'm sure this won't be the last thing I build from source for this project. Such skills will help if trying to make a similar system, and they're not too hard. Usually you only need to know the commands "cd" "make" sudo make install." Leave a comment asking for help/details if you want them, otherwise, I'll assume your google-fu gets you through.

Anyway, once sixad was installed I just run the command "sixad --start" then push the PS3 middle button on the controller, and it blinks, vibrates happily, and shows which controller number it shows up as (1-4). I also found that with sixad running you can push the PS3 button with the controller plugged in and it stops the vibrating.

So, the first nightmare was trying to avoid any unofficial programs to connect to the controllers. Once I embraced installing qtsixa, it was super easy. Turns out that its still the best way (for fake controllers at least) even in 2016. Oh well. That's over. Or so I thought...

I first bought 2 controllers, and once they were working ordered 2 more. They are labelled the same, feel the same, came from the same seller, but they are not the same. I could not get them to pair the same way as the first two!

First thing I saw was that unlike the first two controllers, these new controllers did not appear in the devices list of the bluetooth wizard. I tried resetting the controllers with the pinhole button on the back, but no combination of button presses seemed to change anything. If you can't access ubuntu's bluetooth tools, you might need to restart your computer if you've already run sixad, since it seems to clobber them, but check to see if the controllers appear.

I tried a whole bunch of things and eventually got them to work. I'll describe the process I took, but possibly some of these steps are unnecessary.

If not first connect the controller with usb to your computer and run the command "sudo sixpair" which is a program with the sixad-tools and does something that makes the controller suddenly visible to your machine's bluetooth. Now when you run the bluetooth-wizard or the "add device" option in the blueman-applet you'll see a new "PLAYSTATION3(R) Controller" but you still can't pair it. But once its visible there, sixad can pair to it and it will work the same as the other controllers. I wish I knew why they were different, but I've got it working now.

Best of luck, hope you can avoid some nightmares.