ADVENTURES IN PROPELLER PROGRAMMING
■ BY JON WILLIAMS
Wii WILL ROCK YOU
The design and development of effective man-machine interface devices is an
incredibly difficult task. And, yes, I'm speaking from experience — a long time
ago in a galaxy far away, I used to help design sprinkler timers that were
supposed to be simple enough for anyone to use. The good news for those of
us that are hardware and firmware junkies is that the multi-billion dollar
gaming industry has the resources to create really cool widgets, and with a
snip snip here and a bit of code there, we can take advantage of their efforts.
For me, one of the coolest and most cleverly designed gaming accessories on the market today is the Wii
Nunchuk controller. This little beauty fits very comfortably
in your hand (see Figure 1) and has an analog X/Y joystick
(eight-bit values), two active-low buttons, and a three-axis
accelerometer (10-bit values). The best part? The Wii
Nunchuk costs about $20 and is easy to connect to any
microcontroller using I2C. Of course, I'm going to show
you how to connect it to the Propeller.
If you do an Internet search on "Wii Nunchuk," you
will find dozens of sites with instructions on how to
connect it to the Arduino — I guess this is what Fred Eady
meant by the "Arduino effect." As I'm not an Arduino user,
I was initially confused when adapting code samples
written for that platform; it all came down to the way
Arduino does I2C (versus the rest of the world): the
Arduino requires the slave ID to be shifted right by one
bit. No worries, with a little reading on how the Arduino
does things I got it figured out and using the Nunchuk is,
in fact, every bit as easy as everyone says. Let's jump in.
■ FIGURE 1.
Nunchuk in hand.
GETTING CONNECTED: HARDWARE
I don't actually own a Wii console; again, I bought the
Nunchuk when I learned it uses I2C communications. I've
done lots of work with I2C. For my projects, then, I simply
hacked off the connector and soldered male pins to the
wires, protecting each with heat shrink tubing. If you do
have a console and don't want to take this action, you can
find many companies offering adapters.
The Nunchuk has four wires for connecting to a host:
Yellow: SCL (pin 28 on the Propeller)
Green: SDA (pin 29 on the Propeller)
Figure 2 shows my hacked Nunchuk cable and labels for
each of the wires. The Propeller uses P28 and P29 to connect
to the boot EEPROM, so that's what I'm using with my Nunchuk.
These pins are free after the Propeller boots up so it makes
■ FIGURE 2.