algorithmic modeling for Rhino
Hi guys,
Im having trouble reading data from multiple sensors attached to the arduino board (light sensor, sound pressure sensor and sound/piezo sensor as laid out below).
In Grasshopper the data can be read from the serial read component with a panel attached to the output (below). But it reads them simultaneously on one line and we need each sensors data to be read individually.
Using the 'UnoRead' component, we get an error message which makes us think that our arduino sketch code is incorrect..
Heres the code we uploaded to the arduino board:
Any help would be greatly appreciated!!!!!!!!!!!!!
Thanks
Tags:
Hi Amy,
There's a few things that I can suggest based on your description. The first thing that's happening in your sketch is that you're actually printing 3 separate lines (because you're using the Serial.println function). The print line function adds a carriage return and new line feed symbol at the end of each line (which is when in the serial monitor it puts each new statement on it's own line). The Firefly Generic Serial Read uses the new line feed character as its designation symbol on which to terminate the line and spit it out to Grasshopper. I think what's happening is that you need to format the string coming over from your Arduino so all of your sensor data is sent on a single line (not three lines) of text. You can do this using the Serial.print statement (not println). You will need to use the println function on which ever print statement that ultimately concludes the line you want to print... but you can concatenate longer strings together simply by printing using the other print statement. You also don't need the metadata that is sent over (like "Light Level:" or "Sound Pressure:"). You're really just interested in the actual numbers (assuming you know the order of the numbers in the string your sending over the serial port). My recommendation would be to concatenate all of your sensors into a single line of text separated by commas. Then, once you read the string into GH, then you can split it up at the commas using some of the built in string components.
Now, all of that said... I notice that all of your sensors are just standard analog sensors (you're simply using the analogRead() function). Since this is the case, you can easily upload the Firefly Firmata (which handles all of the formatting for you) then you can simply use the Uno Read component (the reason it threw an error was because it was expecting a specifically formatted string of data... and the string you were sending was of a different format). If you upload the Firefly Firmata, then you can use the Uno Read and all should work well. Note that you're using the baud rate of 38400 in your sketch, but the Firmata uses 115200. It doesn't really matter (too much) which you use in this instance... but you have to make sure the baud rate on the Open Port component matches that of the Arduino sketch. If you're using the Firmata, then the default is set to 115200, so you don't need to worry about it... but I just wanted to bring it to your attention since you were using a different baud rate in your other sketch.
I hope this helps.
-Andy
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by