Wednesday, April 7, 2010

Interfacing the NES Controller with the Firefly Microcontroller

Today we successfully interfaced the NES controller with the Firefly microcontroller.

Following the instructions here and here, we programmed three GPIO (General Purpose Input/Output) pins on the Firefly to mimic the NES in retrieving the states of the buttons.

An NES controller contains seven wires. Two of the wires quite literally do nothing. They're not even connected to the 4021 serial IC in the controller. The other five wires are +5 V, Ground, Latch, Pulse, and Data. The NES performs the following operations in order to read the button states from the controller:

  1. Every 16.667 milliseconds (60 Hz), the NES sets the Latch line high for 12 us and then low again.
  2. Six us later, the NES sends out eight 12 us period pulses on the pulse line.
  3. The NES controller sends out the states of the buttons for each pulse in the following order: A, B, Select, Start, Up, Down, Left Right.
It's that simple. Check out the diagram below for a more visual explanation.
The majority of the GPIO pins on the Firefly are hidden under the mini-SD card slot, so eventually we'll probably have to de-solder the mini-SD card slot to access them.

In the mean time, we used the Firefly programmer/debugger board which provides additional access to the GPIO pins. For this experiment, we used NRK_DEBUG_0, NRK_DEBUG_1, and NRK_DEBUG_2. Note the "NRK_" prefix. We omitted that prefix initially, which prevented our program from working for several hours.

NES Controller plug connected to breadboard

Firefly programmer/debugger (left) connected to Firefly node (right)

Firefly node in action

Finally, we'll leave you with a video of our program that prints out to the serial terminal what buttons are being pressed on the NES controller. The next step of the project will be to interface the Firefly directly with the NES game console so that we can play the NES using the keyboard of the computer.


No comments:

Post a Comment