NES Controller --> PC Joystick




Eh, something to do

After the door display, I was still board and had some more creative energy. I hadn't worked on my Senior Project at all, but didn't think about that. However, I didn't have my nintendo at school, but had some Microchip PICs on my hands and wanted to stop having to use the keyboard with the emulator. Challenge: interface a NES controller to my computer.

Protocols and Hardware

I ended up going with the Joystick idea. Although there are enough pot inputs in a PC joystick port (4) for two control pads (2x2), there aren't enough buttons (4) for two NES controllers (2x4). So this was a single joystick solution.

I had thought about using the keyboard system... making a pass-thru device that could also over-ride and act as the keyboard, but two impediments were (a) the emulator I was using only allowed 3 buttons pressed at a time, so even 1 player gameplay would be negatively affected, and (b) the Basic Micro interpreter wasn't quite up to par speed-wise for that. I'd have to upgrade (their Pro compiler, as an option, can produce assembly code for ops as well as implimenting an interpreter where space is a conscern. It also costs more $$$). Since both the joystick and keyboard ports provide power, such wasn't a conscern. In the end, the joystick option was easiest.

Two controllers were purchased from a local video game and movie shop. One was saved as a "control" subject, the other was neutered. Interesting and annoying note about the wires in the controller. The NES controller cable has 5 wires, each with its own color-coded insulation. Inside is copper foil wrapped loosely around some string. This yeilds a cable that can withstand much abuse (tension is along string, not wire. bending may eventually break foil, but the layers of loose foil will still remain in contact) but that is very VERY hard to solder. i ended up doing a weird thing with the cable and some electricaly tape, folding it over to minimize stress on the solder joints. I think I had to re-solder a wire 6 times over the whole process.

Compiler issues

Coding seemed straight foward. 4 I/O lines were wired to the joystick port, and are only active low in software. Buttons. 3 wired to X, 3 wired to Y, active high. Impedances are 2k, 50k, and 100k, to allow 3 different positions on each axis. The NES controller is just a d-latched shift register with 8 buttons. That's easy to read. Piece of cake.

Some complications encountered were compiler bugs that caused incorrect pause timings (Basic Micro released an update) and the fact that my first write of the software could only scan the controller 15 times a second. That amounts to a maximum tap speed of 7 times a second! Only 3 or 4 times a second reliably.

With some modification, I've gotten the speed up to about 90 to 100 scans per second (temperature dependant. A scan takes longer if a button was pushed or released between scans). The project has been pronounced done.

Source code: nes.bas

Pictures: _1_