Example Code

Wii Nunchuck as PC Mouse

Code and Documents

Attachment

Overview

The attached code allows you to use your Wii Nunchuck as a mouse for your PC.

Description

Using this example as a starting point, one is able to use their white Wii Nunchuck as a mouse for their Windows PC.


One novel method used in this example is the calibration process. By default the joysticks on Wii Nunchucks are not terribly accurate. As a result using it for a mouse in an uncalibrated state is a frustrating experience at best. This program actually uses an image processing algorithm to do this calibration.

First a baseline image is created with two even gradient color planes, one color plane of which represents the X-axis and the other which represents the Y-axis. In theory the pixel value in the center of the left hand edge of the image will correspond to the centerpoint of the Y-axis and leftmost extreme of the X-axis, the centerpoint of the top edge would correspond to the centerpoint of the X-axis and uppermost value of the Y-axis, etc.

In order to do the calibration, a reading is taken at each extreme of the joystick during the calibration phase. This reading is then converted to a pixel value. Using a shephard's transformation, the baseline image is transformed such that the resulting image has a distorted gradient with pixel values at each of the extremes corresponding to the measured pixel values. The remainder of the distorted gradient then represents an approximate map of the non-linearity of the joystick. Thus, a lookup table is created.

This transformation is done with the open source ImageMagick .dll, which is included in this distribution under the Apache 2.0 license.

NOTE: While running this .vi your default mouse will temporarily be disabled.

Steps to Implement or Execute Code

  1. Connect the Arduino to your PC and the Wii Nunchuck to the Arduino as outlined in the starting example linked above.
  2. Open the NunchuckMouse.vi.
  3. Change the constants on the block diagram to represent the appropriate VISA resource and board type for your Arduino.
  4. Run the NunchuckMouse.vi.
  5. Move the joystick to the uppermost position and press the "set calibration" button. Continue this process for each of the calibration points listed.
  6. Use the joystick as your mouse. The Z-button performs a left click and the C-Button a right click.
  7. Click the "stop" button when you want to return control to your default mouse.

Requirements

Software

LabVIEW 2011 or newer

LabVIEW Interface for Arduino

ImageMagick (included)

Hardware

Arduino Uno, Mega 2560 or Duemilanove

White Wii Nunchuck

Wii Nunchuck connector adapter (optional)


--------------------------------------

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
johnnydel
Member
Member
on

Great information... Thank you so much

Contributors