In this short article Frank provides example code to use the Nintendo Wii Nunchuck as a mouse. In this previous article we looked at the Nunchuck and an adaptor board I purchased from Todbot. I also mentioned making a mouse device using the Nunchuck using ideas from Bernard’s Accelerometer Based Mouse article. Frank has done the hard work to make this easy for us.
This article was submitted by Frank Zhao as part of the “Hobby parts for articles” program.
Hardware and software so that you can use a Wii Nunchuck controller as a computer mouse.
This example software uses the joystick for mouse movements. Z button for left click, C button for right click.
Tilt via the Nunchuck accelerometers are used for mouse wheel scrolling, middle clicks, and also the "back" button in Internet browsers.
An Arduino microcontroller provides the hardware interface, reading data from the Nunchuck and sending the measurements to the PC via a serial port. The source code package includes a project file for use with the Arduino IDE.
Autoit is used on the PC side to convert the serial data from the AVR microcontroller into mouse movements and key presses. Autoit is a freeware BASIC-like scripting language designed to simulate keystrokes and mouse movements in Windows. The Autoit source code and executable are included in the package below.
Update: Frank looked over his code and made improvements. The zip files linked above has been updated with his new files. The new code works with the Arduino. If you have already picked up the files, ditch what you have and get the new stuff.
Update2: Frank provided a great code breakdown for the code used in this article. It’s posted as a new article here.
Links to related information.