Easy way to setup the controller buttons via GPIO

Various user-contributed guides for software-related things
User avatar
tinkerBOY
Posts: 702
Joined: Tue May 30, 2017 4:00 am
Has thanked: 294 times
Been thanked: 200 times

Easy way to setup the controller buttons via GPIO

Post by tinkerBOY » Sat Jul 08, 2017 12:46 am

Updated: 12/2612017 - included Method 2 (RetroPie image with built-in GPIO support)

I just recently completed my first GBZ build using the GPIO pins for the controller buttons which i think is very easy to setup than the usual Teensy.

I made a simple script to automate the task of setting up the Adafruit Retrogame utility software on a Raspberry Pi Zero assuming you've already installed RetroPie on your sdcard.
GPIO Soldering RequirementsShow

GPIO04 - 'UP' button
GPIO07 - 'DOWN' button
GPIO27 - 'LEFT' button
GPIO22 - 'RIGHT' button
GPIO05 - 'A' button
GPIO06 - 'B' button
GPIO13 - 'X' button
GPIO26 - 'Y' button
GPIO23 - 'ENTER' button
GPIO12 - 'SELECT' button
GPIO16 - 'LEFT Shoulder' button
GPIO20 - 'RIGHT Shoulder' button

GROUND - Connect to any ground pin

You can check all the corresponding GPIO pin number at https://pinout.xyz/

If you have different GPIO pin assigments then you can edit the file retrogame.cfg to suit your needs.
Method 1
  1. Download file.
    retrogame.zip
    (22.95 KiB) Downloaded 762 times
  2. Use 7zip or any zip program to extract the file and copy the "Adafruit-Retrogame" folder into your RetroPie sdcard on "/home/pi". Edit the file retrogame.cfg if you soldered to the GPIO pins differently.
  3. Edit the file "/etc/rc.local" and add the following before the line "exit 0" and save.

    Code: Select all

    sudo bash /home/pi/Adafruit-Retrogame/Setup-Retrogame.sh
  4. Now power on your Pi Zero with the RetroPie sdcard in. It should automatically reboot once and you're good to go.
Let me know if this method works for you. 😉😃

Tested on RetroPie 4.1, 4.2, and 4.3.

Method 2
Just download a RetroPie image with pre-installed Adafruit Retrogame utility.
Last edited by tinkerBOY on Thu Jan 25, 2018 6:07 pm, edited 8 times in total.
New! tinkerBOY PowerSwitch v1.0 with Safe Shutdown
Game Boy Zero Controllers available @ tinkerBOY.xyz * Support
tinkerBOY Controller v3.0 - built-in usb controller, usb audio, and usb hub
tinkerBOY Controller v2.0 - GPIO buttons and builtin PWM Audio and Amplifier
tinkerBOY Controller v1.1 - simple pcb button
* DPI Adapter - better display for GBZ
* keyboard converters - IBM XT/AT Soarer's Converter | ADB to USB Converter

User avatar
firestw152
Posts: 79
Joined: Mon Mar 06, 2017 5:14 pm
Has thanked: 22 times
Been thanked: 3 times

Re: Easy way to setup the controller buttons via GPIO

Post by firestw152 » Mon Jul 17, 2017 12:31 am

This is not working for me :( I am using the Raspberry pi zero W with retropi 4.2 and I am using winscp to edit and trasnfer the retrogame files. Am I doing something wrong or is the pi zero W not supported with your tool? I have been trying to get my GPIO buttons to work all weekend and I have made no progress. They only work in recalbox but I want to use retropi.

User avatar
tinkerBOY
Posts: 702
Joined: Tue May 30, 2017 4:00 am
Has thanked: 294 times
Been thanked: 200 times

Re: Easy way to setup the controller buttons via GPIO

Post by tinkerBOY » Mon Jul 17, 2017 12:54 am

firestw152 wrote:
Mon Jul 17, 2017 12:31 am
This is not working for me :( I am using the Raspberry pi zero W with retropi 4.2 and I am using winscp to edit and trasnfer the retrogame files. Am I doing something wrong or is the pi zero W not supported with your tool? I have been trying to get my GPIO buttons to work all weekend and I have made no progress. They only work in recalbox but I want to use retropi.
Did your pi reboot automatically once?

Tested on pi zero and pi zero w with 4.1 or 4.2 retropie image. What do you mean by not working? Im assuming youre using gpio pins and not the teensy?

Here's how you test the buttons if the Adafruit Retrogame utility is installed correctly and running. Assuming also buttons are connected to the gpio pins.

Run the command on you pi zero via ssh:

Code: Select all

/usr/local/bin/retrogame
If it runs then you installed it correctly. Now try to test your buttons. Press each button. You should get a response from the retrogame program. That means its working. Now reboot and re-configure your buttons on emulationstation.

If not then paste your log file(/dev/shm/runcommand.log) here.
New! tinkerBOY PowerSwitch v1.0 with Safe Shutdown
Game Boy Zero Controllers available @ tinkerBOY.xyz * Support
tinkerBOY Controller v3.0 - built-in usb controller, usb audio, and usb hub
tinkerBOY Controller v2.0 - GPIO buttons and builtin PWM Audio and Amplifier
tinkerBOY Controller v1.1 - simple pcb button
* DPI Adapter - better display for GBZ
* keyboard converters - IBM XT/AT Soarer's Converter | ADB to USB Converter

User avatar
firestw152
Posts: 79
Joined: Mon Mar 06, 2017 5:14 pm
Has thanked: 22 times
Been thanked: 3 times

Re: Easy way to setup the controller buttons via GPIO

Post by firestw152 » Mon Jul 17, 2017 2:04 am

zeroboy wrote:
Mon Jul 17, 2017 12:54 am
firestw152 wrote:
Mon Jul 17, 2017 12:31 am
This is not working for me :( I am using the Raspberry pi zero W with retropi 4.2 and I am using winscp to edit and trasnfer the retrogame files. Am I doing something wrong or is the pi zero W not supported with your tool? I have been trying to get my GPIO buttons to work all weekend and I have made no progress. They only work in recalbox but I want to use retropi.
Did your pi reboot automatically once?

Tested on pi zero and pi zero w with 4.1 or 4.2 retropie image. What do you mean by not working? Im assuming youre using gpio pins and not the teensy?

Here's how you test the buttons if the Adafruit Retrogame utility is installed correctly and running. Assuming also buttons are connected to the gpio pins.

Run the command on you pi zero via ssh:

Code: Select all

/usr/local/bin/retrogame
If it runs then you installed it correctly. Now try to test your buttons. Press each button. You should get a response from the retrogame program. That means its working. Now reboot and re-configure your buttons on emulationstation.

If not then paste your log file(/dev/shm/runcommand.log) here.
Yes the Pi rebooted once and yes I am using GPIO soldered like this picture because I attempted to use recalbox first and did not feel like re soldering everything.

I also have GPIO 13 connected to a speaker. Thanks for the tips and I will update as soon as I try what you recommended. Oh and I also already have my keyboard mapped as my default controller if that has anything to do with my problem. I installed retropi and before it let me do anything it told me to set up a controller so I used my keyboard so I could connect to wifi.

Do I need to delete my keyboard for the gpio buttons to work or something? I also can't get the buttons working with the regular adafruit retrogame no matter how many times I tried so I am hoping your thing works.

User avatar
tinkerBOY
Posts: 702
Joined: Tue May 30, 2017 4:00 am
Has thanked: 294 times
Been thanked: 200 times

Re: Easy way to setup the controller buttons via GPIO

Post by tinkerBOY » Mon Jul 17, 2017 2:13 am

You don't have to delete your old keyboard settings. If you used gpio13 for the speaker then the x button for this guide wont work. You can edit the file /boot/retrogame.cfg to suit your needs.

if you said it rebooted once then probably it copied all the files needed but maybe just a file permission issue.

Try

Code: Select all

sudo chmod 777 /usr/local/bin/retrogame
reboot
New! tinkerBOY PowerSwitch v1.0 with Safe Shutdown
Game Boy Zero Controllers available @ tinkerBOY.xyz * Support
tinkerBOY Controller v3.0 - built-in usb controller, usb audio, and usb hub
tinkerBOY Controller v2.0 - GPIO buttons and builtin PWM Audio and Amplifier
tinkerBOY Controller v1.1 - simple pcb button
* DPI Adapter - better display for GBZ
* keyboard converters - IBM XT/AT Soarer's Converter | ADB to USB Converter

User avatar
firestw152
Posts: 79
Joined: Mon Mar 06, 2017 5:14 pm
Has thanked: 22 times
Been thanked: 3 times

Re: Easy way to setup the controller buttons via GPIO

Post by firestw152 » Mon Jul 17, 2017 7:04 pm

So I tried re-installing again even with a fresh install of retropie 4.2 on my zero W and nothing the buttons are not working.

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi

/usr/local/bin/retrogame &
exit 0


I think the program works up to this point because it changed to that from sudo bash /home/pi/Adafruit-Retrogame/Setup-Retrogame.sh

I also used WinSCP to check the folders and /usr/local/bin/retrogame and the retrogame file is in there. I also went to /dev/shm/runcommand.log and nothing was in there.

Also when I run the command /usr/local/bin/retrogame it says permission denied and when I do sudo /usr/local/bin/retrogame it says :Command not found.


What could I be doing wrong? The only think I am changing are the gpio pins for ABXY and I am following the instructions as they are written.

When I ran sudo chmod 777 /usr/local/bin/retrogame Nothing happened. It just made a new line.
Last edited by firestw152 on Mon Jul 17, 2017 7:08 pm, edited 1 time in total.

User avatar
tinkerBOY
Posts: 702
Joined: Tue May 30, 2017 4:00 am
Has thanked: 294 times
Been thanked: 200 times

Re: Easy way to setup the controller buttons via GPIO

Post by tinkerBOY » Mon Jul 17, 2017 7:08 pm

if you get a "permission denied" try this one and it should work:

Code: Select all

sudo chmod 777 /usr/local/bin/retrogame
New! tinkerBOY PowerSwitch v1.0 with Safe Shutdown
Game Boy Zero Controllers available @ tinkerBOY.xyz * Support
tinkerBOY Controller v3.0 - built-in usb controller, usb audio, and usb hub
tinkerBOY Controller v2.0 - GPIO buttons and builtin PWM Audio and Amplifier
tinkerBOY Controller v1.1 - simple pcb button
* DPI Adapter - better display for GBZ
* keyboard converters - IBM XT/AT Soarer's Converter | ADB to USB Converter

User avatar
firestw152
Posts: 79
Joined: Mon Mar 06, 2017 5:14 pm
Has thanked: 22 times
Been thanked: 3 times

Re: Easy way to setup the controller buttons via GPIO

Post by firestw152 » Mon Jul 17, 2017 7:10 pm

Oh sorry I forgot to mention that when I did sudo chmod 777 /usr/local/bin/retrogame nothing happened it just made a new line.

root@retropie:~# sudo chmod 777 /usr/local/bin/retrogame
root@retropie:~#

and after that nothing happened my buttons still didnt work. and they should I tested them with a multi meter and they show resistance when pressed.

User avatar
tinkerBOY
Posts: 702
Joined: Tue May 30, 2017 4:00 am
Has thanked: 294 times
Been thanked: 200 times

Re: Easy way to setup the controller buttons via GPIO

Post by tinkerBOY » Mon Jul 17, 2017 7:13 pm

firestw152 wrote:
Mon Jul 17, 2017 7:10 pm
Oh sorry I forgot to mention that when I did sudo chmod 777 /usr/local/bin/retrogame nothing happened it just made a new line.

root@retropie:~# sudo chmod 777 /usr/local/bin/retrogame
root@retropie:~#

and after that nothing happened my buttons still didnt work. and they should I tested them with a multi meter and they show resistance when pressed.
after you've done

Code: Select all

sudo chmod 777 /usr/local/bin/retrogame
reboot. or you can just run the program.

Code: Select all

/usr/local/bin/retrogame &
New! tinkerBOY PowerSwitch v1.0 with Safe Shutdown
Game Boy Zero Controllers available @ tinkerBOY.xyz * Support
tinkerBOY Controller v3.0 - built-in usb controller, usb audio, and usb hub
tinkerBOY Controller v2.0 - GPIO buttons and builtin PWM Audio and Amplifier
tinkerBOY Controller v1.1 - simple pcb button
* DPI Adapter - better display for GBZ
* keyboard converters - IBM XT/AT Soarer's Converter | ADB to USB Converter

User avatar
firestw152
Posts: 79
Joined: Mon Mar 06, 2017 5:14 pm
Has thanked: 22 times
Been thanked: 3 times

Re: Easy way to setup the controller buttons via GPIO

Post by firestw152 » Mon Jul 17, 2017 7:14 pm

Ok so something weird just happened. I ran the command /usr/local/bin/retrogame again and it worked.
I have no idea what changed or what happened.



[1] Exit 126 /usr/local/bin/retrogame
root@retropie:~# sudo: /usr/local/bin/retrogame: command not found

[2]+ Exit 1 sudo /usr/local/bin/retrogame
root@retropie:~# /dev/shm/runcommand.log
-bash: /dev/shm/runcommand.log: No such file or directory
root@retropie:~# /usr/local/bin/retrogame
-bash: /usr/local/bin/retrogame: Permission denied
root@retropie:~# sudo /usr/local/bin/retrogame
sudo: /usr/local/bin/retrogame: command not found
root@retropie:~# sudo chmod 777 /usr/local/bin/retrogame
root@retropie:~#
login as: root
root@RETROPIE's password:

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Tue Jul 18 00:54:03 2017 from desktop-anij3v8
root@retropie:~# clear
root@retropie:~# /usr/local/bin/retrogame
retrogame: Config file is '/boot/retrogame.cfg'
retrogame: Board is single-core
retrogame: Loading config
retrogame: virtual key 103 assigned to GPIO04
retrogame: virtual key 108 assigned to GPIO17
retrogame: virtual key 105 assigned to GPIO27
retrogame: virtual key 106 assigned to GPIO22
retrogame: virtual key 30 assigned to GPIO24
retrogame: virtual key 48 assigned to GPIO25
retrogame: virtual key 45 assigned to GPIO15
retrogame: virtual key 21 assigned to GPIO18
retrogame: virtual key 28 assigned to GPIO10
retrogame: virtual key 57 assigned to GPIO09
retrogame: virtual key 38 assigned to GPIO14
retrogame: virtual key 19 assigned to GPIO23
retrogame: debug level 99
retrogame: uidev init OK
retrogame: SDL2 init OK
retrogame: Entering main loop
retrogame: GPIO25 key press code 48
retrogame: GPIO18 key press code 21
retrogame: GPIO18 key release code 21
retrogame: GPIO25 key release code 48
retrogame: GPIO25 key press code 48
retrogame: GPIO25 key release code 48
retrogame: GPIO25 key press code 48
retrogame: GPIO25 key release code 48
retrogame: GPIO25 key press code 48
retrogame: GPIO25 key release code 48
retrogame: GPIO25 key press code 48
retrogame: GPIO25 key release code 48
retrogame: GPIO25 key press code 48
retrogame: GPIO25 key release code 48
retrogame: GPIO24 key press code 30
retrogame: GPIO24 key release code 30
retrogame: GPIO24 key press code 30
retrogame: GPIO24 key release code 30
retrogame: GPIO24 key press code 30
retrogame: GPIO24 key release code 30
retrogame: GPIO22 key press code 106
retrogame: GPIO17 key press code 108
retrogame: GPIO17 key release code 108
retrogame: GPIO22 key release code 106
retrogame: GPIO17 key press code 108
retrogame: GPIO17 key release code 108
retrogame: GPIO17 key press code 108
retrogame: GPIO17 key release code 108
retrogame: GPIO22 key press code 106
retrogame: GPIO17 key press code 108
retrogame: GPIO17 key release code 108
retrogame: GPIO22 key release code 106
retrogame: GPIO22 key press code 106
retrogame: GPIO22 key release code 106
retrogame: GPIO04 key press code 103
retrogame: GPIO04 key release code 103
retrogame: GPIO17 key press code 108
retrogame: GPIO17 key release code 108
retrogame: GPIO09 key press code 57
retrogame: GPIO09 key release code 57
retrogame: GPIO10 key press code 28
retrogame: GPIO10 key release code 28
retrogame: GPIO25 key press code 48
retrogame: GPIO25 key release code 48
retrogame: GPIO24 key press code 30
retrogame: GPIO24 key release code 30
retrogame: GPIO25 key press code 48
retrogame: GPIO25 key release code 48
retrogame: GPIO18 key press code 21
retrogame: GPIO18 key release code 21
retrogame: GPIO15 key press code 45
retrogame: GPIO15 key release code 45
retrogame: GPIO10 key press code 28
retrogame: GPIO10 key release code 28
retrogame: GPIO17 key press code 108
retrogame: GPIO27 key press code 105
retrogame: GPIO17 key release code 108
retrogame: GPIO27 key release code 105
retrogame: GPIO17 key press code 108
retrogame: GPIO17 key release code 108
retrogame: GPIO17 key press code 108
retrogame: GPIO27 key press code 105
retrogame: GPIO17 key release code 108
retrogame: GPIO27 key release code 105
retrogame: GPIO17 key press code 108
retrogame: GPIO27 key press code 105
retrogame: GPIO17 key release code 108
retrogame: GPIO27 key release code 105
retrogame: GPIO17 key press code 108
retrogame: GPIO17 key release code 108
retrogame: GPIO17 key press code 108
retrogame: GPIO27 key press code 105
retrogame: GPIO17 key release code 108
retrogame: GPIO27 key release code 105

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest