Today, more and more devices are using motion control. From tablets to cellphones to game consoles, people are getting used to interacting with electronics using gestures. Personal computers, however, have lagged behind a bit. Unable to find a suitable gestural controller for my Windows PC on the consumer market, I set out to build my own.
I based my design on the Wii Nunchuk controller for several reasons. First, it’s a versatile, comfortable, well-designed controller; second, it‘s cheap and easy to find; and third, its native I2C serial protocol is easy to interface with Arduino. As a bonus, the connector will accept standard jumper wires, so there’s no need to cut up the cable or use a dedicated adapter.
The Arduino runs a sketch that reads data from the controller and prints to the computer’s serial port. The computer runs a Python script, which receives serial data and emulates a mouse.
Materials
- Nintendo Wii Nunchuk controller — $17; third-party controllers may not work.
- Arduino Uno microcontroller — item #MKSP11 from Maker Shed (makershed.com), $35
- 140mm male/male jumper wires (4) — item #MKSEEED3 from Maker Shed, $9/65
Tools
- Windows PC — Mac/Linux users will have to adapt the Python script.
Web Materials
- Download the Arduino IDE for Windows at arduino.cc/en/Main/Software.
- Download the ArduinoNunchuk library at github.com/GabrielBianconi/ArduinoNunchuk.
- Download Python 2.7.2 for Windows at python.org/ftp/python/2.7.2/python-2.7.2.msi.
- Download the pyserial module at pypi.python.org/pypi/pyserial.
- Download pywin32 at makezine.com/go/pywin32.
- Download the Python script at makezine.com/go/nunchuk.
MAKE Volume 33 features our special Software for Makers section covering apps for circuit board design, 3D design and printing, microcontrollers, and programming for kids. Also, meet our new Arduino-powered Rovera robot and get started with Raspberry Pi. As usual, you’ll also find fascinating makers inside, like the maniacs on our cover, the hackers behind the popular Power Racing Series events at Maker Faire.
Try your hand at 22 great DIY projects, like the Optical Tremolo guitar effects box, "Panjolele" cake-pan ukelele, Wii Nunchuk Mouse, CNC joinery tricks, treat-dispensing cat scratching post, laser-cut flexing wooden books, sake brewing, growing incredibly hot “ghost chili” peppers, and much more.
On newsstands now, by subscription, or available in the Maker Shed
Steps
Step #1: Install the software.
Next- Download the Arduino IDE for Windows at arduino.cc/en/Main/Software. Extract the arduino-1.0 folder to your hard drive. Inside this folder you’ll find arduino.exe.
- Download the ArduinoNunchuk library at github.com/GabrielBianconi/ArduinoNunchuk. Extract the ArduinoNunchuk folder to your hard drive. Open the Arduino IDE and select File → Preferences. Note the folder under Sketchbook folder and open it in Windows Explorer. Look for a folder named libraries. If there isn’t one, you should create it. Move the ArduinoNunchuk folder into libraries.
- Download Python 2.7.2 for Windows at python.org/ftp/python/2.7.2/python-2.7.2.msi and run the installer. You can find IDLE, the Python IDE, at Start → Python 2.7 or launch it at C:Python27Libidlelibidle.pyw.
- NOTE: You should not download Python 3. The script used in this project won’t work with this version.
- Download the pyserial module at pypi.python.org/pypi/pyserial. Extract the pyserial-2.6 folder to C:. Launch the command prompt window at Start → Accessories → Command Prompt. Type cd /d c:pyserial-2.6 and hit enter. Now type c:Python27python setup.py install and hit enter again.
- Download pywin32 at makezine.com/go/pywin32 and run the installer.





Is there more to this? I’d like to see the how-to and the programming code for the arduino.
Hi Neil,
This is Gabriel, the author of the article. The article that is being published in the print edition contains all the instructions needed to complete the project. I’m also the author of this Arduino library that interfaces the Wii Nunchuk. If you want to learn more about it, please check: http://www.gabrielbianconi.com/projects/arduinonunchuk/
If you’re interested in the project, I recommend that you get the print edition.
Best regards,
Gabriel Bianconi
Whenever I Try It Says arduinonunchuck not found Help me Obyone conoby your my only hope
I mean arduinonunchuck does not name a type
Hi Tristan,
I’m the author of the article. This errors occurs when the library isn’t imported correctly. The two most common causes are:
a. You didn’t place the files in the correct folder. Did you place the ArduinoNunchuk folder (not the ArduinoNunchuk-master folder) in the libraries folder?
b. Did you add #include “ArduinoNunchuk.h” to your code?
Let me know if the error persists.
Best regards,
Gabriel Bianconi
i have the print magazine and im on the last step of your article (4c) and it says that the syntax is invalid. the program (python) then highlights the 7 in the first line which you can not edit. i tried restarting everything like the article suggested but it still wont work. what am i doing wrong?
-Kevin K
Hi Kevin,
Are you using the Python script that can be found at: makezine.com/go/nunchuk ?
If yes, please send me a picture of the error. You can host the screenshot at imgur.com or any other image hosting website.
Best regards,
Gabriel Bianconi
I’m having the same problem with the “ArduinoNunchuck does not name a type”. I was wondering if I was supposed to leave the command prompt and idle open. I made sure it was in the folder and stuff. One other thing that might be the problem is when i opened up Arduino, It said ArduinoNunchuckMaster was unusable because of the dash(-), Could this have messed anything up?
Hi Matthew,
You should place the “ArduinoNunchuk” folder, not the “ArduinoNunchuk-master” folder, in “libraries”. Note that the “ArduinoNunchuk” is the folder inside “ArduinoNunchuk-master”.
Best regards,
Gabriel Bianconi
Hi Gabriel,
I enjoyed this project quite a bit, thank you. Did you author the python script used in the project? I have ported it to Linux and would like to make it available.
Thanks,
Aaron Mitchell
Hi Aaron,
I’m glad that you’ve enjoyed completing the project. I authored the Python script too. When you publish the code, let me know. I’d be interested in having a look!
Thanks,
Gabriel Bianconi
I have uploaded the script to https://github.com/ajmitc/nunchukmouse. If you like it, feel free to borrow from it and post a link to it from your project blog. Suggestions are always welcome.
Thanks,
Aaron
I am having trouble downloading the pyserial module in step 1d. It only leads to a pyserial-2.6.tar.gz file, not a pyserial-2.6 folder. Is this correct? The command prompt reply tells me “path not found”. Thank you.
Hi Gavin,
I’m not typically a Windows user, but I believe you can extract the tar.gz file using WinRAR (I did this a number of years ago). Google ‘winrar’ to find some sites that offer it for download.
Alternatively, you can go to http://sourceforge.net/projects/pyserial/files/pyserial/2.5/ and find Windows binaries for version 2.5. I haven’t tested this project with pyserial-2.5, but it may still work.
Hope that helps,
Aaron
thanks!
Hey Gabriel,
I’m up to step 4b on the project, but when I go to the makezine site, I can’t seem to right click-open with IDLE. Instead, I opened IDLE on my (Win 7) PC, file->new window, copied and pasted the text and replaced with the COM port. When I save and hit F5, I get a new window with two lines of >>> then no response from the nunchuk. I confirmed that the serial reader in Arduiono IDE is picking up the nunchuk, so I’m guessing there’s something I missing with Python? Any thoughts would be appreciated!
Hey piratebrahm,
You should save the file on Make’s website as a .py file (e.g. “nunchukmouse.py”) on your computer. You should right-click this file. Let me know if you have any other problem!
Best regards,
Gabriel Bianconi
Thanks, it turned out that I couldn’t download the .py file because I was using Internet Explorer. I tried it with Firefox and was able to get the save prompt to show up.
Hi It turns out that i also have an issue with step 3e, where it sayes ‘Open the Serial Monitor.’ I have never used the serial monitor before and i don’t know where to find it. i’ve tried useing windows search but that turned up nothing relivent. please help! ;P
Never mine i got it
For others that may face the same problem:
You can open the serial monitor by clicking the following button in the Arduino IDE: http://arduino.cc/en/uploads/Guide/serial_monitor.png
the link above doesn’t work. in the arduino ide, press Ctrl+Shift+M or select it on the tools tab.
Hi Gavin,
The link is working for me. It is however a small icon; look at the top left of the link. Thanks for the shortcut!
Best regards,
Gabriel Bianconi
on 4c ‘press F5 to run the file and wait a few seconds,’ i get this message in red, and no response from the nunchuck:
Traceback (most recent call last):
File “C:/Python27/ArduinoNunchuck”, line 31, in
ser = serial.Serial(port, baudrate, timeout = 1)
File “C:\Python27\lib\site-packages\serial\serialwin32.py”, line 31, in __init__
SerialBase.__init__(self, *args, **kwargs)
File “C:\Python27\lib\site-packages\serial\serialutil.py”, line 261, in __init__
self.open()
File “C:\Python27\lib\site-packages\serial\serialwin32.py”, line 59, in open
raise SerialException(“could not open port %s: %s” % (self.portstr, ctypes.WinError()))
SerialException: could not open port COM4: [Error 5] Access is denied.
Note the last line; How to allow access?
polease help! ;P
Hi Gavin,
Try restarting your computer; this problem is common and rebooting usually solves it. If the problem persists, make sure that your Arduino is connected on port COM4 (as described in the article). Let me know if you still get the error after trying these steps.
Best regards,
Gabriel Bianconi
thanks!
Also make sure that you read the step to close the serial monitor. I left mine open and received the same error.
Hi Matt,
Thanks for pointing this out.
In the article I mentioned that the serial monitor should be closed, but didn’t emphasize this as an important step. Maybe I should have mentioned this explicitly.
Thanks again!
Best regards,
Gabriel Bianconi
I got the serial port to read the nunchuk outputs but the Python is reading a syntax error over with the 7 in 2.7.2. Any suggestions?
Hi Austin,
Could you please post a screenshot of this error and tell how it occurred?
Best regards,
Gabriel Bianconi
hi yet again! after restarting, and i reopened the arduinonunckuck file, hit F5, and got this error message in red print:
Traceback (most recent call last):
File “C:\Python27\wiimouse”, line 49, in
analogX = int(line[0])
ValueError: invalid literal for int() with base 10: ”
please help! ;P
Hi Gavin,
This message shows that an error occurs while the Python script tries to read the nunchuk’s data. One possibility is that the values are not being reported to your computer’s serial port. When using the Arduino IDE’s serial monitor, do you see changing values? Are the Arduino board and the controller set up correctly?
Another possibility is that the data is being sent to the computer, but the Python script is not reading it correctly. Did you edit the file and add the correct port? You should recheck that you are trying to read from the right port, because it may have changed after you’ve restarted the computer.
Let me know if the error persists.
Best regards,
Gabriel Bianconi
yes, when i use the Serial Monitor, i see the values change. i rechecked that the arduino is connected to the right port, and i edited the python script with the same changes. i have the wii nunchuck properly connected to the arduoni, and i still get the error message!
thank you! ;P
*arduino
Hey Gavin,
I have to see what is being written to your serial port in order to solve your problem. The following script shows this information:
http://pastebin.com/raw.php?i=gKM0Jqtt
Can you run it (as you would with the regular script) and tell me what you see? Please paste a few lines here.
Best regards,
Gabriel Bianconi
i get (in blue)
Please set up the Arduino port.
what does that mean? i have the port working. (i can upload to the arduino)
Hey Gavin,
You should edit the Arduino port in this script too, like you did in the previous. This script shows what is being written to your computer’s serial port.
Best regards,
Gabriel Bianconi
Ok here’s what the second python script. this is about 3 seconds; it put about 5 lines per second
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type “copyright”, “credits” or “license()” for more information.
>>> ================================ RESTART ================================
>>>
20123 124 322 544 562 0 0
### 20123 124 322 544 562 0 0 ### ['20123', '124', '322', '544', '562', '0', '0']
123 124 321 544 562 0 0
### 123 124 321 544 562 0 0 ### ['123', '124', '321', '544', '562', '0', '0']
123 124 321 544 562 0 0
### 123 124 321 544 562 0 0 ### ['123', '124', '321', '544', '562', '0', '0']
123 124 322 544 562 0 0
### 123 124 322 544 562 0 0 ### ['123', '124', '322', '544', '562', '0', '0']
123 124 321 544 562 0 0
### 123 124 321 544 562 0 0 ### ['123', '124', '321', '544', '562', '0', '0']
123 124 321 544 562 0 0
### 123 124 321 544 562 0 0 ### ['123', '124', '321', '544', '562', '0', '0']
123 124 321 544 562 0 0
### 123 124 321 544 562 0 0 ### ['123', '124', '321', '544', '562', '0', '0']
123 124 322 544 562 0 0
### 123 124 322 544 562 0 0 ### ['123', '124', '322', '544', '562', '0', '0']
123 124 321 544 562 0 0
### 123 124 321 544 562 0 0 ### ['123', '124', '321', '544', '562', '0', '0']
123 124 321 544 562 0 0
### 123 124 321 544 562 0 0 ### ['123', '124', '321', '544', '562', '0', '0']
123 124 322 544 562 0 0
### 123 124 322 544 562 0 0 ### ['123', '124', '322', '544', '562', '0', '0']
123 124 322 544 562 0 0
### 123 124 322 544 562 0 0 ### ['123', '124', '322', '544', '562', '0', '0']
123 124 321 544 562 0 0
### 123 124 321 544 562 0 0 ### ['123', '124', '321', '544', '562', '0', '0']
123 124 321 544 562 0 0
### 123 124 321 544 562 0 0 ### ['123', '124', '321', '544', '562', '0', '0']
123 124 322 544 562 0 0
### 123 124 322 544 562 0 0 ### ['123', '124', '322', '544', '562', '0', '0']
123 124 321 544 562 0 0
### 123 124 321 544 562 0 0 ### ['123', '124', '321', '544', '562', '0', '0']
123 124 321 544 562 0 0
### 123 124 321 544 562 0 0 ### ['123', '124', '321', '544', '562', '0', '0']
123 124 322 544 562 0 0
### 123 124 322 544 562 0 0 ### ['123', '124', '322', '544', '562', '0', '0']
123 124 321 544 562 0 0
### 123 124 321 544 562 0 0 ### ['123', '124', '321', '544', '562', '0', '0']
123 124 321 544 562 0 0
sorry if that’s a lot of lines ; it went about 5 lines per second.
i hope this helps! ;P
Gavin,
I was getting the exact same problem. I believe it occurs because the first few times the serial port is read in, it outputs some strange digits (I’m using Windows 8). After about the second time it reads in the values from the serial port, the output starts looking good. I set up a counter to wait for the third array of input values before it starts converting them into integers for the cursor movements. I put the code I used at http://www.kwalla.com/NunchuckMouse_release.txt . There is probably a more eloquent solution, but it’s my first time using python. Hope it helps some people. It’s pretty fun once you get it up and running.
Hi Seth,
Thanks for the contribution! Your insight was very clever and could fix Gavin’s problem.
Thanks again!
Best regards,
Gabriel Bianconi
Thanks Seth, but when i copyed the script, changed the port to my arduion’s port, and rad the script in python, it poped up a window saying:
There’s An Error In Your Program:
Invalid Syntax.
and then in the script it highlights the 7 in ‘python 2.7.2′:
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type “copyright”, “credits” or “license()” for more information.
i tryed to delete the top section, but the comp. made one of those crazy erroe blips. Please Help! ;P
i have the same error, when i copy the script and run it i get There’s An Error In Your Program:
Invalid Syntax.and then in the script it highlights the 7 in ‘python 2.7.2′ any ideas how i an fix it ?
i change the port to port = ‘COM11′
Hi Fernando,
I believe that you are pasting the script in IDLE’s shell, but you should paste it in a new file instead. Save the script with Ctrl+S (or File > Save) from MAKE’s website with .py extension (no IDLE yet) and then right-click > Edit with IDLE. This will open a text-editor-like window and not the IDLE shell. Edit the port, save it again, and press F5 to run.
Let me know if this solves the problem!
Gabriel
ImportError: No module named serial
Can someone please give me a step by step for this, because evidently I am having some trouble.
Thanks in advance!
Problem fixed!
One more thing though…
Does anyone know what the mac version for the python script would be? I have everything but that (and pywin32) working fine.
Thanks!
Hey Carter,
You can use https://github.com/msanders/autopy instead of pywin32 to emulate the mouse on the mac. If you have some Python knowledge, it shouldn’t be hard to implement it.
Best regards,
Gabriel Bianconi
// What's Trending
Raspberry Pi Design Contest
Maker Faire: Day Two
Seventeen Sneaky Secret Hides
10 Things to Connect to Your Raspberry Pi
Maker Faire: Day One
47 Raspberry Pi Projects to Inspire Your Next Build
I Have a (Puzzling) Dream
// What's Shared
A better way to slice a pumpkin
DIY Nerf Darts
In the Maker Shed: Minty Boost USB Charger
100 Dollar Store Organization Ideas for Craft Rooms and Beyond
Mad’s Mouse House
Lace Princess Crowns
I Have a (Puzzling) Dream
Play the Rings of a Tree Trunk Like a Record
// Most Commented
DIY Hacks & How To’s: Get Emergency Power from a Phone Line
Resin Casting: Going from CAD to Engineering-Grade Plastic Parts
Ten Tips for Screws and Screwdrivers
Ten Tips for Better Measurement
Makers on TV: Big Brain Theory
Arduino Announces New Wireless Linux Board
Grow: A Portable CNC Router System
Build a “Boomcase” and Upcycle that Old Suitcase
Trending Topics
Get our Newsletters
About Maker Media
Subscribe
to MAKE!
Get the print and digital versions when you subscribe