fuzzix.org

Jaws was never my scene and I don't like Star Wars
Subscribe

Connecting an old Gamepad to PC

A couple of posts ago I mentioned A Megadrive Gamepad Repair I did.

While it's a great pad for use on classic computers and consoles, it's not so usable on a PC without dedicated hardware... which we can build quite easily with an arduino and an old serial socket.

There are projects to have the arduino act as a standard USB HID device, but after much trial and more error I could not get it working reliably. The alternative I chose was to send the joypad status over plain serial (the Arduino's FTDI serial device, the serial socket mentioned elsewhere is to plug the gamepad into) and issue Xlib key down/up events based on this to the currently focused window. Simply plug the arduino in, run 'sendkeys' and away you go. Arduino and C++ code is linked at the bottom of the post.

I connected the lines of the (9 pin D-Sub) serial socket to the Arduino (Nano 3.0) like so:

+-------------+-------------+
|   Serial    |   Arduino   |
+-------------+-------------+
|      1      |     D13     |
|      2      |     A0      |
|      3      |     A1      |
|      4      |     A2      |
|      5      |     +5V     |
|      6      |     A3      |
|      7      |     A4      |
|      8      |     GND     |
|      9      |     A5      |
+-------------+-------------+

The Gamepad can now plug straight in. I used the analogue pins just to keep them out of the way while experimenting with USB.

Video of the Gamepad in action using the Gens/GS Megadrive Emulator. Yes, I know the gameplay is poor, but it wasn't the most comfortable playing angle :) :

Megadrive Gamepad via Arduino

Gist for the (single pass) code - comments and contributions welcome.

by fuzzix on Fri, 06 Sep 2013 15:29.

Comments

claude
Thu, 22 May 2014 17:40

Hi,

Thanks for sharing ;)

I'm actually trying to make a genesis pad working through my arduino uno.
Whenever I press a button it seems like it's receiving input so the ino code is ok.

As a total newbie in C++ and make file. How do you "run" sendkeys ? Through a compiler ?
If so, which one ?

Thanks a lot ;)


fuzzix
Sun, 25 May 2014 23:21

Thanks for commenting.

There's a Makefile in the gist. If you run 'make' inside the directory with all the files, then run './sendkeys', you should be able to send events to the active window.


claude
Wed, 28 May 2014 16:21

Thanks for taking the time to reply

As a noob to makefiles, i have some questions,

do you need a program like Gnu or can you directly run the command in a C: prompt window ?
I've read makefiles are common under a linux environnement. Do you use linux or windows ?

Again, thanks !


claude
Wed, 28 May 2014 22:38

I have understood how to run a makefile.

I installed MingW and configured it (in PATH environement variables) win7. but when i type the command "make" in the directory of gistfiles there is a message:

g++ -o sendkeys sendkeys.cpp -L/usr/lib64/ -lX11
sendkeys.cpp:12:22: fatal error: X11/Xlib.h: No such file or directory
#include <X11/Xlib.h>
Compilation terminated.
make: *** [sendkeys] Error 1

Your help may be appreciated.


fuzzix
Thu, 29 May 2014 13:47

Ah, OK, sorry claude, this code is only going to work on something running X, so usually Linux or BSD.

Apologies for not making this more clear in the post.

It's *possible* that you *might* be able to compile this with MinGW/cygwin and an X server for windows, but all your applications accepting input would need to be X applications too.

A better approach might be to adapt sendkeys to emit Windows API calls, though not sure how feasible that is and don't have the expertise to offer guidance.


claude
Sat, 31 May 2014 14:10

Hey thanks !!!

I'll give Linux a try I think soon as I have some time.
For now I'm stuck with my arduino r3 cause I tried an app called "Unojoy" that completely messed up my Arduino board.
I turned it into DFU mode (by resetting the two pins) and loaded a batch file. Detected my arduino as a game controller but the controls sucks ! Only one button works (UP) and it reads upperleft !

I try to run the Backtoarduino batch file but it doesnt work...I'm stuck in a DFU messed up mode. Plus Atmel Flip soft closes everytime I load a hex file...Damn!!!!

Anyway thanks for replying as always. I really appreciate when people are helping ;)


claude
Thu, 05 Jun 2014 19:00

Hi,

Just to let you know.

I finally managed to work a genesis pad on pc with arduino ;))))

I used unojoy (R3 compatible) and this code :
https://gist.github.com/jrmedd/5516875
Works great ;)


fuzzix
Tue, 10 Jun 2014 13:55

Nice, thanks for the link!


claude
Thu, 12 Jun 2014 20:41

http://claudebna.overblog.com/megadrivepadusb.html

Here's the blog. You're credited ;)
Thanks !


fuzzix
Thu, 19 Jun 2014 14:54

Very nice, much neater work than my effort (my soldering is very much software guy soldering).


Comment on this post

Text only, no HTML, * denotes a required field.

Name *
Email Address *
Website
Mystery box, leave it alone!