USB joystick for primary input device
  • I bought this controller, because I found someone who said it worked for them:
    http://www.amazon.com/gp/product/B0015PHMFU/ref=oh_details_o00_s00_i00?ie=UTF8&psc=1

    I'm just trying to get PiMAME running without a keyboard. I'm hoping to use this as a MAME machine, where it's possible to scroll through menus with the joystick, select from menus with a joystick button, etc.

    I have no idea where to begin - I basically just want to map keys to joystick functions.
  • Anyone? I didn't think it would be difficult, I just dont know how to remap keys.

    I just need to change the keyboard keys for tab, enter, escape, up and down to joystick functions.
  • Joysticks have been at the top of my list, but it really sucks getting them to work. I could def use some help on that front.
  • I got it working, but I want it working for the boot menu. It's fine in the emulators.
  • If you goto the console, what output do you get when you press up and down and each of the buttons. If I have that info, I'll know what to map it to
  • Console? Which console?
  • I tried to install xev to do something like this, but I couldn't get it working. I even tried copying it off my Mint box, no luck. If there's a console where I can get that data, that's awesome - just let me know how to access it! :)
  • And actually, I reinstalled PiMAME because I wanted a clean install after I did so much mucking about working on the roms and joystick, and now the joystick doesn't work in the emulators anymore.

    I have not installed a driver for it, but it shows up in /dev/input/ as js0.
  • when i said console, i meant the command line. from pimame menu select exit and you will be on the command line.

    It's weird that the joystick isn't working at all now.
  • I didn't install any package to get the joystick to work. But it shows up as js0.

    How do I check the output from an input device on the command line?
  • First, many thanks for your great work Shea!

    I have a PS3 dual shock usb connected to the pi with the following results which may help:

    jstest shows all buttons & axis working great :)

    advmenu - works but control mapping seems fixed - i.e. I have to use the joystick rather than the d-pad etc (I could be missing something here)

    advmame - works up to button 12 (or it may have been 11 or 13) - anything after that does not work which is problem as the main X & O buttons are numbered higher than this so cannot be used :(

    pi-snes - doesn't work - googling around I think someone had found this was due to it expecting a max of 5 axes but the dualshock has many more. Someone got it to work by changing unix.cpp (i think) and removing the check on 5 axes limit.

    Let me know if you are interested in more details and I'll do some research for you with more exact results!

    Cheers!
  • Rather than use a USB joystick, I rewired some arcade parts to GPIO (used a breakout cobbler board from adafruit) and then went and compiled their retrogame code to map the GPIO pins to keyboard presses. It was fairly trivial to get the buttons I wanted mapped to the default mame keys (including ESC, so I can go completely keyboard free!)

    I also needed to enable the uinput module at boot time.

    I don't know if there is a module that needs to be loaded before USB joypads can be used in linux, but I suspect there is.
  • nayphee, can you detail how you did this please? I was trying to do this for the RPi shutdown with no luck.
  • Baby steps here. I've installed jstest but I can't quite figure out how to use it.

    I'm trying:

    jstest --event js0

    Nothing I touch on the joystick seems to do anything.
  • Do you get any characters displayed on the command line when you press various buttons on the controller?
  • Check this out for wiring your joysticks and buttons to the GPIO pins.

    http://learn.adafruit.com/retro-gaming-with-raspberry-pi/buttons

    What I did was to get a cobbler breakout board from adafruit and solder all my connections to that. It's nicely laid out with solder holes, and has a ribbon cable so that you can connect it to the pi. That way avoids soldering pins directly to the pi, and I can easily unhook the pi from all the buttons if/when I need to pull the pi out and do work on it.

    http://learn.adafruit.com/adafruit-pi-cobbler-kit/overview

    I simply edited the retrogame code and added what keys I wanted for each pin, compiled it, dropped it in /home/pi. Then I set up uinput to load at boot time and got rc.local to start it -- as per the instructions.

    All the buttons and joystick directions need to have a common "ground" connection (so one side of each button and joystick switch are all wired together in a ground circuit), and that in turn is wired to the ground pin on the board. Then you wire each direction/button to it's respective GPIO pin.
    I managed to cram 4 joystick directions, 5 game buttons, player 1&2 buttons, as well as coin insert, ESC, and I have one spare (which I may wire to F3 for reset, or TAB for menu -- not sure yet -- but this could have been a sixth button if I had room for one on my case.)

    To go completely keyboard free with the PI, I created a short script to act as a "maintenance window" before automatically starting up any emulator. This gives you a 3 second window to break out of the script with Ctrl-C and get a bash shell. Unless you've been silly and configured both CTRL and C to seperate output buttons, you won't be able to break out of the script without a keyboard attached - which is the goal.
    Without this script, and since the emulator is going to be autostarting, we'd have no opportunity to stop the pi and we'd likely lose control of it!

    #!/bin/bash
    echo "Loading MAME! Ctrl-C for maintenance"
    sleep 3

    I edited /home/pi/.profile. First task was to comment out the line that starts the pimame menu.

    After that, I added three lines:
    First I called the maintenance window script.
    Next I called mame4all
    Lastly I called shutdown -h now

    So the way it works is that the pi starts up, triggers the maintenance window script, which if left alone, automatically finishes and then starts up MAME.
    Since I have ESC wired to one of my buttons, when I am done playing, hitting it closes MAME and then .profile triggers off the shutdown command.

    Now I am keyboard free! I'll post some photos later in another thread.
  • @nicktones

    If I'm simply sitting at the pi@raspberrypi ~ $ command line & press buttons on the controller, no, nothing happens at all.
  • How should I be using jstest? I feel like I'm definitely doing it wrong...
  • @kcross

    I used

    sudo jstest /dev/input/js0

    which worked for me with the ps3 dual shock connected on usb cable...
  • @SSilver2k2

    The PiSnes changes made for using the ps3 dual shock as a usb joystick I referred to earlier are here:

    http://www.raspberrypi.org/phpBB3/viewtopic.php?f=78&t=42152&start=35

    Hope it means something to you!

    Cheers
  • @chriso OK! That worked for me - it showed the joystick functions correctly when I moved the controller & pressed the buttons...

    Now --- how do I get that to work with the PiMAME Menu?
  • Getting a USB joystick to work on the PiMAME menu is not going to be easy. As that responds to key presses.
  • the PiMAME menu is made in Python, and looks for a keypress, I wonder if I could use something to read in the usb joystick info. I don't know yet, but its a possibility.
  • if the menu could be activated with CTRL instead of return, that would also help a lot.
    I suppose we could just recode the menu ourselves....
  • @SSilver2k2

    Maybe this would help:

    http://www.stealth-x.com/programming/driver-writing-with-python.php

    There is a complete script at the end...
  • nayphee, can you detail how you did this please? I was trying to do this for the RPi shutdown with no luck.
  • @Kcross did you ever get your usb stick working with the games? I seem to be having the same issue as you did.

    Jim
  • I managed to hack the menu.py script to read the joystick controls using the pygame add-on but there's a known bug in the pygame binary for the raspberry pi where it constantly sends debug info to the screen. There's an updated version of the source code with the bug fixed but I haven't got a clue how to go about compiling it for the pi. If someone can point me in the right direction, it would be much appreciated.
  • I've managed to get around the pygame joystick bug by writing the joystick event handler slightly differently and it now works fine with the joystick! Woohoo!! However, in doing so, I've had to disable the keyboard input as it uses Curses commands which doesn't really work with the way the pygame joystick code needs to be written. I'm trying to use the pygame keyboard events instead which should be fairly straight-forward as it's similar to the joystick code, but I can't get it to work. Anyone got any experience of this?
  • I've discovered why I can't read keyboard presses in Pygame in a console window. Without rewriting the entire interface, I'll have to do it another way, which can wait for the time being. It works from the joystick which is what I wanted it to do. Let me know if you want the program.
  • i will take the program!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!