Grasshopper

algorithmic modeling for Rhino

I can't seam to 'READ' serial data with Firefly.  

I have a sensor that constantly broadcasts a stream of ascii data that I can read with Hyperterm (with some difficulty) and 'Advanced Serial Port Terminal'.  But with Grasshopper/Firefly all I get is this:

Please note, I am able to 'Write' data to the sensor (activation commands and config. data) when I set the 'start' values accordingly.

Views: 2227

Replies to This Discussion

I just posted a comment on your other thread... asking for a sketch or more information on what was going wrong... and here it is in this thread :)

Ok... I guess I need a little more information on your setup.  Can you say what sensor you are using?  Are you using an Arduino to write this ascii information to the serial port?  If so, there may be some formatting code for the string that you'll need to do to get the Read component to function properly.  I see that you were able to open the port and Start reading... so my first thought is that the data is formatted correctly....

 

All of the read components look for a specific character (in this case two characters) to indicate when it has reached the end of the line being read and should spit out the data.  In this case, Firefly uses the Carriage Return (\r) and Line Feed (\n) to know when it has reached the end of the line.  In arduino, these are automatically added to any line if you use the Serial.println("blah, blah, blah"); command.  Notice, this is different from the Serial.print("nothing to see here"); command.  This doesn't mean that you can't still use the regular print command... it's just you need to use the println command to indicate when you've reached the end of the line.  Let's take a look at a simple example.

 

void setup() {
  Serial.begin(9600);
}

void loop() {
  int sensorValue = analogRead(A0);
  Serial.print("The value of the sensor is: ");
  Serial.println(sensorValue);

  delay(20);  // important to wait some small time so you aren't sending just a ton of info over to GH which will cause it to crash :(

}

 

The first print statement prints a string to the serial port... and the next one adds the current sensor value... and THEN adds the carriage return and line feed to start a new line.  The nice thing about using these together is that you can concatenate any type of data you want.  If you were to upload this sketch, you should see a sentence being printed to the serial port that says "The value of the sensor is: 512".  I made up the number, but you get the idea.  Notice, I also had to include a delay function.  You don't always need this (there are other ways to go about this) but the important thing to note is that the loop cycle on the Arduino can run really fast.  I mean... really fast.  So, you wont want to send so much data over to GH, because this could flood the string buffer in the Read component and cause it to crash (eventually).  It's a good idea to add some small time interval just to slow it down a bit. I should say that I've optimized the refresh rate in the next release so it's significantly faster... so hopefully this wont be as big of a problem... but hopefully that helps some.

 

Now... Why are you writing data to a sensor?  Sensors by default are considered inputs... so I'm quite confused as to why you would want to send data back (if you are... then you need some way to handle the string data being sent from GH... this is the whole reason we built the Firefly firmata... it sets up the two-way protocol so you don't have to deal with all of that mess... If you're going to read and write, you're better off just uploading the firmata and using the Uno Read and Write components).  Also, I'm not very familiar with the Hyperterm or Advanced Serial Port Terminal... but I will say that could get COM conflicts if you're trying to open the port with different tools.  Anyway, I hope some of this helps you get up and running.

 

Cheers,

Andy

 

Sorry about the double post but it looked like my first was only going to be seen by the 2 of you in that one thread.

 

Any hoo...

The sensor is an ultrasonic 'range finder'.  

When activated and configured (You send it the activation/deactivation signal and configuration data via a serial 'write' command) if sends the range data as number of 0 -4096.  This along with other data is sent in a string enclosed in {} brackets.  {=start of frame, }=end of frame. So no escape characters will be needed.

Are you using this code?

http://arduino.cc/en/Tutorial/Ping

I'm not using an Arduino.  The data stream comes directly from the sensor.

 

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service