USB NES Controller With an Arduino!

66,177

75

85

Published

Introduction: USB NES Controller With an Arduino!

About: Semi-Creative Lack of concentration Believes beards are awesome <3 Arduino Willing to help people in need of answers to teh interwebz q's

UPDATE 22-12-2014
Instructables user mattpbooth has updated the code and is hosting it on github:

https://github.com/mattpbooth/ArduinoNESController...

Thanks Matt!

UPDATE 03-12-2011

Replaced a println with print (derp).

UPDATE 01-12-2011

Remade all code from scratch.

Remade 'ible code section; Now includes a 'Processing COM port config for dummies'

Ladies and gentlemen, I proudly present 8bit pleasure.. yours for the grabbing! Whether you use GNU/Linux, Mac OS X, or Windows the USB NES controller is compatible.

Will this in any way alter the controller?

Nope, the controller will stay the same so you can still use it on a real NES

But I don't have an arduino ;_;

You can use the parallel port: http://hellalame.com/nes/nes_controllers.html

Buy an arduino: http://hellalame.com/nes/nes_controllers.html

Or a retrozone NES kit: http://hellalame.com/nes/nes_controllers.html

Step 1: Ingredients for Some Awesome Controller Soup

You will need:
A NES controller
An Arduino
A USB cable type B
Something you can use as a Casing
and some wire..
Optional: NES port http://www.parallax.com/Store/Components/Other/tabid/157/CategoryID/32/List/0/SortField/0/Level/a/ProductID/522/Default.aspx

Arduino software http://arduino.cc/
Processing http://processing.org/

Step 2: How to Connect the Arduino to the Nes Controller

With some wire connect the pins according to the texts on both pictures..
You could also use the controller port from a NES (a broken one, don't waste a working one).

You want something vaguely similar to the last picture.

Step 3: Code

UPDATE 22-12-2014

Instructables user mattpbooth has updated the code and is hosting it on github:

https://github.com/mattpbooth/ArduinoNESController

Thanks Matt!

Hey guys, I've completely rewritten the code and it should work now flawlessy.
The only adjustment you might need to make is to the Processing Sketch; you need to adjust which COM port it should use.
To do this please follow these steps carefully!

Steps

1 ) Disconnect the Arduino if it's connected.
2 ) Run the Processing sketch, it WILL(!) display an error.
3 ) Check the console (black box with text at the bottom of processing)
4 ) In the console will be a list of active COM ports;

Serial list
WARNING: RXTX Version mismatch
Jar version = RXTX-2.2pre1
native lib Version = RXTX-2.2pre2
[0] "COM3"
End of serial list

5 ) As you can see currently COM3 is active and is the first COM port at the moment (denoted by "[0]")
6 ) If the Processing sketch ran without displaying an error, press the stop button.
7 ) Hook up the arduino.
8 ) Run the Processing sketch again.
9 ) Check the console for active com ports;

Serial list
WARNING: RXTX Version mismatch
Jar version = RXTX-2.2pre1
native lib Version = RXTX-2.2pre2
[0] "COM3"
[1] "COM5"
End of serial list

10 ) As you can see COM5 suddenly appeared in the list after we connected the arduino.
11 ) We now know that the arduino has COM5 and is the second COM port (denoted by "[1]")
12 ) We know adjust our code;

Replace:
arduino = new Serial(this, Serial.list()[?], 9600); // ATTENTION!!!

With:
arduino = new Serial(this, Serial.list()[1], 9600); // ATTENTION!!!

13 ) Save the program.
14 ) Load the arduino sketch unto the arduino.
15 ) Start the Processing sketch!

Step 4: Making a Case

Let your imagination run wild!
I put my arduino into an old printer adapter I found and I think it looks pretty good =)
I did this by gutting the adapter and only saving the 'nipple'.
I removed the 'nipple' from the cable by cutting into one side with a knife, after which the original cable could be pushed out and replaced by my USB cable.

The adapter had a small hole (which I used for the usb cable) and a big hole which I used for the NES controller.
The big hole however wasn't big enough so I cut some away with a saw (very sloppy) after which it was too big, I temporarily fixed this by putting some sticky tape around the controller plug.
I've currently ordered a broke NES to harvest the controller port from in order to make it more.. sexy.

Step 5: It's Alive!

I currently don't have a camera at hand so here is a short desktopmovie of me bashing some buttons on the controls.
If you get an error file saying java wasn't found you'll need to install it (again) http://java.com/
In case anyone is wondering why I made a batch file; I was too lazy to reinstall java and made a small manual fix.

Btw,
to play a NES game on your computer you will need an emulator:

[windows] http://www.emulator-zone.com/doc.php/nes/ (If you're running vista, use FakeNes)
[Mac] http://www.zophar.net/macintosh/nes.html
[Linux] http://www.zophar.net/linux/nes.html

And you will need some games(ROMS) ofcourse but these are illegal to download (Yes, even if you own the original) so whatever you do don't download them and especially not from this site http://vimm.net/ because that one is the most illegal of all *GASP*

Step 6: Additional Info

More details
Inside the NES controller is an 8bit shift register.
By putting the latch pin high for a few microseconds I'm telling the chip to start spitting data at me.
When it does this, the first byte becomes available to read over the serial pin.
If I want to receive the next byte I'll have to set the clock pin high for 200 microseconds.
I need to 'flash' the clock pin 7 times to get all bytes

/*
Latch high
Wait 200 microseconds
Latch low
Read serial
Wait 200 microseconds

Repeat 7 times
[
Clock high
Wait 200 microseconds
Read serial
Clock low
Wait 200 microseconds
]
*/

SNES controller
The code I've written can also be used with a SNES controller!
If someone makes a request I can expand this 'ible to also show how to do that

Original code
http://little-scale.blogspot.com/2007/07/nes-controller-to-arduino.html'

and finally..
This is my first instructable, so go hard on me =P (yes hard, not soft =P)

Share

    Recommendations

    • Microcontroller Contest

      Microcontroller Contest
    • Make it Move Contest

      Make it Move Contest
    • Casting Contest

      Casting Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    85 Comments

    Hello!

    I tried this today and it works but i cannot get a response outta the A button and i've tried both my NES controllers.

    I have a hard time believing that the same button on both my controllers are broken, especially since my NES never saw much use.

    So i'm leaning on an error in the code somewhere, i'm not a programmer and thus have no knowlefe in this stuff, so debugging is out for my part.

    2 replies

    Hey, see the reply to Andromorfo above. Your A is first in the cycle and was being skipped with the first clock pulse.

    I have leonardo set to press keys like makey makey and it works fine
    On everything but emulator
    I don't want to use controller I made foot and fist pads but it won't work on emulator please help

    thanks for the update and quick reply
    i got an error code right away and on this line
    import processing.serial.*;
    am i doing something wrong
    sorry im a newb

    4 replies

    still getting error messages and wsalgklgkwsaklgwsalgwsalgklgkwsaklgwsalgwsalgklgkwsaklgkwsaklgws
    when trying to use the controller

    Hey, those keystrokes are down to the keyboard emulator doing its thing. The processing script was reading a string as individual char at the version I used so was firing text like the above when not touching the buttons. If you swap the Serial communication to use a single byte each time (8 inputs = 2^8 = 256) by using Serial.Write/Serial.Read you'll also save 2 bytes per message and have a fixed message length.

    Hey lewsidius did you fix that wsalgllgkwsaklg thing because I'm getting it too

    I have pins set to print letters on keyboard how can I use this to play games on emulator
    For some reason the arduino key presses aren't registering

    I would also like to see this include the SNES controller. It's a far easier way to attach a controller to an Ardiuno Uno than building a HID controller.

    Please help I got everything hooked up and ready and was ready to play some childhood nes games with the real controller instead of a keyboard but all of the sudden it just started saying wsalglgk just like lewsidius and I don't know if it's hooked up wrong or something please help

    1 reply

    Also forgot to say I'm using the arduino uno

    Hey man thanks for the instructable, i used the NES controler to control my robot arm, but for some reason the button A doesn`t work, and i`ve tested it with different controlers.

    here is a video of my robot arm
    http://www.youtube.com/watch?v=Va9D9Fpc5H8

    P.D.- sorry for the awful english :P

    3 replies

    i changed some of the arduino code and now it works with all the buttons, i needed to read the first bit before the for cicle and then read the others 7 bits

    here´s the code, i hope it helps someone getting the same problem

    void ReadNESjoy() {
    nes[0]=1;nes[1]=1;nes[2]=1;nes[3]=1;nes[4]=1;nes[5]=1;nes[6]=1;nes[7]=1;
    latchlow;
    clocklow;
    latchhigh;
    wait;
    latchlow;
    nes[0]=dataread;
    for (int i = 1; i < 8; i++) {
    clockhigh;
    wait;
    nes[i]=dataread;
    clocklow;
    wait;
    }
    }

    Doesent work!

    Just throws a buncha error messages like "nes not declared in this scope" among other things.

    This worked for me:

    void ReadNESjoy() {
    latchlow;
    clocklow;
    latchhigh;
    wait;
    latchlow;

    for (int i = 0; i < 8; i++) {
    output += dataread * (1 << i);
    clockhigh;
    wait;
    clocklow;
    wait;
    }
    }

    Hi again,

    I made it with an atmega standalone inside the nintendo, so i can plug two remote. I used the usbkeyboard librairie but i still have a tiny problem... When i print letter on a txt everything work fine, but on a emulator it seem that the flow of data is not good. My mario is almost not moving at all, and he make very small jump when i keep press.
    I tried to configure a "repeat delay" and a "repeat rate", but the result is still the same. I don't anderstand how your usbjoystick library send the data to the computer, do you know any configuration to do about that?

    Thanks..

    1 reply

    Hi Jeanot1314,

    Could you show me the code you've written?

    thanks for the code ^^ To simplify i tried with the serial reading without processing. This work on actual version of arduino.

    void loop() {
    output = 0;
    ReadNESjoy();
    Serial.println(output);
    delay(50);
    }


    void ReadNESjoy() {
    latchlow;
    clocklow;
    latchhigh;
    wait;
    latchlow;
    output += dataread * (1 << 0);
    for (int i = 1; i < 8; i++) {
    clockhigh;
    wait;
    output += dataread * (1 << i);
    clocklow;
    wait;
    }
    }

    If you replace the loop and the setup in the program with this, you can see directly the value in the Serial Monitor. All the buttons are fonctionning, it s necessary to read the first time before the first clockhigh.
    THanks again, and now lets play!!!! ^^

    you should use an arduino nano and ditch the power cable. it would be smaller and less bulky.just a thought. ..good ible