Easy way to setup the controller buttons via GPIO

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

Re: Easy way to setup the controller buttons via GPIO

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

firestw152 wrote:
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
Congrats your buttons are now working! :)

the sudo 777 chmod fixed the file permission. since retrogame is not yet running, restarting the pi will run it or just start it by

Code: Select all

/usr/local/bin/retrogame &
When you re-installed RetroPie did you re-download this script? Coz i just updated the script earlier to fix the file permission issue.
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 8:12 pm

I redownloaded the script yesterday but I am guessing it was not the one with the fix. Thank you so much tho this tool is amazing.

Syntax_X
Posts: 11
Joined: Wed Jul 19, 2017 1:25 am
Has thanked: 2 times
Been thanked: 1 time

Re: Easy way to setup the controller buttons via GPIO

Post by Syntax_X » Wed Jul 19, 2017 1:34 am

Had a play with this today, a few issues I ran into

Tested on a Pi Zero with PWM audio on GPIO 18. With 18 disconnected the system runs fine, connected it will pause. If you boot with 18 connected it will hang on Emulation station loading screen.
I did manage to get output from GPIO 13 but with crazy stutter, almost like a rapid pause was being initiated. Regardless, it made me relaise how crappy PWM audio is, and for the $4 ill spend on a usb sound card the difference will be worth it. But I thought it worth a mention for those wanting to use PWM audio and this controller method.

Also for some reason some boots today did not start the script, I had to manually do it. not sure what was going on there.

With usb audio this method seems to work fine, yet to test across all emulators.

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

Re: Easy way to setup the controller buttons via GPIO

Post by tinkerBOY » Wed Jul 19, 2017 3:29 am

Syntax_X wrote:
Wed Jul 19, 2017 1:34 am
Had a play with this today, a few issues I ran into

Tested on a Pi Zero with PWM audio on GPIO 18. With 18 disconnected the system runs fine, connected it will pause. If you boot with 18 connected it will hang on Emulation station loading screen.
I did manage to get output from GPIO 13 but with crazy stutter, almost like a rapid pause was being initiated. Regardless, it made me relaise how crappy PWM audio is, and for the $4 ill spend on a usb sound card the difference will be worth it. But I thought it worth a mention for those wanting to use PWM audio and this controller method.

Also for some reason some boots today did not start the script, I had to manually do it. not sure what was going on there.

With usb audio this method seems to work fine, yet to test across all emulators.
Im also using pin18 for PWM Audio and this method for the buttons and everything is working fine. The quality of the PWM Audio on the Pi Zero is known to be noisy. But that can be remedied by adjusting the volume down and just map some buttons to control the volume via retroarch. I have not tested any usb sound card but already ordered some for my next build.

Also have two running program in the background listening for inputs on two gpio buttons for shutdown and a temperature checker. Everything works.

So hows the usb sound? Do you get any hiss or noise when you boot up or play?
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 » Wed Jul 19, 2017 4:17 pm

I too am having the same issue. GPIO 13 works with audio but it stutters like crazy. This is what my setup looks like except I am using GPIO 13. Maybe I will try the USB sound card too.

https://lh3.googleusercontent.com/momnB ... 84-h588-no

Syntax_X
Posts: 11
Joined: Wed Jul 19, 2017 1:25 am
Has thanked: 2 times
Been thanked: 1 time

Re: Easy way to setup the controller buttons via GPIO

Post by Syntax_X » Wed Jul 19, 2017 4:34 pm

I'm glad I'm not crazy and someone else had the issue, gpio 18 pauses the system, 13 stutter pauses it when connected to an amp. Multiple amps tried out, clean installs with only audio to confirm the gpio is functioning correctly.

The usb audio was soooooo much better, heres a link to 2 small, easily desoldered usb sound cards.

http://www.ebay.com.au/itm/5V-USB-Power ... 2749.l2648

http://www.ebay.com.au/itm/CM108-USB-Dr ... 2749.l2648

Combine one of those with one of these

http://www.ebay.com.au/itm/3-6mm-Mini-P ... 2749.l2649

And you have yourself a usb sound card, amp, speaker, volume knob, a spare small battery for some other project, will accept stereo and sum to mono or pass thru stereo to headphones and auto shut off the speaker.
These little rechargeable speakers also tend to have EQ and limiter tweaks to make the small speaker sound better than it normally would being driven directly from an amp.
All for under $9 AUD. This is the method I will use from now on.

I'm not very good with code and am fairly new to all this but half wrote up a shutdown + low battery script that runs off counters instead of switching off from breathing on it or shutting down whenever the Low battery light flickers.. I need help.
shutdown low battery 1.zip
(1.54 KiB) Downloaded 381 times
Last edited by Syntax_X on Wed Jul 19, 2017 5:06 pm, edited 3 times in total.

Syntax_X
Posts: 11
Joined: Wed Jul 19, 2017 1:25 am
Has thanked: 2 times
Been thanked: 1 time

Re: Easy way to setup the controller buttons via GPIO

Post by Syntax_X » Wed Jul 19, 2017 4:46 pm

I should add that last night I was playing some master system games and the frame skip was huge, was teleporting a few frames forward every couple of seconds. This was on a fresh install with the only extra process being this GPIO button one.
I have not encountered this problem before.

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 » Wed Jul 19, 2017 5:14 pm

I went ahead and ordered this one since it was 6 USD and had amazon prime.
https://smile.amazon.com/gp/product/B00 ... UTF8&psc=1

Can you link me to whatever it is that you followed to get the USB card working with the pi?

Syntax_X
Posts: 11
Joined: Wed Jul 19, 2017 1:25 am
Has thanked: 2 times
Been thanked: 1 time

Re: Easy way to setup the controller buttons via GPIO

Post by Syntax_X » Wed Jul 19, 2017 5:50 pm


Syntax_X
Posts: 11
Joined: Wed Jul 19, 2017 1:25 am
Has thanked: 2 times
Been thanked: 1 time

Re: Easy way to setup the controller buttons via GPIO

Post by Syntax_X » Wed Jul 19, 2017 5:51 pm

That sound card you linked should have very nice decoupling caps but its a pain in the butt to desolder and use.
The tiny traces lift and its near impossible to remove the usb header without damaging the board.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest