Wednesday, April 11, 2012

Super Mario Kart Cycle



I love Super Mario Kart and the SNES in general.


When I was young I used to think about how much fun it would be to play SMK with a real bike. Now, many years later, we finally have the ability to create such a thing without a lot of very specific knowledge and tools.

Some of the things I used:
Arduino microcontroller (UNO)
A few transistors
Some pushbutton switches
A few resistors
A 2$ photo interrupter
An SNES controller
A very old stationary bike
A breadboard


Nothing there is overly expensive and none of it should require more then a little time and googling to figure out how to use. That said I'm not particularly experienced with electronics so there may very well be better ways to do some of this. (Actually I've found a few things I'd like to correct myself quite recently)

This was my 2nd Arduino project, the first being an n-back test game which I'll make a post about in the future (https://github.com/statuswoe/nBackGame).

There are two separate parts to this project, the first is finding an easy way to output from Arduino into the SNES and the second is having the Arduino recognize when the bike is being pedaled and when the buttons are being pressed.

Arduino to SNES

The SNES controller isn't particularly complicated, there looks to be a multiplexer and a couple resistors but little else. I wasn't able to find a really good diagram though. There is a description of the pinouts here: http://www.gamesx.com/controldata/snesdat.htm but I wasn't really interested in playing with a clocked signal when I didn't have to since I had an old SNES controller that I wasn't using. All I needed to do was put an NPN transistor across the points that the buttons contacted and I can fake a button press by applying voltage to the base pin, this was pretty simple.

My soldering is getting a little better, couldn't get much worse.


What I ended up with is a series of input pins that I plugged into my Arduino board and when I set them high the associated SNES button is triggered.

I mounted the project board and the modified controller into a small toolbox which was the cheapest container I could find that fit them both. The SNES connector comes out of one end and the Arduino connector comes out of the other. One of my goals was to make the SNES controller adapter entirely separate so that I can use it for other games/peripherals.




Bike to Arduino

The Handlebar buttons are pretty self explanatory. I used momentary push button switches that are on unless pressed just because I had some on hand. Because I'm running them into the Arduino I was able to invert the state in software.

The fun part was finding a simple way to track pedaling. I found a few caveats:
- Because the wheel doesn't stop when you stop pedaling and there are no real breaks I didn't want to use the wheel to track speed. I need to know when the user stopped pedaling.
- Running wire onto the pedal would be a pain because the pedal rotates relative to the bike so I'd need to set up brushes or something that wouldn't twist up when you pedal.

Because of these issues I decided to mount a photo interrupter next to the sprocket and have something attached to the sprocket at regular intervals that can pass through the interrupter and trigger the state-change. I ended up using 6 small pieces of playing card to do this.


Once the photo interrupter and buttons were hooked up to the Arduino I wrote some quick code to read the inputs and set the appropriate outputs to the SNES Controller adapter. The code is available here(and could use some polish).

I have the code and SNES Controller adapter set up to accept up, down, left, right, A and B, but I don't have the up/down hooked up to the bike yet because I'm not satisfied with the toggle switch I was going to use for it.

So in the end we have The Bike pushing data into Arduino, which does a little logic and sets some appropriate outputs which saturate the transistors to press the appropriate button.





EDIT:
Maicol asked for some more info on using transistors to control digital buttons, so here's a better image of that part of it, click on it for full size. The common ground is the red blocks, the blue side is the per-button input from the arduino (high to simulate the push).  The NPN transistors bridge the path from the (green block) SNES controller wires to ground which the SNES reads as a button having been pressed.
The SNES is a bit odd in this sense, what you really want to do if you're using this for any other sort of input is put one side of the NPN transistor on the wire leading into one side of the button and the other side of the NPN transistor on the wire coming from the other side of the NPN transistor. You can then apply a charge to the middle pin of the transistor and it will act as though the button had been physically bridged. Hope this helps.


4 comments:

Sophronis Mantoles said...

Super cool!!!

Sam said...

Wow nice idea to work more on exercise. I didnt think that you can use Online Car Games for exercise.

pharmacy said...

Super mario kart is one of the best games ever made theres no doubt about it!

Maicol Zoia said...

Hi Man! i want to do the same thing witch a keyboard pcb controller for the pc. Can you explain me how did you link the button controller with the arduino? with the transistor? i can't do this step :(