Archive for December, 2012

Teensy 2.0

The Teensy 2.0 showed up in the mail today!  Here it is, nice and small:

Teensy Test

It took me less than two hours to get a working gamepad in both Windows and Linux.  I had found some code online that modified Teensy’s keyboard example to be an SNES gamepad, so a lot of the work was already done.  However, the NES and SNES controllers have a chip that communicates over 4 wires to the console using a simple protocol.  (I’ll include some fun trivia about the NES/SNES at the end of this post). This code I found used that protocol to communicate with the chip inside the controller.  In order to make my gamepads all consistent and not have to worry about timing with the NES chip/protocol, I stripped all of that out and modified it to manually read from the Teensy’s input pins, one for each button.

Once I got it all working, I could plug the USB port in and have a gamepad with 2 axis and 8 buttons (just like the SNES).  And I verified that I could use whatever name I want the gamepad to show up as:

Teensy Gamepad Test

The only thing left was to test that it can actually fit inside an NES controller, and it does, sort of.  It is maybe 2 sheets of paper too tall, which will probably be okay as long as I can make sure the wires soldered into the holes do not protrude any.  Otherwise, I will need to remove the USB connector from the Teensy and solder the USB wires on directly.

Next, I’ll be working on the base code I will use to create each gamepad.


Fun Nintendo Controller Trivia:
The NES and SNES controllers actually use the same exact protocol for communicating with the console.  It is very electrically simple, and supports infinite buttons.  The console just keeps querying each button until its done.  The first eight buttons on the SNES are the same as the NES controller: Up, Down, Left, Right, Select, Start, B, and A.  So if you connected the wires of an SNES controller to the NES, it would actually work.  The NES queries 8 buttons and then stops.  The only downside is the placement of B and A on the SNES controller don’t lend well to pressing the B and A buttons simultaneously with your thumb like you do in Super Mario Bros., etc.  The SNES console queries the additional X, Y, L, and R buttons after the first eight.

Case and Controller Solutions

Caleb has started playing Excitebike!  That, and I had a week off from from work so I started working on things again.

First, the case.  I had previously thought that the motherboard was not going to fit without removing the RESET button from the front of the NES.  I thought it was off by about 1/8 inch or so, because the top just barely wouldn’t close, and looking inside I saw the processor fan right up at the top so I figured it wouldn’t work.  While trying to calculate how low I needed to go, I discovered that there is indeed room, and it was actually a piece of the inside of the top that was bumping up against the DVI connector on the back of the motherboard.  I removed that piece on the inside, and it just barely closed!  So I get to keep the RESET button.  Everything now just barely fits.

One thing I had not foreseen that I also just discovered, is I can’t mount the motherboard where I wanted it at the far side.  This is because the mounting standoffs would be going through the existing rubber feet on the bottom of the NES.  I’ll have to move it over a little bit, and that cramps all the room allocated for the fans, power supply, and cords.  After a lot of mucking around with this ‘puzzle,’ I believe I finally found a way to stuff everything in there and route the cords.

Now about the controllers: previously I thought I would have to use different solutions for every type of controller, as one chip in all controllers meant I wouldn’t be able to tell them apart.  Well, when I was searching for a very simple single USB button to connect the RESET button to, I came across a microprocessor that I think will solve all my troubles: The Teensy 2.0.  At $16, it is only $1 more than I paid for the JoyWarrior (today the JoyWarrior is $4 less).  But the JoyWarrior also required a few extra components, and tested my patience soldering everything together in such a small space.

The Teensy is a C programmable microprocessor that comes with libraries and sample code to fully support USB.  On top of that, it’s extremely easy to load firmware on and use. The JoyWarrior required no programming, but fortunately, coding is something I’m good at.  Using their examples, I can easily create my own “gamepad” base program.  Then, from the base program, I simply have to add whatever buttons I need, and can even add analog sticks, analog triggers, etc.  The best part is, I can name how the gamepads show up in Windows, for example, “CES NES-pad,” “CES SNES-pad,” CES Genesis-pad,” etc.  With names like these, I can pop up a message when an SNES game is started saying to plug the controller in if no compatible controllers are already in.  I can also map every button just how I want it. This way there will be no need to re-configure buttons on the NES emulator for an SNES gamepad, because SNES Y and B will be the same Windows buttons as NES B and A, respectively.

The other great thing about Teensy is it requires no other components, and the button inputs can be configured to use pull-up resistors.  I had to scratch all the pull-up resistors off from the NES gamepad for use with the JoyWarrior.  With the Teensy, all I have to do is connect one wire from power, ground, and each button hole on the NES board to a much easier to solder hole on the Teensy (my biggest headache with the JoyWarrior was trying to solder the wires to its pins).

Another Teensy will also live inside the case and connect to the RESET button.  This one I will probably program to show up in Windows as a keyboard, and when the button is pressed it will send something like Ctrl-Alt-Shift-X, which my menu software will use to close the current full-screen emulator and return to the games menu.

My Teensy is on its way in the mail – I’m looking forward to playing with it.


WordPress theme by LeadCamp, Inc