Homepage › Forums › RetroPie Project › Everything else related to the RetroPie Project › emulationstation 2 gpio input problem
- This topic has 39 replies, 4 voices, and was last updated 9 years, 8 months ago by deepdivered.
-
AuthorPosts
-
07/09/2014 at 20:22 #13648francesconumaParticipant
Hi all,
I use adafruit script retrogame.c to map gpio pins to emulate keyboard. It seems that raspbian (retropie image 2.2 from emulationstation site) and mame4all recognise the inputs, emulationstation not. Any hint? I noticed that snesdev is in status off and it’s ok… i use arcade controls connecting pin to ground. While configuring I noticed that only one time emulationstation recognised a gpio pin for menu up, seems something in conflict…07/10/2014 at 04:21 #13820nbonaparteParticipantI have the same problem as you. I asked Aloshi (creator of EmulationStation) on the Raspberry Pi Forums and this is what he said:
This probably has to do with the change from SDL 1.2 to SDL 2. SDL2 uses evdev for input handling (in the console in the Pi). I don’t remember what SDL 1.2 uses. Not much I can do about this, sorry.
07/10/2014 at 14:47 #13983francesconumaParticipantOh, bad news here!
This is the code I used:https://github.com/adafruit/Adafruit-Retrogame/blob/master/retrogame.c
How did you resolve the problem?
07/10/2014 at 17:47 #14017ChanchaiGuestI use gpio pin to emulate keyboard.
I use python language for programing.On RetroPie 1.9. I use python-uinput module. It work fine.
On RetroPie 2.x The python-uinput module is not work.I solve this problem. I use python-evdev module. It work fine.
I think. uinput is not work on RetroPie 2.x.
Maybe libevdev is work on RetroPie 2.x.Python-evdev Module
https://pythonhosted.org/evdev/Source code
https://github.com/gvalkov/python-evdevExample Code
I use gpio pin 24 for ESC Keyboard for exit game#!/usr/bin/python import time from evdev import UInput, ecodes as e import RPi.GPIO as GPIO # GPIO PIN pin_esc = 24 ui = UInput() # Bools to keep track of movement key_esc = False GPIO.setmode(GPIO.BCM) GPIO.setup(pin_esc, GPIO.IN, pull_up_down = GPIO.PUD_UP) try: while True: if (not key_esc) and (not GPIO.input(pin_esc)): key_esc = True #print("Button Pressed"); ui.write(e.EV_KEY, e.KEY_ESC, 1); # KEY_ESC down #ui.write(e.EV_KEY, e.KEY_F4, 1); # KEY_F4 down ui.syn() if (key_esc) and (GPIO.input(pin_esc)): key_esc = False #print("Button Released"); ui.write(e.EV_KEY, e.KEY_ESC, 0); # KEY_ESC up #ui.write(e.EV_KEY, e.KEY_F4, 0); # KEY_F4 up ui.syn() time.sleep(0.3); except KeyboardInterrupt: ui.close() GPIO.cleanup()
07/10/2014 at 18:18 #14026nbonaparteParticipantDoes the python script take up more processing power?
The only other solution I can think of is to hook the buttons up to a Teensy.
07/10/2014 at 18:31 #14028ChanchaiGuestPlease try to modify code of retrogame.c with libevdev.
libevdev : http://www.freedesktop.org/wiki/Software/libevdev/
Maybe it can solve your problem.
07/11/2014 at 01:52 #14095MicroByteGuestAny luck from anyone getting controls to work? This is a shame since I just finished building a new controller into my Gameboy mod that works outside of ES.
Is there anyway to run an older version of ES until the issue is resolved or a workaround is found?
In the meantime, is there a way to launch the emulators directly from the command line maybe?
07/11/2014 at 10:35 #14225francesconumaParticipantI’m using mame4all-pi as emulator and It’s autoloaded via the /etc/profile file. Just changed “emulationstation” with “/…??/emulators/mame4all-pi/mame”
07/11/2014 at 10:47 #14230francesconumaParticipantI wrote to retrogame.c programmer asking for help.
07/11/2014 at 10:50 #14231francesconumaParticipant[quote=14017]#!/usr/bin/python
import time
from evdev import UInput, ecodes as e
import RPi.GPIO as GPIO# GPIO PIN
pin_esc = 24ui = UInput()
# Bools to keep track of movement
key_esc = FalseGPIO.setmode(GPIO.BCM)
GPIO.setup(pin_esc, GPIO.IN, pull_up_down = GPIO.PUD_UP)
try:
while True:
if (not key_esc) and (not GPIO.input(pin_esc)):
key_esc = True
#print(“Button Pressed”);
ui.write(e.EV_KEY, e.KEY_ESC, 1); # KEY_ESC down
#ui.write(e.EV_KEY, e.KEY_F4, 1); # KEY_F4 down
ui.syn()if (key_esc) and (GPIO.input(pin_esc)):
key_esc = False
#print(“Button Released”);
ui.write(e.EV_KEY, e.KEY_ESC, 0); # KEY_ESC up
#ui.write(e.EV_KEY, e.KEY_F4, 0); # KEY_F4 up
ui.syn()time.sleep(0.3);
except KeyboardInterrupt:
ui.close()
GPIO.cleanup()[/quote]the Python script is considering rebounce as in retrogame did you try with a “shot” button?
07/12/2014 at 19:44 #14888francesconumaParticipantMaybe someone could mix snesDEV with retrogame… Any c programmer here?
07/13/2014 at 23:58 #15390bolchGuestFound this thread while looking for the same problem
Today I pulled apart a Dreamcast Arcade Stick with the intention of putting a Pi inside running Retro Pi.
After plugging the buttons into the GPIO ports, I used Retrogame as mentioned above to configure the keyboard buttons.
Works perfect in the emulators, just doesn’t work in the launcher :-(
07/14/2014 at 13:11 #15554francesconumaParticipantI think the solution is quite simple, but we need a c or python script traslating from gpio to evdev, and someone who can write it. I think emulationstation programmer is not really interested on the problem because there is a gpio adapter we can buy on the site to connect retro joystick. So we have to find a solution by ourselves…
07/15/2014 at 05:04 #15733ChanchaiGuestI try to create simple python code.
I don’t have gpio joystick
#!/usr/bin/python import time from evdev import UInput, ecodes as e import RPi.GPIO as GPIO # GPIO PIN pin_esc = 24 pin_left = 25 pin_right = 9 pin_up = 10 pin_down = 17 pin_leftctrl = 23 pin_leftalt = 7 ui = UInput() # Bools to keep track of movement key_esc = False key_left = False key_right = False key_up = False key_down = False key_leftctrl = False key_leftalt = False GPIO.setmode(GPIO.BCM) GPIO.setup(pin_esc, GPIO.IN, pull_up_down = GPIO.PUD_UP) GPIO.setup(pin_left, GPIO.IN, pull_up_down = GPIO.PUD_UP) GPIO.setup(pin_right, GPIO.IN, pull_up_down = GPIO.PUD_UP) GPIO.setup(pin_up, GPIO.IN, pull_up_down = GPIO.PUD_UP) GPIO.setup(pin_down, GPIO.IN, pull_up_down = GPIO.PUD_UP) GPIO.setup(pin_leftctrl, GPIO.IN, pull_up_down = GPIO.PUD_UP) GPIO.setup(pin_leftalt, GPIO.IN, pull_up_down = GPIO.PUD_UP) try: while True: if (not key_esc) and (not GPIO.input(pin_esc)): key_esc = True ui.write(e.EV_KEY, e.KEY_ESC, 1); ui.syn() if (key_esc) and (GPIO.input(pin_esc)): key_esc = False ui.write(e.EV_KEY, e.KEY_ESC, 0); ui.syn() if (not key_left) and (not GPIO.input(pin_left)): key_left = True ui.write(e.EV_KEY, e.KEY_LEFT, 1); ui.syn() if (key_left) and (GPIO.input(pin_left)): key_left = False ui.write(e.EV_KEY, e.KEY_LEFT, 0); ui.syn() if (not key_right) and (not GPIO.input(pin_right)): key_right = True ui.write(e.EV_KEY, e.KEY_RIGHT, 1); ui.syn() if (key_right) and (GPIO.input(pin_right)): key_right = False ui.write(e.EV_KEY, e.KEY_RIGHT, 0); ui.syn() if (not key_up) and (not GPIO.input(pin_up)): key_up = True ui.write(e.EV_KEY, e.KEY_UP, 1); ui.syn() if (key_up) and (GPIO.input(pin_up)): key_up = False ui.write(e.EV_KEY, e.KEY_UP, 0); ui.syn() if (not key_down) and (not GPIO.input(pin_down)): key_down = True ui.write(e.EV_KEY, e.KEY_DOWN, 1); ui.syn() if (key_down) and (GPIO.input(pin_down)): key_down = False ui.write(e.EV_KEY, e.KEY_DOWN, 0); ui.syn() if (not key_leftctrl) and (not GPIO.input(pin_leftctrl)): key_leftctrl = True ui.write(e.EV_KEY, e.KEY_LEFTCTRL, 1); ui.syn() if (key_leftctrl) and (GPIO.input(pin_leftctrl)): key_leftctrl = False ui.write(e.EV_KEY, e.KEY_LEFTCTRL, 0); ui.syn() if (not key_leftalt) and (not GPIO.input(pin_leftalt)): key_leftalt = True ui.write(e.EV_KEY, e.KEY_LEFTALT, 1); ui.syn() if (key_leftalt) and (GPIO.input(pin_leftalt)): key_leftalt = False ui.write(e.EV_KEY, e.KEY_LEFTALT, 0); ui.syn() time.sleep(0.3); except KeyboardInterrupt: ui.close() GPIO.cleanup()
07/17/2014 at 00:59 #16415WilsonGuestI am also having the same issue. I just finished building a Porta-Pi that uses RetroPie 1.9.1 and I was hoping to upgrade to 2.2 but this definitely looks like a show stopper. Any luck with the retrogame.c developer?
07/17/2014 at 08:29 #16541francesconumaParticipantNo response at all.
07/17/2014 at 16:55 #16687WilsonGuestOk, I also opened a ticket on Github in hopes to make the programmer aware of the challenge and maybe incorporate the changes in a future version…soon! :) The new version of RetroPie looks really nice and would love to upgrade to it.
07/18/2014 at 23:40 #17082WilsonGuest07/19/2014 at 04:10 #17140nbonaparteParticipantConfirmed working!
Many thanks to CrazySpence for his work!If you’re looking for the SDL2 folder, it’s in /opt/retropie/supplementary.
EDIT: works in ES but not for Retroarch. It might need to be recompiled again or something.
07/19/2014 at 16:25 #17299bolchGuestHow do I get the new SDL to work? I downloaded it from github (https://github.com/CrazySpence/Adafruit-Retrogame) copied the new SDL_udev.c to /opt/retropie/supplementary/SDL-2.0.1/src/core/linux/ and restarted emulation station but it didn’t work
Is there something else I need to do (like Make), if so can you point this noobie in the right direction? Thanks
07/19/2014 at 18:18 #17323nbonaparteParticipantBolch: You have to run “make” and “make install” for it to run.
I still haven’t gotten Retroarch to work, however (but it worked in 1.9.1). Does it use SDL2 as well?07/19/2014 at 20:35 #17350bolchGuestThanks nbonaparte, worked perfectly after running make & make install in the SDL directory.
I found this (https://github.com/libretro/RetroArch/issues/799) which seems to suggest Retroarch it’s using SDL2
Putting my project on hold for the next couple of days as I’ve just bought the B+ so hoping there’s a fix by then
07/20/2014 at 00:35 #17410francesconumaParticipantGreat, thanks all
07/20/2014 at 01:03 #17414nbonaparteParticipantDo the controls on the RetroArch emulators (NES, Atari 2600, PSX, Mega Drive, etc.) work for you?
07/20/2014 at 21:19 #17601Marv2.0Guesthi guys, could give me a hand? Here’s what i’ve so far:
– downloaded SDL2-2.0.3, extracted and copied it to my home directory (/pi/SDL2-2.0.3)
– copied CrazySpence’s SDL_udev.c into /src/core/linux (overwrote the original one)
– run “make” or “sudo make” from the /pi/SDL2-2.0.3 and get this error:pi@raspberrypi ~/SDL2-2.0.3 $ make install
make: *** No rule to make target `install’. Stop.i also tried “make” from /src/core/linux, but I get the same error. Do i need to copy a makefile somewhere?
Thanks all.
07/20/2014 at 21:24 #17602Marv2.0GuestI copied the wrong error above. here’s the correct error when i type “make” inside SDL2-2.0.3
pi@raspberrypi ~/SDL2-2.0.3 $ make
make: *** No targets specified and no makefile found. Stop.07/21/2014 at 01:14 #17637nbonaparteParticipantYou don’t download SDL 2.0.3. You use the one in /opt/retropie/supplementary and “make” and “make install” there.
07/21/2014 at 05:29 #17674Marv2.0GuestThank you for your reply.
I did what you suggested, but I’m still getting errors. Below are all the different variations of “make” I tried. Any suggestions?
pi@raspberrypi /opt/retropie/supplementary/SDL2-2.0.1/src/core/linux $ ls
SDL_udev.c SDL_udev.hpi@raspberrypi /opt/retropie/supplementary/SDL2-2.0.1/src/core/linux $ make
make: *** No targets specified and no makefile found. Stop.pi@raspberrypi /opt/retropie/supplementary/SDL2-2.0.1/src/core/linux $ make SDL_udev.c
make: Nothing to be done for `SDL_udev.c’.pi@raspberrypi /opt/retropie/supplementary/SDL2-2.0.1/src/core/linux $ sudo make SDL_udev.c
make: Nothing to be done for `SDL_udev.c’.pi@raspberrypi /opt/retropie/supplementary/SDL2-2.0.1/src/core/linux $ sudo make
make: *** No targets specified and no makefile found. Stop.Thank you again.
07/21/2014 at 12:03 #17756francesconumaParticipantDo the controls on the RetroArch emulators (NES, Atari 2600, PSX, Mega Drive, etc.) work for you?
Sorry I didn’t try yet. I can suppose not, also for me.
07/21/2014 at 12:27 #17763francesconumaParticipantYou have to look for a file named Makefile.. I can’t verify now the exact position..
07/21/2014 at 17:52 #17846nbonaparteParticipantTo clear everything up, here are the commands in order (after transferring SDL_udev.c):
cd /opt/retropie/supplementary/SDL2-2.0.1 sudo make sudo make install
07/21/2014 at 18:42 #17856Marv2.0GuestThanks again… I was running make inside the linux folder. So now that I’m running it from the correct folder (/opt/retropie/supplementary/SDL2-2.0.1/) I get further…although I’m not successful just yet :)
I copied the SDL_udev.c from CrazySpence’s github and WinSCP it to /opt/retropie/supplementary/SDL2-2.0.1/src/core/linux. I then ran the make command from /opt/retropie/supplementary/SDL2-2.0.1/ and get a bunch of errors like the below. I think I’m just going to get a keyboard encoder and attach the joystick hardware via USB…that being said if you guys feel good about giving me a helping hand on what all these errors may mean, I would greatly appreciate it! Thanks in advance.
*I didn’t copy/paste the entire error output*
/opt/retropie/supplementary/SDL2-2.0.1/src/core/linux/SDL_udev.c:874:69988: warning: multi-character character constant [-Wmultichar] /opt/retropie/supplementary/SDL2-2.0.1/src/core/linux/SDL_udev.c:874:69998: warning: character constant too long for its type [enabled by default] /opt/retropie/supplementary/SDL2-2.0.1/src/core/linux/SDL_udev.c:874:70047: warning: multi-character character constant [-Wmultichar] /opt/retropie/supplementary/SDL2-2.0.1/src/core/linux/SDL_udev.c:874:70057: warning: character constant too long for its type [enabled by default] /opt/retropie/supplementary/SDL2-2.0.1/src/core/linux/SDL_udev.c:874:70082: error: expected identifier or '(' before '<' token /opt/retropie/supplementary/SDL2-2.0.1/src/core/linux/SDL_udev.c:874:70106: warning: multi-character character constant [-Wmultichar] /opt/retropie/supplementary/SDL2-2.0.1/src/core/linux/SDL_udev.c:874:70116: warning: character constant too long for its type [enabled by default] /opt/retropie/supplementary/SDL2-2.0.1/src/core/linux/SDL_udev.c:874:70146: warning: multi-character character constant [-Wmultichar] /opt/retropie/supplementary/SDL2-2.0.1/src/core/linux/SDL_udev.c:874:70156: warning: character constant too long for its type [enabled by default] /opt/retropie/supplementary/SDL2-2.0.1/src/core/linux/SDL_udev.c:874:70186: warning: multi-character character constant [-Wmultichar] /opt/retropie/supplementary/SDL2-2.0.1/src/core/linux/SDL_udev.c:874:70196: warning: character constant too long for its type [enabled by default] /opt/retropie/supplementary/SDL2-2.0.1/src/core/linux/SDL_udev.c:874:70082: error: stray '#' in program /opt/retropie/supplementary/SDL2-2.0.1/src/core/linux/SDL_udev.c:917:18: error: expected identifier or '(' before numeric constant make: *** [build/SDL_udev.lo] Error 1
07/22/2014 at 20:05 #18280nbonaparteParticipantIn RetroPie 2.3, the SDL 2.0.1 folder is gone and there is no SDL_udev.c, so this hack fix might not work anymore.
07/23/2014 at 01:32 #18356kj holmGuestOK, totally bummed out here. I have built a really nice mini Mame arcade machine (all inside the iarcadie iphone cabinet) and I wired in the controls so as to use retrogame solution like the adafruit.com example shows. However, I like other, can’t get the GPIO direct wired inputs to work with emulationstation OR with any of the emulators. When I hit F4 to exit back to command prompt my joystick and buttons are registering button presses at the command prompt so I know the code (for retrogame revised using CrazySpence solution above) and wiring is fine.
No idea what to do now….
Anyone have any clues?
07/23/2014 at 15:16 #18642Marv2.0GuestKJ, did you get any errors when running ‘make’ or ‘make install’?
in regards to your question, nbonaparte mentioned that this hack may not work on retropie 2.3 (not working for me on 2.2) so make sure you use an older version.
-
AuthorPosts
- The forum ‘Everything else related to the RetroPie Project’ is closed to new topics and replies.