Grasshopper

algorithmic modeling for Rhino

Hi,

 

I have a load cell that is hooked up on a HBM Spider box which, in turn, is connected to my PC on the serial port.

 

I would like to get the information that is sent to the PC into Grasshopper to graph the data. Does anybody know how I would get Grasshopper to listen on the serial COM1 port?

 

thanks,

wim

Views: 2918

Replies to This Discussion

Hi Wim,

Try looking at the Firefly plugin (www.fireflyexperiments.com).  If you're data is already being sent to the Serial Port, then I would recommend using the Generic Serial Read component within Grasshopper.  You'll have to first Open the Port (using the Open/Close Port component) and then just start reading the values.  Hopefully this should be pretty straight forward, but please let me know if you have any questions.

Cheers,

Andy

Hi Andy,

thanks for a speedy reply!

 

I've now installed Firefly and am trying to read data but clearly I'm doing something wrong.

Attached is a screengrab of grasshopper and the window of the Spider software.

 

When I toggle the Open boolean to True, the component turns red and the note output is "No data was collected...".

 

In the Spider window, I've circled the value that updates realtime when I put weight on the load cell - so apparently data is coming in over the serial port.

 

Thanks for helping!

wim

Does the spider hardware print info without that window being open?  What I'm thinking is that the port is open by the Spider software (to visualize the data) and because the port is open by another software program, then GH can't open the port (and thus no data).  The same thing happens in Arduino... If you have the Serial Monitor open in the Arduino IDE and then try opening the port in GH, it will throw an error because the port is already open by another software.  Theoretically, the hardware should be printing info to the serial port regardless of whether or not that Spider software is running... so try shutting down that viewport and then trying to re-open the port via Firefly (you may need to restart GH as there is a small bug in the Open/Close port component... it's been fixed for the next version... but I'm not exactly sure when that release will happen).  Let me know if this makes sense.

Cheers,
Andy

Andy,

Yes, that makes sense.

 

But I guess I'll have to try again tomorrow when I'm back at work. I don't have a docking station here and my laptop doesn't have a serial port. While the spider has an adapter cable from its printer port to USB, I don't suppose Firefly listens on the USB port...

 

cheers,

wim

Hi Wim,

Yes, Firefly listens to any serial port (virtual or otherwise).  The arduino, for example, uses a USB cable to send serial communication to/from the computer.  When data from the arduino is printed to the serial port... the Firefly component just opens the connection and reads the data into a buffer and spits it out into GH.  The generic serial read component just returns any data being sent over the serial port... The Uno/Mega Read components are  specifically tailored for using the Firefly Firmata which is basically just a set of instructions that is loaded onto the board which tells all of the pins how to talk back and forth with GH.  In this case, it reads the buffer and does some string manipulation to spit the data out to various outputs.  In your situation, you wouldn't need all of this... but long story short... yes, Firefly can read anything coming/going over the serial port (whether it's USB or printer port).

-Andy

Hi again,

In that case we (or rather, I) have a problem.

When using the spider program (which first gives me a dialog where the interface is picked - LPT, COM, USB) works through the USB interface but now Firefly returns an empty list from the Ports Available component - both when the spider program is running in the background and otherwise...

 

I hope I'm not getting on your nerves quite yet...

thanks!

wim

An update, Andy,

here at work, using the COM port and not having the spider window running in the background, I now get the Hooray! message. :-) Cool!

 

I now hooked up a generic serial read component on the port and put the Msg output into a yellow note. That read "Now reading values from the Arduino board".

 

Any ideas on why the USB doesn't work?

 

I guess I should now read the manual to find out how to actually get the numbers that are constantly spit out by the sensor...

 

thanks!

wim

Hi Wim,

If you've gotten the "Hooray" message, then at least we're making a connection to the correct COM port.  When using the Generic Serial Read, you need to give it the same COM port as you used in the Open Port component.  Then connect a boolean toggle (Params/Special/Toggle) to the Start input and set it to True.  One thing to double check is the Baud Rate input on the Open/Close Port component.  It's default is set to 9600 but I don't know what rate your spider hardware is running so that could be causing the problem if you aren't seeing any data.  Also, the data should be coming out of the 'Out' output node on the Generic Serial Read component (not the 'Msg' output).  If you set the Generic Serial Read to True, check to see if you have anything coming out of the 'Out' output.  If so, then connect another boolean toggle to the Timer input and set it to true to begin automatically refreshing the output data.  Depending on how your data is formatted, you may have to perform some other string manipulation once it comes out of the Read component... but that's not too hard either.

Hi Andy,

Weird...

This morning, I thought I'd turn the boolean toggles to False before hooking up the spider hardware to the PC and when I opened the grasshopper definition, the Hooray message was still showing.

Yesterday, I noticed that when I streamed the output into a text file on the harddisk, that this text file had grown in size after a while but that all the lines were blank.

I looked into this some more today and see that, when the port is open, the output of the Log component adds non-numbered lines in a yellow note, and when I then close the port, <null> values are added rapidly. I made a screen capture video of this that I could send you but here is a screen grab...

Do note that is is without anything being attached to my serial port!

 

As for the spider, the baud rate of 9600 should be right:

 

Where do I go from here?

 

cheers,

wim

Hey Wim,

Hmmm... I hadn't accounted for the nullable items in the Data Log... but I can see how this would be causing some problems.  I will add some code so that it only adds valid values to the Log (so it wont include null items).  As a work around, you should be able to use a Clean Tree component (Sets/Tree/Clean Tree) to remove all of the null items from the list (then make sure to stream that resultant list to a new text file... Right click on any text panel and choose Stream Contents to continuously write the contents to a text file).  Hopefully this will work for you.

-Andy

Hi Andy,

I've installed a new version of Grasshopper just now and see that it behaves a bit differently.

Whereas the non-null items in the list perviously just were empty lines, it now states <empty>.

I put in a Clean Tree but as far as I can tell, the problem is that all the lines are either <empty> (when the port is open) or <null> (when the port is closed). No data at all is coming through - still many lines per second are added to the log. (image attached).

Also, as I said, there doesn't appear to be a difference between having something (the spider) hanging on the port and nothing at all on the port.

 

note: trying to start the Spider software when Grasshopper is working pops up "Error during OpenPort." When I then close the port in Grasshopper and try to start the spider software again, this time it works. And then, when that is running and I try to open the port again in Grasshopper, Grasshopper throws a "No data was collected..." error and the Open Port compontent turns red.

It doesn't make sense to me.

 

cheers,

wim

Hi Wim,

This all sounds very weird to me too... I'll have to take a further look.  From your image, I think you have the Clean Tree component too high in your sketch... What I was suggesting was to remove all the null and empty items from the list that is coming out of the Data Log component.  You're cleaning the data coming out of the Generic Read component.  If you clean the Log Values, it should at least remove all of the null and empty items from the list, so you just have the valid sensor values (assuming you're even getting those).  Again, not knowing the ins and outs of this spider software... it's kind of hard for me to know how it works.  I'll try to put some more error checking in the Firefly components, but I'm not exactly sure why it isn't working for you (BTW, do you need to record all of the sensor values?)  Can you just use the most current value (and skip the Log all together)?

-Andy

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service