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.
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