Joystick using GPIO and USB at the same time
-
Hello I am about to star a new project about building a arcade but I have a few questions that I would like to know before I start.
What I am trying to accomplish is to have a retropie using the GPIO as inputs for a sanwa joystick and 8 action buttons plus a start and selet buttons.
At the same time I wish to have the possibility to plug and play any other controller using the USB port. Xbox 360 controller or another arcade stick (using PS360+ for example) or even a PS4 controller.Is this all possible?
The raspberry pi GPIO can be used like this? Are they laggy?
-
why add another layer of complexity, have another running process tie up 14 pins, if all you want to achieve is 1) hook up your arcade controls and 2) have the occasional usb controller added.
Just use on of these usb controllers for your sanwa controls and go usb all the way, retropie will happily manage them all;
Even better, show some support and get this nifty thingamagic called the ControlBlock!
http://blog.petrockblock.com/2014/12/29/controlblock-power-switch-and-io-for-the-raspberry-pi/
-
@edsousa84 said
The raspberry pi GPIO can be used like this? Are they laggy?
I have used the GPIO input method before and it does work well. My main focus was MAME games and I don't remember lag being an issue.
That being said I found it more complex than using something like an I-PAC for inputs. You have to keep track of each GPIO input you wire (i.e. - up=2, down=3, left=4, right=17, button 1=18, etc), then assign it a key (i.e. - 2, KEY_UP | 3, KEY_DOWN | 4, KEY_LEFT, 17, KEY_RIGHT | 18, KEY_LEFTALT, etc. these can be any keyboard input). Then compile the file and run a short command to poll the GPIO inputs on bootup. Lastly start the game you want to play and start configuring inputs which basically is just pressing the button you want assigned for up, down, etc. (I didn't have to much to do here as I configured the inputs to match the MAME default inputs). You'll need a keyboard attached for this part.
It might sound daunting but Adafruit has a great tutorial that really walks you through it step by step. After going through it once you'll breeze through it almost as fast an I-PAC. The hardest part is keeping track of what inputs do what so a pad and paper come in handy for that part. I used Notepad to keep track as you forget the inputs 6 months down the road asking yourself I think GPIO pin 2 was joystick up or was it down. Backup the retrogame.c file (modified input file). A diagram is nice if you ever need to replace the Pi but you could also you could use one of those dupont stacking header blocks which are really handy in keeping the wires organized if you unplug them. Like this:
https://www.adafruit.com/products/1979
Here's a snip of what I mean from the file, you see how each GPIO input is assigned to a key, basically it treats it like a keyboard input.
Here's a link to my project I used with GPIO. It was a kit that works well. HDMI for video with audo separated to a small amp with speakers. You can see all the GPIO inputs in a few of the photos. I had a cover created for the buttons under the marquee. It was pretty easy to find a guy with a 3D printer and he charged a nominal fee to create it.
https://www.flickr.com/photos/chadwilson/albums/72157645440659060// Input Output (from /usr/include/linux/input.h) { 2, KEY_UP }, // Joystick (4 pins) { 3, KEY_DOWN }, { 4, KEY_LEFT }, { 17, KEY_RIGHT }, { 18, KEY_LEFTALT }, // B/Bomb/secondary { 23, KEY_LEFTCTRL }, // A/Fire/jump/primary { 24, KEY_Z }, { 25, KEY_LEFTSHIFT }, { 8, KEY_X }, { 7, KEY_SPACE }, { 27, KEY_5 }, { 22, KEY_ENTER }, { 10, KEY_1 }, { 9, KEY_ESC }, // For credit/start/etc., use USB keyboard or add more buttons. { -1, -1 } }; // END OF LIST, DO NOT CHANGE
-
Thank you for all your inputs.
@ senkun
Adding a usb board takes a lot of space for my project that is why I am trying to use the Raspberry pi GPIO's
The ControlBlock migth be a solution it is a little bit expensive but it is a option.@ Riverstorm
I just have to configure the mapping of the inputs once right?
O I have to configure, compile the file run the command for every game I have to run (When you say compile the file I assume that is not a true compiler but a parser). -
@edsousa84 said in Joystick using GPIO and USB at the same time:
Thank you for all your inputs.
@ Riverstorm
I just have to configure the mapping of the inputs once right?
O I have to configure, compile the file run the command for every game I have to run (When you say compile the file I assume that is not a true compiler but a parser).Yes, you only need to do it once and it's the 'make' command, if that's a parser?
You're basically tying the button to a keyboard input. So if I go out to the prompt and press button 5 on the game console it literally prints z as if I pressed z on a keyboard, the buttons act just like a keyboard. From there you just tie the buttons to the emulator inputs. So MAME buttons A & B are Left-Ctrl & Left-Alt. Above you can see I tied KEY_LEFTCTRL to GPIO 23 and KEY_LEFTALT to GPIO 18. In MAME Left-Ctrl and Left- Alt are already the default keys so right off the bat my A & B buttons worked in MAME. In other emulators I had to reassign the keys to work with Left-Ctrl and Left-Alt, etc.
With that being said if you plan to use more than one emulator I would change the control keys like Left-Ctrl and Left-Alt as they do seems to wreak havoc in other emulators sometimes. Avoid them altogether and use letters which work the best when using GPIO. Except for like Enter, Escape, Tab which work fine for management like exiting the emulator, entering the settings, etc. I just avoided control keys as the main game buttons.
As I remember a little. If you're a button masher or hitting a lot of buttons it does confuse the GPIO occasionally where as an I-PAC keeps up flawlessly. The tradeoff is the price, GPIO is pretty much free as you still need to run the wires and ground regardless of input. For wire organization and I suppose troubleshooting I used multiple grounds grouping main keys, joystick, management buttons, etc. but I think you could use a common ground through the whole wiring harness if you wanted.
The main difference between the I-PAC and GPIO is configuring the retrogame.c file, running make and setting the polling to auto-load on boot. Once you have your retrogame.c file setup you can reuse it for other setups (using the same input setup) which makes things much quicker. I also just pull the emulator config files and as long as the version doesn't change in RetroPie I reuse the config files by copying and overwriting the default files.
Some of this is sketchy as it's been a few years since I worked with the GPIO inputs.
-
One more question is it possible to use Retropie without a mouse and a keyboard? Not the configuration part ofcourse but to a normal alredy configurated usage is it possible?
-
@edsousa84 said in Joystick using GPIO and USB at the same time:
One more question is it possible to use Retropie without a mouse and a keyboard? Not the configuration part ofcourse but to a normal alredy configurated usage is it possible?
Absolutely, take a look at the link of the project I did above. That's all I use. I plugin the power and away I go. I pull up the Emulationstation Quit Menu and Shutdown System when done. I have to manually unplug the power cord or the Pi still gets power but it should be easy enough to wire in a switch with some light soldering and shrink tubing or there are several inline pigtails with an off/on switch. The issue I am currently working out is adding volume buttons to the back with normal open switches. A power button later but I don't mind unplugging it for now since it's such a small counter top unit really. It's a fun unit and not so much for serious gaming even though it does a fairly decent job.
I use a keyboard for troubleshooting or adding a game, etc. and it doubles nicely for ScummVM games or other emulators that might need a keyboard like C64, etc. I bought a wireless keyboard/mouse with a built-in Trackpad. It's about an 80% full size keyboard so it's compact enough to move around until you get the bugs ironed out. The wireless dongle is one of those penny micro size ones I just leave plugged in. Here's the keyboard I use. I got it on sale for $20.
http://www.amazon.com/Logitech-Wireless-Keyboard-Built-In-Multi-Touch/dp/B005DKZTMG
-
@edsousa84 said in Joystick using GPIO and USB at the same time:
One more question is it possible to use Retropie without a mouse and a keyboard? Not the configuration part ofcourse but to a normal alredy configurated usage is it possible?
Depending on which emulators you're setting up with Retropie, but generally with mame and all console gaming emulators you can ditch the kbd/mouse once you've got em all configured.
Seriously, have a good look and read up on the ControlBlock, it has everything you'd want, all worked out nicely and would save you a ton of headaches trying to piecemeal something together.
-
@senkun said
would save you a ton of headaches trying to piecemeal something together.
Honestly it's a nice project and learning experience especially for younger folks in so many aspects from hardware, electrical to software. I enjoyed the "journey" almost more than the gaming. Well I should say I have spent more time building the boxes than I have playing them.
Anyway the ControlBlock looks awesome! I see they are sold out of "+ 4 LOCKING POSTS (DUAL SIDE LOCK-IN SUPPORT, MADE OF NYLON) ($41.50) (SOLD OUT)". Is there mounting hardware with the Block or is that a separate order? The city I live in has very little in the way of proper nylon washers and spacers.
-
@Riverstorm you don't really need the locking posts if you're careful not to apply pressure while wiring it up. They just take the strain off the gpio pins in case you press too hard on the board. Just wire up everything before you plug in on to your pi.
-
Thank you again for all your help.
-
@senkun said in Joystick using GPIO and USB at the same time:
I know, sad to admit, but that is one sexy pic!
-
@Riverstorm said:
I know, sad to admit, but that is one sexy pic!
lol it is innit? look at all them slots waitin to be filled... ;P
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.