« Using Grasshopper to Control a Pan/Tilt Servo | Main | Testing the Grasshopper G-code Writer for 2D Shape Milling »

Using a Wii Nunchuck to Control Grasshopper

Posted on September 9, 2009 by Registered CommenterAOP in , | Comments2 Comments



The video above demonstrates how we can feed a stream of live sensor data (in this case, I chose to use the accelerometer data from a Wii nunchuck) into Grasshopper to control a parametric model.  I'll be the first to admit that this is not a 'new' demo... In fact, this demo was heavily inspired (in concept) by this video that was created in 2008 that shows how a Wii nunchuck can control a mechanical arm in 3D Studio Max . 

However, my own research was primarily concerned with understanding how to get the sensor data into Grasshopper (and how we can also reverse this flow of information to get Grasshopper to control servos, motors, LED's, etc...) in order to create more complex and sophisticated digitial and physical environments.

Before we get too far, I'd like to say thank you to Robert Lee for his insights on how to setup the VB.NET listener.

Now onto the more technical aspects.  Let's start with the hardware setup.  I am sending the accelerometer data from the Wii nunchuck to an Arduino Diecimila micro-controller which allows me to format the data into a block of code that the Grasshopper VB.NET listener will be able to understand.  I could have spliced up my Wii controller to connect the various parts of the circuit to the appropriate pins on the Arduino board, but I decided to buy a wonderful and cheap little adapter that simplifies the entire process.  You can buy your own from these online stores:

- FunGizmos.com. International shipping for $1 more.
- Tinker.it (UK)
- Little Bird Electronics (Australia)
- Sparkfun. Ships domestic & internationally. Be sure to order header pins too!
- Freduino.eu (EU)

Now, that we've properly connected the Wii nunchuck to our micro-controller, we'll need to program our Arduino board so that it can read the incoming sensor data and send it over the serial port.  For this, I have used a custom built library written by Tod E. Kurt that was designed to help the communication process between a Wii controller and the Arduino.  You can download the "nunchuck_funcs.h" library from his website at: http://todbot.com/blog/.  You can also get the source file needed to program your own board by clicking on the links below.

On the Grasshopper side of things, we need to create a custom VB.NET listener component that can read a string of data coming in over the serial port.  The nice thing about this listener is that it will display any string that is being sent from the Arduino... What you do with that string is another matter... but in this example, we are feeding a string of information that is separated by a comma ",".  The comma will be our delimeter which essentially tells us where to split the string so we can extract the integer value on the left side of the comma (which cooresponds to the X-value of the accelerometer) and the integer value on the right side of the comma (which will cooresponds to the Y-value of the accelerometer). 

Once we have successfully read the data from Grasshopper, we can connect a Timer Component to automatically refresh the solution at a given time interval.  In the video above, I was able to refresh the sensor data at 50 millisecond (the smallest time interval that is currently available in Grasshopper) without any lag or delay.  You can download both the Rhino file and the Grasshopper definition needed for this demo by clicking on the links below.

Source Files:
Wii Nunchuck to Grasshopper.pde (Right-click to 'Save Link As') This is the Arduino source file.  This file was written for Arduino IDE ver. 0017.

Wii Nunchuck to Grasshopper.3dm (Right-click to 'Save Link As') This is the Rhino file that accompanies the Grasshopper definition.

Update: Please use the new FireFly toolbar to facilitate the Grasshopper to Arduino connection.  Click here for more information.

Note: These documents are in the public domain and are furnished "as is". The author, Andrew Payne, makes no warranty, expressed or implied, as to the usefulness of the software and documentation for any purpose. This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License. http://creativecommons.org/licenses/by-sa/3.0/us/

PrintView Printer Friendly Version

Reader Comments (2)

Very interesting interface exploration, opens up a wide range of possibilities.

Nice work!

Alessio

09-10-2009 | Unregistered CommenterAle2x72

this is super awesome~~I'm thinking can it be made to use in applications like zbrush or 3ds max...so we can model things more convenient,more intelligent,mostly more fun~~just like game paddle,it could be fantastic~

06-4-2010 | Unregistered Commenternim
Comments for this entry have been disabled. Additional comments may not be added to this entry at this time.