Some weeks ago Andy Payne from Lift Architects announced the release of his first version plugin Firefly which is a specialized set of tools dedicated to bridging the gap between the Arduino interface and Grasshopper , currently the plugin has two components one for receiving data coming from sensors and the other to send parametric data from grasshopper to some sort of actuator via Arduino.
I think Firefly is a great tool for prototyping projects that involve sensors and actuators , because before you actually build it, with this tool you can first model a digital muck up to see how your project elements will behave with real sensor data, so then you can port that same logic to build your real project.
Here is an experiment I made sending data from a photoresistor to Grasshopper to create a Responsive Structure that reacts to the degree of light of a physical space in real time.
What you need:
(sorry about the crappy picture I had to use my webcam)
You have to start by making your Arduino Hookup and writing a code in the Arduino environment so you can retrieve the value of the photoresistor which measures the amount of light in a room and then send it to the board , in this case I wanted that when the amount of light is low an LED started to turn on and that the intensity of it also varies depending the amount of light .
So for the hookup the photoresistor and 1K resistor are hooked up in series. Arduino +5V goes to the photoresistor and ground goes to the 1K resistor. The junction where the photoresistor and the 1K meet is where Arduino pin #5 goes (picture Above).
Next step is write a code in the Arduino environment were we take an analog reading being send from the photoresistor to our board and then send that value to our output which in this case is digital pin11 which is the position of our LED , I made some annotations to the Arduino code to make it more easy to understand.
The last part would be porting the data from arduino to Grasshopper , here is were Firefly comes into action , actually is very easy to use once you install the plugin you´ll se two more components added which are the Serial Read and Serial Write.
In this case as we want to import data from Arduino we are going to use the Serial Read component which has three inputs , the first one is to define if we want the port that transfer data open or closed, you will like to have an integer slider that goes from 0 to 1 to control this easily, remember to have it always at cero before yo start the timer, the second input is for indicating the computer the serial port you are working on which in my case was COM3 but it depends on the serial USB ports of each computer you can check with which port you are working by opening your Arduino code , then going to the menu Tools and were it says Serial Port you´ll see the one that the Arduino board is using , the last input of the component is the Baud Rate which controls the speed and it should match the one you are using in Arduino apparently the standard is 9600 so I used that one.
Besides that the rest goes pretty straight forward using the common tools of Grasshopper , have I also included some notes in the definition to help you out.
As always let me know if you have any problems the best way to catch me is by twitter @Rodrigo_Medina
Grasshopper Definition:Arduino + Firefly experiment.ghx