lunarkingdom
Posts: 127
Joined: Sun Jul 20, 2014 3:38 am

RetroPie With 1 or 2 GPIO Game Controllers Tutorial

Wed Jul 30, 2014 11:27 pm

Hello! Most of the credit to getting this working goes to DigitalLumberjack who did all the code to make the joysticks work, he has been working close with me the last 3 days and this is what we have come up with. The rest goes to PetRockBlog for all of the Retropie code as well as for the Retropie Image. As with all opes source I am sure a bazillion others helped get this to where it is today and I thank them as well. Follow THIS tutorial only, there are subtle changes to PetRockBlog's and DigitalLumberjack's pages to get the B+ running smoothly. First thing you are going to need to do is download the RetroPieImage_Ver2.3.img from here:

http://blog.petrockblock.com/download/r ... ect-image/

Burn this image to your microSD card then put it in your Raspberry Pi and fire it ip and proceed.

Credit for this first part goes to:


http://blog.petrockblock.com/2012/07/22 ... pberry-pi/

Follow THIS tutorial only, there are subtle changes to PetRockBlog's and DigitalLumberjack's pages to get the B+ running smoothly. The link is for credit and reference only.

First run the raspi-config script to extend your root file system.

sudo raspi-config

Credit for the next part goes to:

https://github.com/digitalLumberjack/mk ... ystick_rpi

Follow THIS tutorial only, there are subtle changes to PetRockBlog's and DigitalLumberjack's pages to get the B+ running smoothly. The link is for credit and reference only.

This part you can either configure your GPIO for 1 or 2 GPIO controllers (or mame cabinet controls), the GPIO pinout is as follows for B+ Pi, if you are only hooking up one joystick use the green only.

Image

Right click this image and select open link in new window to see large version

Installation Script

Download the installation script and install it:

mkdir mkjoystick
cd mkjoystick
wget https://github.com/digitalLumberjack/mk ... install.sh
sudo sh ./install.sh

Loading the driver

The driver is loaded with the modprobe command and take one parameter nammed "map" representing connected joysticks. When you will have to load the driver you must pass a list of parameters that represent the list of connected Joysticks. The first parameter will be the joystick mapped to /dev/input/js0, the second to js1 etc..

If you have connected a joystick on RPi GPIOs (joystick 1 on the pinout image) you must pass "map=1" as a parameter. If you are on B+ revision and you connected 2 joysticks you must pass map="1,2" as a parameter.

If you have one joystick connected on your RPi B or B+ version you will have to run the following command :


sudo modprobe mk_arcade_joystick_rpi map=1

If you have two joysticks connected on your RPi B+ version you will have to run the following command :

sudo modprobe mk_arcade_joystick_rpi map=1,2

The GPIO joystick 1 events will be reported to the file "/dev/input/js0" and the GPIO joystick 2 events will be reported to "/dev/input/js1"

Auto load at startup

Open /etc/modules :


sudo nano /etc/modules

And add the line you use to load the driver :

For single controller:

mk_arcade_joystick_rpi map=1

For dual controllers:

mk_arcade_joystick_rpi map=1,2

To exit and save hit control X then select Y and when it shows the file name "/etc/modules" hit enter.

Testing

Use the following commands to test joysticks 1 inputs :

jstest /dev/input/js0

Use the following commands to test joysticks 2 inputs :

jstest /dev/input/js1

To exit the test program use ctrl+c, do not cycle the power to get out of it.

Then reboot:


sudo reboot

Next part make sure you use correct caps on RetroArch name

cd /opt/retropie/emulators/RetroArch/installdir/bin
sudo ./retroarch-joyconfig -j 0 >> /opt/retropie/configs/all/retroarch.cfg

It will say:

found joypad driver: udev
using joypad: 2nd arcade GPIO controller B+
Joypads tend to have stale state after opened.
press some buttons and move some axis around to make sure joypad state is completely neutral before proceeding.
when done press enter…

Hit Enter and it will then say:

Configuring binds for player #1 for joypad #1
B button (down)

Then map your joystick and buttons BUT if there are more to do than your game pad has just use the last button over and over until it was done, after you are complete open the file you just wrote for editing like this:

sudo nano /opt/retropie/configs/all/retroarch.cfg

Copy and paste the entire section that begins with “input_player1_” and change it to “input_player2_”. Don’t forget to change the “input_player_joypad_index” to 0 or 1 as well. Make sure you add this to the end of your code so you can use start and select together to exit rom's:

input_enable_hotkey_btn = “4″
input_exit_emulator_btn = “5″

Once complete save by using control and x, then y for yes, then enter for filename (make sure you don't accidentally hit a key and mess it up) then do this and let it boot to emulationstation, load a rom and see if it works (it should), if there are any discrepancies please don't hesitate to let me know. I hope this helps some of you who are having trouble adding buttons via the GPIO, I do not know how to set up any other interface so please do not ask this is for digital inputs only (buttons and arcade joysticks).

pandadesh
Posts: 3
Joined: Thu Aug 14, 2014 11:54 am

Re: RetroPie With 1 or 2 GPIO Game Controllers Tutorial

Thu Aug 21, 2014 2:32 pm

i want to add more buttons to player 1. how will i do that? and what if i want to use a analog joystick?
the joystick is this https://www.adafruit.com/products/512
thanks in a advance

Vasilisrk
Posts: 1
Joined: Sat Sep 27, 2014 6:11 pm

Re: RetroPie With 1 or 2 GPIO Game Controllers Tutorial

Sat Sep 27, 2014 6:14 pm

Hi, thanks for the great tutorial.

I've done it all but I don't know what to do with that:

Copy and paste the entire section that begins with “input_player1_” and change it to “input_player2_”. Don’t forget to change the “input_player_joypad_index” to 0 or 1 as well....

P-Nut
Posts: 3
Joined: Mon Feb 09, 2015 8:58 pm

Re: RetroPie With 1 or 2 GPIO Game Controllers Tutorial

Thu Feb 19, 2015 10:26 pm

I get a error when I try and use 'sudo modprobe mk_arcade_joystick_rpi map=1,2

FATAL: Module mk_arcade_joystick_rpi not found....

I think when installing the problem occurs.
https://github.com/digitalLumberjack/mk ... install.sh
sudo sh ./install.sh

The install file references to links/packages that are no longer there....

Hopefully someone will help me out... its driving me nuts.

User avatar
DigitalLumberjack
Posts: 336
Joined: Thu May 22, 2014 8:55 am
Location: France
Contact: Website

Re: RetroPie With 1 or 2 GPIO Game Controllers Tutorial

Fri Feb 20, 2015 12:49 pm

There are new version since this tutorial.
https://github.com/digitalLumberjack/mk ... /releases/
You should change all 0.1.1 to 0.1.4 :)

P-Nut
Posts: 3
Joined: Mon Feb 09, 2015 8:58 pm

Re: RetroPie With 1 or 2 GPIO Game Controllers Tutorial

Sat Feb 21, 2015 12:49 am

Thanks for the reply.

I was able to do the new tutorial of 1.0.4.

* mkdir mkjoystick
cd mkjoystick
wget https://github.com/digitalLumberjack/mk ... install.sh

* sudo sh ./install.sh updatesystem
sudo reboot

* sudo sh ./install.sh

* sudo modprobe mk_arcade_joystick_rpi map=1,2

* sudo nano /etc/modules

* mk_arcade_joystick_rpi map=1,2 (got 2 player setup)

I then tested and all the inputs were registerd.

Most emulators work but I can't get pifba to respond to the controls... and I cant find anything that describes how to get it to work with the gpio/joystick setup. Could you please tell me how I can get pifba to work ;o

Greets Paul

KingRoyz
Posts: 16
Joined: Thu Mar 05, 2015 8:00 am

Re: RetroPie With 1 or 2 GPIO Game Controllers Tutorial

Thu Mar 05, 2015 8:16 am

Hello,
sorry for my bad English,
I'm making an arcade retrogame using scripts digitlLumberjack:
https://github.com/digitalLumberjack/mk ... 9ab30134a5

Because I would like to add 4 players, I installed the integrated MCP23017, I realized, that, but can not be activated and usable outputs GPB6, GPB7, GPA6 and GPB7. I want to use all of the outputs of this integrated, how do I activate them? Where is the file to edit the parameters of MCP23017?

Thanks

geoldr
Posts: 6
Joined: Fri Feb 20, 2015 7:24 pm

Re: RetroPie With 1 or 2 GPIO Game Controllers Tutorial

Fri Mar 13, 2015 11:32 pm

Hey all, I am on the latest retro Pie, and using the latest 0.1.4. When I run the install script, I eventually get a 'Error! Bad return status for module build on kernel: 3.18.9-v7+ (armv71).

And when I modprobe, it just gives the FATAL: module mk_arcade_joystick_rpi not found.

Any ideas?

peter2626
Posts: 1
Joined: Sat Mar 28, 2015 1:22 pm

Re: RetroPie With 1 or 2 GPIO Game Controllers Tutorial

Sat Mar 28, 2015 1:25 pm

Great work...Thanks so much
Has any one considered a tutorial video on this starting from a fresh install? Or does any one know if it exists. That would be excellent for noobs like me

thanks again for all the hard work

User avatar
Djinny
Posts: 122
Joined: Sat Jul 05, 2014 12:21 am
Contact: Website

Re: RetroPie With 1 or 2 GPIO Game Controllers Tutorial

Wed Apr 22, 2015 4:51 pm

How do i reconfigure the buttons and such?
I'm going to need 14 buttons + analog sticks using a 12bit ADC.

ABC/XYZ/Start/Select/Dpad4/Ltrigger/Rtrigger + two 12bit analog channels.
I know it's a lot but if i want compatibility with more emulators, i need a lot of buttons. n64 for example.
My RPi needs a fan, heat will leech into the battery, so people saying I don't need a fan, don't understand how Li-Po batteries are affected by high temps. Cool pi = cool battery.
I would very much so like to see a Pi2/Pi3 Zero, power and size.

Barnuk
Posts: 1
Joined: Thu May 14, 2015 9:09 am

Re: RetroPie With 1 or 2 GPIO Game Controllers Tutorial

Thu May 14, 2015 9:14 am

Hi, firstly - thanks for the work you've put in on this and the tutorial. I am however struggling to get the second controller (GPIO controller 2). To be recognised in any emulator other than MAME. The jstest works perfectly for both js0 and js1 but I just cannot get proper function in games elsewhere.

I have manually created a GPIOcontroller2.cfg to see if that helped but it didn't.

I wonder if maybe I'm just listing the code wrong in the retroarch.cfg (all configs) file. What should it look like (could you share yours please?)

Regards
Neil

ivwshane
Posts: 3
Joined: Wed May 27, 2015 5:46 am

Re: RetroPie With 1 or 2 GPIO Game Controllers Tutorial

Fri Jun 19, 2015 7:10 am

Can this be done with recalbox?

Also, is there a similar graphic for the pin out for the raspberry pi 2?

User avatar
DougieLawson
Posts: 29790
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: RetroPie With 1 or 2 GPIO Game Controllers Tutorial

Fri Jun 19, 2015 8:42 am

ivwshane wrote: Also, is there a similar graphic for the pin out for the raspberry pi 2?
http://pi.gadgetoid.com/pinout
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

ivwshane
Posts: 3
Joined: Wed May 27, 2015 5:46 am

Re: RetroPie With 1 or 2 GPIO Game Controllers Tutorial

Fri Jun 19, 2015 9:01 am

Thanks, I just realized the gpio on the b+ and rpi2 are the same:o

r1racing
Posts: 1
Joined: Tue Dec 15, 2015 10:47 pm

Re: RetroPie With 1 or 2 GPIO Game Controllers Tutorial

Tue Dec 15, 2015 11:00 pm

Help!!!
I know this is old, but I cant make this work...
I follow all the steps, the buttons are workin ok on the test, BUT nothing happens on any emulator...

I have the raspberry pi 2, model B, 2 joysticks and 8 buttons each player.. but I have to use the keyboard..

any clue what can I do???

thrylax
Posts: 2
Joined: Sun Jun 19, 2016 3:54 pm

Re: RetroPie With 1 or 2 GPIO Game Controllers Tutorial

Sun Jun 19, 2016 4:02 pm

Hi. Thanks for the great script by the way. Its EXACTLY what I was looking for.
I just have some issues I hope someone can help me with.
I had gotten this to work perfectly on my Raspberry Pi 3 running RetroPie v3.6, however, I recently tried to update to RetroPie v3.8.1 and when I run the script it seems to work fine, but whenever I try to start the script with sudo modprobe mk_arcade_joystick_rpi map=1,2 I get the following error.
modprobe: FATAL: Module mk_arcade_joystick_rpi not found.
I followed the tutorial exactly and even made sure to update with sudo sh ./install.sh updatesystem as well as performed a reboot before installing with sudo sh ./install.sh.
I have tried to perform this install twice and both times I still get modprobe: FATAL: Module mk_arcade_joystick_rpi not found.
Any help on solving this would be greatly appeciated. Thanks.

thrylax
Posts: 2
Joined: Sun Jun 19, 2016 3:54 pm

Re: RetroPie With 1 or 2 GPIO Game Controllers Tutorial

Sun Jun 19, 2016 9:34 pm

Nevermind. After an extensive search though the forums I managed to find this......https://github.com/recalbox/mk_arcade_j ... /issues/32
Which explains the issue as well as resolves it, at least for me on my Raspberry Pi 3 running RetroPie v3.8.1.
Basically what it says is that you need to do a manual install for the GPIO Joystick drivers. Heres a synopsis.

Code: Select all

sudo apt-get update
sudo apt-get upgrade
sudo rpi-update

Code: Select all

sudo apt-get install -y --force-yes dkms cpp-4.7 gcc-4.7 git joystick
sudo apt-get install raspberrypi-kernel-headers

Code: Select all

wget https://github.com/digitalLumberjack/mk_arcade_joystick_rpi/releases/download/v0.1.4/mk-arcade-joystick-rpi-0.1.4.deb
sudo dpkg -i mk-arcade-joystick-rpi-0.1.4.deb
Start the Driver

Code: Select all

sudo modprobe mk_arcade_joystick_rpi map=1,2
Opens modules with nano editor for editing.

Code: Select all

sudo nano /etc/modules
Add the following line to the now open file “mk_arcade_joystick_rpi” without quotes.
Save the file with CTRL+O press ENTER to save and then CTRL+X to exit.

Code: Select all

sudo nano /etc/modprobe.d/mk_arcade_joystick.conf
Add the following line to the file "options mk_arcade_joystick_rpi map=1,2".
Save the file with CTRL+O press ENTER to save and then CTRL+X to exit.

Reboot System
Done.

candyasdf
Posts: 1
Joined: Thu Mar 09, 2017 5:11 pm

Re: RetroPie With 1 or 2 GPIO Game Controllers Tutorial

Thu Mar 09, 2017 7:50 pm

hi all,
for my case, my modprobe.d conf file named in: "mk_arcade_joystick_rpi.conf"
after edit this, my 2p controller live again. thanks god.
take an hour to figure it out ;).

sicboy101
Posts: 1
Joined: Sun Oct 01, 2017 1:10 pm

Re: RetroPie With 1 or 2 GPIO Game Controllers Tutorial

Sun Oct 01, 2017 1:14 pm

candyasdf wrote:
Thu Mar 09, 2017 7:50 pm
hi all,
for my case, my modprobe.d conf file named in: "mk_arcade_joystick_rpi.conf"
after edit this, my 2p controller live again. thanks god.
take an hour to figure it out ;).
can you be more specific
i'm still get stuck

Thank You

balanceistische
Posts: 1
Joined: Thu Jul 13, 2017 12:09 am

Re: RetroPie With 1 or 2 GPIO Game Controllers Tutorial

Mon Oct 02, 2017 9:15 pm

candyasdf wrote:
Thu Mar 09, 2017 7:50 pm
hi all,
for my case, my modprobe.d conf file named in: "mk_arcade_joystick_rpi.conf"
after edit this, my 2p controller live again. thanks god.
take an hour to figure it out ;).
Well, you solved it.

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 14 guests