Tag Archives: Arduino

NES controller for PC via Arduino

I’ll be updating the 2.x Laser build soon, but I got a little sidetracked while working on it.  The laser is going to have a manual trigger for calibration purposes.  I decided to use a NES zapper because, well, I can.  So in testing the zapper as a switch I added some LEDs and made this (sorry for potato quality pictures):




Then I got really sidetracked with how the NES controller works and decided to mess with it.  Using the same timing that the NES uses to interface with the controller (found here), I wrote an Arduino sketch to get the input.  The shift register will respond to a wide range of timing on the pulses, but I decided to use the exact timing that the NES uses so that I can try to use other methods of input through the Arduino to the NES (that will be a future project, voice control? kinect?).

I also found this post where he uses a library someone created, but that seems kind of unnecessary.  Besides, the sketch I wrote was made to work with a program written in processing for converting the serial output to keyboard commands.


This is a better picture of the pinout.  What was labeled “Pulse” in the other link is “Clock” here, and “Latch” is “Strobe”.

Now here’s how to make it work as a controller for an emulator or anything else. this instructable explains how to use an N64 controller via Arduino and a program written in processing.  In the instructable, he claims that if you are using a newer version of processing (newer than 1.0), that you need to import a few extra packages.  I found that with processing 2.2.1 in addition to the packages mentioned, you also need to import the KeyEvent package.  Here’s a link to the same program with all the necessary packages imported.


It is possible to just stick some wires in the NES controller output socket and go straight to the arduino.  I found this method to result in somewhat loose connections so just to be safe I used the connector from the NES itself and wired from there (the breadboard looks more cluttered than it should because I was moving stuff around).


The processing program was modified from one that was originally made to interface with a gamecube controller.  Instead of modifying it again to make it work with an NES controller (we’re going backwards apparently), I just left it as it is and made the NES controller output from the Arduino match the format of the N64 controller output.  My arduino sketch is here:


Run this arduino sketch, then run the processing sketch and make sure the serial port is the same: “You might need to change the line String portName = Serial.list()[1]; to match the your Arduino, it should be either Serial.list()[0]; Serial.list()[1]; or Serial.list()[2];”   This should result in a working NES controller for your computer.

Of course after I do all this I find an easier method: https://gist.github.com/j-mcc1993/8202522

But, my effort was not entirely wasted.  The keyboard library only works on the Arduino Leonardo, Micro, or Due apparently so it wouldn’t have worked on my Uno anyways.  Other methods that I have seen involved updating firmware and more complicated things.  The method I have here is pretty straightforward and easy.

And now I made an Instructable for it so people can actually find it if they are looking: http://www.instructables.com/id/Using-an-NES-controller-for-emulators-with-Arduino/