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