Interface Rhino with Arduino




This is my first post on Arduino with a grasshopper. It has many exciting features that can be used by the design community. As a designer, we use rhino to generate most of the CAD surface. Adding physical interface could take that to one step hight. Eg, You can design a hand grip by interfacing multiple force sensors on the object and grasshopper can create 3D cushion design based on the force applied. (It is work in progress I will share in a while). To begin with the interface of Arduino with rhino, first, we need Rhino > Grasshopper > Firefly > Arduino.  

The ingredient you need during this tutorial
1) Rhino with grasshopper and firefly installed. 
    You can download a firefly from its website with all details. including examples.
2) Arduino Uno/ Nano
3) interface LEDs/ resistance / breadboard.

To start with,
Prepare Arduino to talk with a grasshopper.
A folder that you download from the firefly website will have Arduino file name, Firefly_Firmata in the Arduino Code folder. copy in your Arduino IDE and upload it to hardware.

Now Open Rhino and grasshopper. 


Now click on the port and open option from toolbar.

Now connect port > open port function which will connect with firefly for further processing.


In last it should show the above message to success full connection.
Now we can put other information to pass to Arduino

First, we will try the output function.


It will blink LED with ON time 44ms(Random number) and off-time 1000ms, You can generate certain patterns with the help of more timing blocks. This will reflect on the Arduino LED as well.




For Input to a grasshopper.
You will need,
1) Any distance sensor (I'm going to use ultrasonic sensor)
2) LED for output indication,



Connections, 
Trigger > D9
Echo > D10
Vcc > 5V
Grd > Grd

In such case, I'm going to do all processing in Arduino to convert ultrasonic range to cm distance. put this data on serial bus to read in grasshopper. 
Upload Ultrasonic range finding Code in Arduino with serail out as below.


// defines pins numbers
const int trigPin = 9;
const int echoPin = 10;
// defines variables
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(115200); // Starts the serial communication
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor
//Serial.print("Distance: "); // remove this line to avoid multiple data in grasshopper feed.
Serial.println(distance);
}

Now open grasshopper and do connection as below.


This will read all serial data and put in your data points to process forward.

Comments

Popular Posts