Using a Wii Nunchuk to Control an Atari

Posted: May 14, 2012 in Arduino
Tags: , , , , , , ,

Over the last semester, Will Byrd, myself, and others have been doing various Atari hacks. These have included things like building a ROM dumper, writing custom ROMs, breadboarding an Atari, and the hack I’m going to talk about here: using the Wii Nunchuk as an Atari controller.

The Atari has two types of controllers. One is a joystick, and the other is a paddle. Both have extremely simple interfaces. The joystick is basically five switches. There is one switch for each direction, and another switch for the button. The paddle also has a button, but also an analog twisty control. The twist control is actually just a 1 MΩ potentiometer. The Atari controller port is a standard DB-9 connector, like is used for PC serial ports. The joystick uses a total of 7 wires (five for the controls, one for ground, and one for +5 volts), so only one joystick can connect to the DB-9 connector. On the other hand, the paddle only needs one wire for the button, one for ground, one for +5 volts, and one for the potentiometer output. Because of the fewer signals, the Atari designers allowed for two paddles per port, which allows for up to four players in a single game. We found the pinout from pinouts.ru very helpful in figuring all this out.

Emulating buttons (and the joystick, which is really just four buttons) with the Arduino is fairly simple. In order to press the button, we need to do the equivalent of shorting the joystick wire to ground. In the Arduino, this is the same as doing a digitalWrite of LOW on the corresponding pin.

At first glance, doing the knob on the paddle shouldn’t be too tricky either. After all, it’s just an analog control, so we can use the analogWrite command, right? Sadly, this is not the case. The Arduino’s PWM pins are still digital; they just turn on and off very quickly, and the percentage of the time that the pins are high is how we represent analog values. The Atari paddle uses a potentiometer to vary the voltage instead. The Arduino has no way to do this natively, so we must use something called a digital potentiometer. Digital potentiometers are like regular potentiometers, except you can control them programmatically. We selected an Analog Devices AD5242 digital potentiometer, which is controlled using I2C. I found deciphering the protocol from the datasheet a little tricky, but I’ve posted the code on my Github.

To interface with the Wii Nunchuk, we used the WiiChuck adapter, which also includes sample code. The Nunchuk also communicates using I2C, so we can wire the WiiChuck adapter and the AD5242 on the same I2C bus. This took a slight modification to the WiiChuk code to make it work with other devices at the same time.

After some fiddling around with all of this, we finally got it working. Here’s a video:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s