Connecting old school joysticks to the Arduino and Gameduino

30 Dec

So you’ve got some old school joystick with a DB9 connector lying around, time to connect it an Arduino board.

The pin out’s for the joystick connector (male connector) I took from the original Atari pin out, as we see later on this pin layout is the most generic one and works with joysticks from Atari, Commodore, Sega, Quickshot, …

Pin’s 1 to 4 are up/down/left/right

Pin 6 is the fire button

Pin 8 is the GND

If you need to support more button’s then there’s some bad news every manufacturer seems to did his own extra button wiring, so for simplicity I took a one button configuration. We simply need to connect these pins to the the Arduino digital pins. I choose pins 3 to 7, you can choose other configurations but for me it was more easier to choose 5 pins next to each other as I reused an old serial switch box to recuperate the DB9 male connector on it, so I simply cut the wires from it.

Next I soldered the wires comming from the male DB9 to the  pins as in the picture. Pins 7 -> 3 Up/Down/Left/Right/Fire

A soldered 1 pin to the GND wire.

Then it was time to test this setup, I used an Arduino Decimilla for the test, with a small sketch.

/*
 Joystick test Sketch

 Reads the digital direction and button state from Atari compatible joystick.
 Some code reused from the Sparkfun joystick shield test sketch.
*/
//Variables for the buttons
char buttonUp=7, buttonDown=6, buttonLeft=5, buttonRight=4, buttonFire=3;
void setup(void)
{

 pinMode(buttonUp, INPUT);
 digitalWrite(buttonUp, HIGH); //Enable the pull-up resistor
pinMode(buttonDown, INPUT);
 digitalWrite(buttonDown, HIGH); //Enable the pull-up resistor

 pinMode(buttonLeft, INPUT);
 digitalWrite(buttonLeft, HIGH); //Enable the pull-up resistor
pinMode(buttonRight, INPUT);
 digitalWrite(buttonRight, HIGH); //Enable the pull-up resistor

 pinMode(buttonFire, INPUT);
 digitalWrite(buttonFire, HIGH); //Enable the pull-up resistor 

 Serial.begin(9600); //Turn on the Serial Port at 9600 bps
}
void loop(void)
{
 Serial.print(digitalRead(buttonUp)); //Read the value of the button up and print it on the serial port.
 Serial.print(digitalRead(buttonDown)); //Read the value of the button down and print it on the serial port.
 Serial.print(digitalRead(buttonLeft)); //Read the value of the button left and print it on the serial port.
 Serial.print(digitalRead(buttonRight)); //Read the value of the button right and print it on the serial port.
 Serial.println(digitalRead(buttonFire)); //Read the value of the button fire and print it on the serial port.

 //Wait for 100 ms, then go back to the beginning of 'loop' and repeat.
 delay(100);
}

Then I did  some testing with joysticks and gamepads I had lying around:

Quickshot standard, original from my C64 works exactly like the Atari.

Atari joystick

Atari gamepad with button 1 & 2 both buttons trigger the same fire button but can be wired different to get both working.

Sega Master System gamepad, only button 1 works.

Sega Mega Drive gamepad, only button B works.

We can conclude that all support the directional buttons and fire button but the extra button’s are a different story maybe for another blog post ?

Finally I hooked the joystick up to my Uno/Gameduino setup, that’s why I didn’t used pin 2 as it’s used by the Gameduino.

I remapped the pins in the Gameduino Asteroids sketch and the whole thing runs perfectly. Although the Asteroids game doesn’t use the fire button.

Advertisements

11 Responses to “Connecting old school joysticks to the Arduino and Gameduino”

  1. yeahright 2012/08/28 at 3:07 am #

    Can it WRITE to the Atari 2600 joystick port? If so, this would be a good way to create macros for games. Also, good for testing games for bugs. Lastly, Joystick inputs could be used as save games or additional levels.

    • cybor808 2012/08/30 at 6:22 pm #

      1) The joystick ports are just switches so you could use arduino to open/close the switches.
      2) So you want to make a joystick cartridge for tha Atari 2600 ? Should be possible if you can get some sort of serial protocol working to read out the memory via the joy port.

  2. Nathan Reeves 2014/09/21 at 3:20 pm #

    I think the pin out should be this:

    http://hooliowobbits.blogspot.com/2012/08/interfacing-atari-joystick-to-arduino.html

    http://old.pinouts.ru/Inputs/JoystickAtari2600_pinout.shtml

    I think you have the pins labeled as a DB-9 male connector

    • cybor808 2014/09/22 at 6:13 am #

      It is indicated in the post that it is a male layout. See second paragraph.

  3. Nathan Reeves 2014/09/21 at 4:15 pm #

    works great!

    i opened the serial monitor and was could see

    press up 01111
    press down 10111
    left 11011
    right 11101
    button 11110

    trying to use this to install some joystick for my c64 emulator. seems like unojoy is a good start.

    thanks!

  4. Nathan Reeves 2014/09/22 at 12:07 pm #

    Did you ever get this to work with an actual emulator?

    I tried using UNOJOY ( https://code.google.com/p/unojoy/ ) to get my Atari joystick to work with C64 forever emulator.

    Only the fire button will work, none of the directional pads will respond even though all buttons when pressed were sending serial data…

    I installed Stella and will try to see if that works better…

    • cybor808 2014/09/22 at 2:31 pm #

      Hi Nathan, never used it with an emulator because it isn’t a joystick to usb application. It’s just sample code to read out the pins. To act as a physical usb device you’ll need some more code. I think the arduino leonardo would be a better design choice. Hope you have more luck with unojoy, let me know if it works.

  5. mustafa 2015/01/01 at 10:26 am #

    can this work with an old pc joy stick?

    • cybor808 2015/05/29 at 7:31 pm #

      I don’t think, if I remember correctly they were analog not digital.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: