Grasshopper

algorithmic modeling for Rhino

I am not sure if this has been posted or not yet previously, I apologize for the duplicate post if it has been, but I figured this could be of help to some people who were working on making the communication between programs like arduino and processing to grasshopper.

Previous to the firefly plugin, I was working on sending data from arduino to grasshopper, and conversely on a different project I was working with sending data from grasshopper to processing. This is all fairly simple, thus far, with the firefly plugin but like I said it did not exist when I was trying to do this. So this could be of great help to someone trying to communicate data but serial communication is not working for one reason or another?

What I did was read sensor data going into an arduino in Processing, via Firmata, and I saved this data to a string variable (this must be an array, so even if you only have 1 line of data you'll have to make it an array of 1 value), then I used the "saveStrings( )"  function in processing to write a .txt file containing the string[] information.

Then on the grasshopper side, I used the "Read File" component in grasshopper with the file path of the text file created in Processing sent to "P" of the component. If you are working with numbers, which is most likely the case if the data is coming from sensors, you can attach the "C" output of the read file component to a "number" or "integer" component to convert the data from a string to a number.

This will update in real time since the read file is always reading, no need for a timer to update it on the grasshopper end. The only suggestion would be to put a delay in your Processing code before you actually use the "saveStrings( )" function to avoid null's being sent to grasshopper because of read/write conflicts. Usually a 50ms delay works fine.

Likewise, if you want to get data from grasshopper to Processing (for example) the nice little feature in grasshopper, while right clicking on a "panel" component, "Stream Contents" will save a .txt file of all data inside the panel, this will update as well in real time without a timer component.

Once you set up the file path of the .txt file of you panel, in Processing you can load this data by using the "loadString( )" function which will create an array of the .txt file created in grasshopper.

I hope this is clear and useful,
Adam

Views: 3033

Attachments:

Replies to This Discussion

Hey.

 

I'm doing a similar thing. Basically reading from a .txt file that is constantly being updated by vvvv. I'm using the read file component, but for some odd reason it only updates when i click into the read file component and then exit the component. only then will the values change. This means only a single value is loaded at a time, instead of a steady updated stream of values...

 

Any thoughts?

 

Thanks,

Bryce

 

thanks.

While I did this almost a year ago, I cannot recall exactly (deep down) what was going on without looking at the files again, which I have not done since I posted this. 

 

First thoughts would be to utilize a timer on 1 or a few components.

Also, is the actual text file being updated? In other words, if you open the file then close it, then open it again in a few seconds, are the values different?

 

I would try putting a timer into the read file component first and see if that works.


Otherwise, maybe post your definition here and I can take a look if I get a moment.

 

Goodluck!

try to use timer sticked to read cpmponent, maybe...
yup, use the timer.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service