WII Nunchuk Swordfish Module

Coding and general discussion relating to user created compiler modules

Moderators: David Barker, Jerry Messina

Post Reply
Jon Chandler
Registered User
Registered User
Posts: 185
Joined: Mon Mar 10, 2008 8:20 am
Location: Seattle, WA USA
Contact:

WII Nunchuk Swordfish Module

Post by Jon Chandler » Sat Feb 12, 2011 5:04 pm

I'm working on a Swordfish module for the WII Nunchuk. This is a great device! For less than US$20 (or even US$10 for a clone) you get a nice handheld package with a 2-axis analog joystick, a triaxial accelerometer and 2 push button switches, all connected over an I2C interface. The Nyko Nunchuk I have also has a "rumble" motor built in to provide feedback, but I haven't been able to find any information on how to enable it.

With a little help from the Bus Pirate, I've got it interfaced to Swordfish and I'm in the process of writing a module to make using it easy. The 3 accelerometer channels provide 10 bit data with a maximum range of a few G. The joystick provides X and Y position as 1 byte each.

The routines I have in the module so far are:

StickZero: returns the x and y values when the joystick is centered so that the zero position is known.

StickCalibrate: returns the minimum and maximum X and Y values so the range of the joystick can be scaled.

StickDecode4: returns a byte value representing the joystick position in terms of north, south, east of west. The value can be latched, so it represents the last ordinal direction or non-latched so it represents the current position (i.e., output is on only when stick is held in position).

StickDecode8: returns a byte value representing the joystick position in 8 positions around the compass. As above, may be latched or unlatched.

I'm debating about a routine to return stick magnitude and angle. This would probably require floating point arithmetic. I'm not sure how useful this would be.

When it comes to the accelerometers, I'm not sure what calculations I want to include yet. -1 G returns a value of about 70, +1 G returns a value of about 189. These values are easy to measure by making each axis vertical - one direction is +1 g, and rotated around is -1 G thanks to the Earth's gravity. I guess a calibration routine and scaled results would be a good first step.

So what can you measure with an accelerometer? These accelerometers respond to the static force of gravity, so it can be used as an inclinometer. When the accelerometer is tilted with respect to the Earth, the measured level will drop in one axis and increase in another. It's a simple trig problem to determine the angle.

What to know how steep the hill you are biking up or down is? :)

Reporting calibrated G levels in all three axes would be a good feature too. You can see how many "G's you pull" accelerating away from the stoplight in your 1973 Ford Pinto! Probably would be more interesting to log the G forces on a roller coaster ride, especially one of those where you're upside-down!

I'd like to hear your ideas on how you might use a WII Nunchuk so that I can make the Swordfish module as useful as possible. I'll be posting it as soon as I make a little progress with presenting the accelerometer readings.

By the way, the nunchuk is a 3.3 volt device. It can be used with a 5 volt PIC with a little extra effort but this is a great application for a PIC18F25K20.
Jon

Check out the TAP-28 PIC Application board at http://www.clever4hire.com/throwawaypic/

wannaBinventor
Posts: 10
Joined: Tue Feb 08, 2011 10:51 pm

Post by wannaBinventor » Fri Feb 25, 2011 3:37 pm

Very cool thing you're working on there.

I also think the Wiimote has a radio transmitter and an IR transmitter in it.

Have you been able to decipher anything with that? Would there a way to hack the remote in such a way that you could use it as an actual control device for wireless applications directly without having to run it by wire to a uC and then to another transmitter controlled by your own uC?

Also, I'm curious where you tapped into the remote to get the signals for the accelero, buttons, and joystick.

Jon Chandler
Registered User
Registered User
Posts: 185
Joined: Mon Mar 10, 2008 8:20 am
Location: Seattle, WA USA
Contact:

Post by Jon Chandler » Fri Feb 25, 2011 5:01 pm

The Wii-mote itself is Bluetooth and there are PC applications to access the sensors. I don't know how difficult it would be to use it with a micro over Bluetooth.

The nunchuk connects to the Wii-mote using a cable and it speaks I2C at 3.3 volts. Some people have used it on 5 volts without an immediate problems but some of the components are only rated for 3.3 volts so this probably isn't a great idea.

All of the nunchuk's sensors (3-axis accelerometer, 2-axis joystick and 2 push-button switches) are available by reading 6 registers on the nunchuk. I'll get my module polished and publish it soon.
Jon

Check out the TAP-28 PIC Application board at http://www.clever4hire.com/throwawaypic/

Post Reply