Jan 23, 2013

Setup PlayStation Joysticks on Raspberry Pi



My friends and I are big fans of KOF. We all know the latency between PC and USB converter of PS joysticks is too long to enjoy our fight. However, the PS joysticks to PC via parallel port is a nice choice for low latency. (It you want to know how the converter works, please refer another Chinese site : http://stevie.myweb.hinet.net/adaptor2.htm )

PlayStation joysticks converter via Parallel Port.

Although it's nice but my computer with parallel port is broken. Why don't we play NeoGeo or MAME on Raspberry Pi? Thus, there is a plan in my mind to turn Raspberry Pi as a console game platform to play many kind of emulators, and RetroPie is a such great project supports SNES, NES, GBA. GB, SEGA, and MAME. In this part, I only focus on how to modify the joysticks and won't mention how to setup an emulator.

I should have a set of very handful joysticks for my game platform. The legacy PlayStation joysticks via GPIO is the best choice because it got the benefits of 12 buttons and 4-axis analog control, and the most important one is with very lower latency via GPIO than USB. If you are a fighting gamer (KOF, Street Fighter) as us, you will know why the latency is such important.


So, let's start to modify the converter for RaspberryPi.

gamecon_gpio_rpi is the driver for NES, SNES, GameCube, and PS Joystick via GPIO, and it's included in RetroPie. In this instruction, you will see how to connect a PS joys to Raspberry Pi. If you need to know the pin descriptions of PS joy, this site gives you how PS joysticks work. The connection method is some different between rev 1.0 and rev 2.0 of RPi. My RPi is rev 2.0, so I summarized the pin table. 


I start to make a simple connector for the P1 of RPi and DB25-Male. Here are some materials I prepared and the connector that I finished:




After a little work, connect with PS joysticks, converters, and RPi together. Start to test it!!!!


Before playing games, use RetroPie-Setup to install the emulator platform and gamecon_gpio_rpi driver for joysticks. The detail instruction can be found here. (The driver should be compiled and installed separately without RetroPie installed, but I haven't tried that yet. :P).

If the kernel module of gamecon_gpio_rpi is built correctly, you can install the module by the command:
pi@raspberrypi ~ $ sudo modprobe gamecon_gpio_rpi map=0,0,0,0,7,7 psx_delay=14

The parameter "map=0,0,0,0,7,7" is indicated using Pad5&6 as both PlayStation joysticks.
The parameter "psx_delay=14" configures the access delay for psx pads to 14ms. The default is 10ms, but it doesn't work correctly. 14ms is more save for me. 
After modprobe, there should be two joystick devices in /dev/input/jsX. (X indicated 0 & 1.) Then use the command to test:
pi@raspberrypi ~ $ jstest /dev/input/js0 

Driver version is 2.1.0.
Joystick (PSX controller) has 6 axes (X, Y, Rx, Ry, Hat0X, Hat0Y)
and 12 buttons (BtnX, BtnY, BtnTL, BtnTR, BtnTR2, BtnSelect, BtnStart, BtnMode, BtnThumbL, BtnThumbR, ?, ?).
Testing ... (interrupt to exit)
Axes:  0:-32767  1:-32767  2:-32767  3:-32767  4:-32767  5:-32767 Buttons:  0:off  1:off  2:off  3:off  4:off  5:off  6:off  7:off  8:off  9:off 10:off 11:off 


If all buttons and axis work well, congratulation that the joysticks setup correctly on RPi!!

There will be another article soon to share how to setup the emulators on RPi.

15 comments:

Derek said...

Hi, what do I do if after jstest I press buttons but there are no responses? The analog light comes on after sudo modprobe... but I don't know what to do on the next step. Thanks, Derek

JakeTheGreat said...

Same here, I can't get my Raspberry Pi to respond to any buttons on my controller. I did jstest and it showed exactly what is shown above, but where do i go from there? Thanks, Jake

Marcus Klumpp said...

How did you wire ATT/Select? I am trying to wire the Playstation Controller Port to the Raspberry Pi. I got it running and working but I am a bit confused on PIN6 ATT/Select as this is not shared like the other pins. I tried to bridge it but on jstest both controllers work on js0 and js1.
I can't imagine how to do this as gamecon only points out one GPIO for ATT/Select.

Maybe you could point out how to solve it.

Thanks in advance

Scott Nelson said...

To wire the second controller, you need to bridge the ATT/Select pins and separate the data pins for the two controllers. In the PSX, the ATT/SEL pins are indeed separate for P1 and P2, and everything else is combined, including Data. The GPIO driver, however expects the ATT/SEL pins to be combined and the Data pins to be separate. Since I was using the original controller ports and PCB that meant that I had to cut the trace on the PCB connecting the Data pins for P1 and P2 so that I could run them separately. I then had to run a jumper between the ATT/SEL pins to combine them.

Mark Nethercot said...

I only have one psx pad wired in. The only buttons that do anything are start and select. That suggests something is wired up right? I set map to 0,0,0,0,7,0 and delay to 20.

Scott Nelson said...

Try installing the latest version of the driver:
https://www.raspberrypi.org/forums/viewtopic.php?p=870383#p870383

There are a lot of issue in the 1.0 version which I believe is still being shipped with RetroPie.

wget https://www.niksula.hut.fi/~mhiienka/Rpi/gamecon-gpio-rpi-dkms_1.2_all.deb
dpkg -i gamecon-gpio-rpi-dkms_1.2_all.deb

Mark Nethercot said...

I installed 1.2 already. I'm using a pi zero, which could be the issue as I'm not due it is supported yet.. The fact start and select work means it must be wired OK and talking as it has to get to byte 4 to decode them - though I'm wondering if it has the analogue/digital bit wrong..

Scott Nelson said...

I haven't used a Pi Zero, but from what I've read, it's basically the same as the Pi 1, hardware-wise, so, I doubt that would be the issue. Some of the issues that I had when setting mine up were with the ground wire (it had to be hooked up to the same ground as the Raspberry Pi for some reason), and with overclocking, causing the driver to crash. But I didn't have the same issues you're describing. I'd double check all of your connections, and try a different controller if you can. PS2 controllers seem to work better than PS1 for me, but I haven't tested the PS1 controllers on 1.2. When I did test my PS1 controller on 1.0, I had the exact opposite problem. Everything worked except Start and Select. So, maybe it just doesn't like your controller?

Scott Nelson said...

And if it turns out to be a problem with PS1 controllers, you might want to post on the thread I linked to above, which the driver maintainer appears to monitor.

Mark Nethercot said...

I've just taken the joystick apart (an old shadowblade which I decided was big enough to house all the raspberry pi boards etc.), all the buttons and the joystick are pressure sensitive - apart from the start/select.. All of the microswitches have digital pins as well so I'm considering wiring them directly to the gpio instead (though I'll need to do something about the stick as it is horrible (huge dead space in the middle)).. Annoyingly the joystick etc worked fine when I plugged it in via a usb adapter.

Alberto Prieto said...

Hi ! thanks for the guide.

This command:

pi@raspberrypi ~ $ sudo modprobe gamecon_gpio_rpi map=0,0,7,7,0,0 psx_delay=14

didnt' work for me on a raspberry pi 3 with retropie, you have to map like this instead:


pi@raspberrypi ~ $ sudo modprobe gamecon_gpio_rpi map=0,0,0,0,7,7 psx_delay=14

and then... everything worked just fine ;)

Marcel Bayard said...

Hi,

i rebuild my own pistation after your example. But the Controller doesn´t work well.
After losing a full weekend i don´t know what is the failure. But then a coincidence geht the solution:

In your Pin-Out-Table you written the GPIO-Ports for the Rev 2.0. Thats not correct. At the Rev 2.0 there´s no GPIO 0 & 1. But the Pins 3 & 5 you are used are not available on a Rev 2.0 Board. Your Plan will work on a Rev 1.0 if you set the gamecon-driver with 7,7,0,0,0,0.



m2_viktor said...

Hi,

My ps pad is work on jstest, and everything is all right, but buttons left, right, up, down(D-pad) is work as axes, and i don't can map their in epxe emulator. Please help me to remake axes to buttons.

P.S. sorry for my english, it is not my default language.

Rey Marc Plazo said...

hi there how do i configure gamecon_gpio_rpi properly it readed by my system but when I do to test it, it's not working at all currently using latest retroPie with R. Pi 2 Model B

Unknown said...

Hi! I used this guide to do this system, but doesn't work, the Analog-light just flashes, when I press it and Pi isn't recognizing the controller.