Viewing 35 posts - 1 through 35 (of 40 total)
  • Author
    Posts
  • francesconuma
    Participant
    Post count: 18

    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…

    nbonaparte
    Participant
    Post count: 17

    I 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.

    francesconuma
    Participant
    Post count: 18

    Oh, 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?

    Chanchai
    Guest
    Post count: 908

    I 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-evdev

    Example 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()
    nbonaparte
    Participant
    Post count: 17

    Does 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.

    Chanchai
    Guest
    Post count: 908

    Please try to modify code of retrogame.c with libevdev.

    libevdev : http://www.freedesktop.org/wiki/Software/libevdev/

    Maybe it can solve your problem.

    MicroByte
    Guest
    Post count: 908

    Any 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?

    francesconuma
    Participant
    Post count: 18

    I’m using mame4all-pi as emulator and It’s autoloaded via the /etc/profile file. Just changed “emulationstation” with “/…??/emulators/mame4all-pi/mame”

    francesconuma
    Participant
    Post count: 18

    I wrote to retrogame.c programmer asking for help.

    francesconuma
    Participant
    Post count: 18

    [quote=14017]#!/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()[/quote]

    the Python script is considering rebounce as in retrogame did you try with a “shot” button?

    francesconuma
    Participant
    Post count: 18

    Maybe someone could mix snesDEV with retrogame… Any c programmer here?

    bolch
    Guest
    Post count: 908

    Found 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 :-(

    francesconuma
    Participant
    Post count: 18

    I 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…

    Chanchai
    Guest
    Post count: 908

    I 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()
    Wilson
    Guest
    Post count: 908

    I 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?

    francesconuma
    Participant
    Post count: 18

    No response at all.

    Wilson
    Guest
    Post count: 908

    Ok, 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.

    Wilson
    Guest
    Post count: 908

    Ok, CrazySpence over at Github created a Retrogame fork that has the fix. You don’t need to modify Retrogame but only one file (SDL_udev.c file in src/core/linux in the SDL2 source tree–instructions in his comments) to get Retrogame.c back up and running. All hail CrazySpence!! :)

    nbonaparte
    Participant
    Post count: 17

    Confirmed 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.

    bolch
    Guest
    Post count: 908

    How 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

    nbonaparte
    Participant
    Post count: 17

    Bolch: 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?

    bolch
    Guest
    Post count: 908

    Thanks 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

    francesconuma
    Participant
    Post count: 18

    Great, thanks all

    nbonaparte
    Participant
    Post count: 17

    Do the controls on the RetroArch emulators (NES, Atari 2600, PSX, Mega Drive, etc.) work for you?

    Marv2.0
    Guest
    Post count: 908

    hi 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.

    Marv2.0
    Guest
    Post count: 908

    I 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.

    nbonaparte
    Participant
    Post count: 17

    You don’t download SDL 2.0.3. You use the one in /opt/retropie/supplementary and “make” and “make install” there.

    Marv2.0
    Guest
    Post count: 908

    Thank 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.h

    pi@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.

    francesconuma
    Participant
    Post count: 18

    Do 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.

    francesconuma
    Participant
    Post count: 18

    You have to look for a file named Makefile.. I can’t verify now the exact position..

    nbonaparte
    Participant
    Post count: 17

    To 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
    Marv2.0
    Guest
    Post count: 908

    Thanks 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
    
    nbonaparte
    Participant
    Post count: 17

    In 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.

    kj holm
    Guest
    Post count: 908

    OK, 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?

    Marv2.0
    Guest
    Post count: 908

    KJ, 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.

Viewing 35 posts - 1 through 35 (of 40 total)
  • The forum ‘Everything else related to the RetroPie Project’ is closed to new topics and replies.