« TEX-FAB | Main | Using a Wii Nunchuck to Control Grasshopper »

Using Grasshopper to Control a Pan/Tilt Servo

Posted on September 12, 2009 by Registered CommenterAOP in , | Comments4 Comments

The above is a follow up video to the posting I made last week showing how we can use a Wii nunchuck to control parametric data in Grasshopper.  However, in this video, we are looking at reversing the flow of information and using parametric data (numeric sliders in Grasshopper) to control two different servos.  In this case, one slider controls the panning servo, while the other controls the tilting servo.

In this demo, we need to set up two different files.  The first is the Grasshopper definition (written for ver. 0.6.0019) which sends the numeric slider information over the serial port via a custom VB.NET component.  This component formats the two variables (the pan slider and the tilt slider) into a string that is separated by a comma.  This comma will serve as our delimeter when we read the data over the serial port on the Arduino side.  You can download the Grasshopper source file below.

On the Arduino side, we first have to understand that serial communication receives individual bytes of information as a stream.  This can become complicated because most data types are more than 1 byte... so you have to understand the data type and then convert it on the Arduino side to the format you are looking for.  In this example, we are reading a string into the buffer and then working through each individual byte until we reach our delimeter (don't forget about the comma).  Once we reach the comma, we pass the data that has been read into the buffer into a variable that ultimately controls one of the servos.  We do a similar process for the second set of bytes after the comma.  The Arduino source code can also be downloaded below.

Again, I'd like to thank Robert Lee for his explanations and insights on how to set up this demo.

Source Files:
Grasshopper_controlling_PanTilt_Servo.pde (Right-click to 'Save Link As') This is the Arduino source code needed to program the micro-controller.  This file was written for Arduino IDE ver. 0017.

Grasshopper to PanTilt Servo.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 (4)

this is like a nerdgasm, so jaelous. Just wondering how this could be implemented in the real world
good job, btw

10-12-2009 | Unregistered Commenterd

Nicely done, this is amazing!
I was wondering if you were able to use the "z" and "c" buttons as well as the joystick, I've been trying to make these work in grasshopper for a while but haven't been able to do so, would you have any tips for me?

11-15-2009 | Unregistered Commentern

...never mind, got it to work!

11-15-2009 | Unregistered Commentern

Hi thanks a lot for this information it was exactly was i was looking for, I have got my Arduino Board and a servo motor , but I have seen different diagrams on how to set them could you post a picture or a link were it shows the correct way to do it , thanks a lot again

01-21-2010 | Unregistered CommenterRodirgo Medina
Comments for this entry have been disabled. Additional comments may not be added to this entry at this time.