MM Arduino NES Controller

While putting together a video for my Kickstarter project, I realized what the video really needed was a good hook. I decided to create a set of fun projects that would demonstrate what you could do with MezzoMill in a week’s time.

Using MezzoMill, I wanted to create a circuit board that looked and acted just like an NES controller. I knew I could make the copper regions act like buttons through the use of capacitive sensing.

So, I began by scouring the web to see if someone had already created some code that would allow the Arduino to control the NES. I found several sources on how to use the Arduino to detect which NES controller buttons had been hit, but I found surprisingly little information on how to use the Arduino to emulate the controller itself. So, I decided to reverse engineer the NES controller protocol.

Files to Download:

Eagle Designs

Arduino Sketch

Data from Reverse Engineering

Reverse engineering the NES controller protocol seemed easy enough at first. I discovered that one of the wires carries a strobe signal (for Mario, the strobe runs at 60 Hz) that is followed by a series of clock pulses on a different line. There are eight clock pulses and each pulse correlates to a button on the controller. The data line is driven high when a player presses the buttons; the controller pulls the data line low for the time during the clock pulses that correspond to each button.

Next, I designed an NES-like circuit board in Eagle.

I printed the design using MezzoMill.

I then discovered that prototyping and printing the circuit board with MezzoMill was the easy part. I soldered the board together and started playing with the code. Because I wanted to share the design with others, I began coding in the Arduino IDE. I found that while the polling rate for the strobe signal is relatively slow (60 Hz), the response time to control the data line needed to be blazing fast. I kept hoping that the various built-in Arduino functions would be fast enough, but it just wasn’t possible to use them. Ultimately, I had to break down and use the low-level bit-masking approach.

It took a lot longer than I originally imagined to pull apart and optimize the code so that it would be truly deterministic. You should really take a look at the code, it’s pretty hairy. I did a few things to make it work. First, I reduced the polling time of the buttons to only do half of the buttons per polling iteration of the strobe pulses. Next, I loop unrolled the code that controls the data line’s response to the clock line so that it would be incredibly fast. Finally, I tweaked the code to have as few instructions as possible during the time-sensitive code region by pre-computing a few numbers. And finally after all of that work... Success!!! I had created a working NES controller from an Arduino! Here is a video of me using it.

There definitely might be a more optimal way to achieve what I was trying to do, but I was still pretty satisfied with the results. While playing with my Arduino NES controller, I only discovered one issue. Every couple of thousand pulses I would miss one, causing Mario to pause. Regardless, I had a blast playing with it and reminiscing about my youth.

I’ve included the raw data and my code so that you can test your hand at a better approach. Let me know what you find.

Note: No NES controllers were harmed during the making of this project! I used a new NES extender cable, which is what I attached to my board.