LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Arduino uno and Parallax PING)))

I have a parallax PING))) ultrasonic sensor and an Arduino uno board. I have also setup Labview and the interface for arduino.

I am wondering whether any one have a working code to get a reading from the PING))) sensor and have it displayed on labview. Any help would be really apriciated. (I checked on the other posts here but didnt have much luck adopting them to my application.)

Thanks in advance.

Message 1 of 13
(9,032 Views)

This will require a custom LIFA function.  I wrote one for the SRF04 but never got confirmation that it worked.  If I have some time, I will try write this up for you.  PM me if you haven't heard from me by Sunday.

0 Kudos
Message 2 of 13
(4,712 Views)

Nathan... anushanw...

I will post my code as soon as I figure out how to do that in a nice way...

I learned from your example code and put together a LIFA function and did the Arduino side...

In the meantime... please view this discussion for partial clues...

Im sure it could be cleaner but it does work...

2. Sep 13, 2012 7:16 PM (in response to anotheralias)

Re: Display data types sent with serial.write in labview after send receive.vi

I'll be back soon...

0 Kudos
Message 3 of 13
(4,712 Views)

First... the LIFA code...

    /*********************************************************************************
    ** PARALLAX PING RANGE FINDER
    *********************************************************************************/
    case 0x40:  // PARALLAX PING range finder
      // Configure pin as an OUTPUT in anticipation of TRIGGER PULSE
      pinMode(command[2],OUTPUT);
      digitalWrite(command[2], HIGH); // Trigger RANGING with 5uS HIGH pulse
      delayMicroseconds(2);
      digitalWrite(command[2], LOW);  // Set pin LOW again
     
      //Configure pin back to INPUT in anticipation of ECHO
      pinMode(command[2],INPUT);
      // Delay for HOLDOFF period (see PING documentation) before listening for ECHO
      delayMicroseconds(T_HOLDOFF-50);
     
      // Read duration of pulse return echo in micro seconds uS
      // If using a timeout (optional), number of uS to wait for the pulse to start
      // retVal = pulseIn(command[3], HIGH, 35000); 
      retVal = pulseIn(command[2], HIGH); 
   
      Serial.write( (retVal >> 24 & 0xFF) );
      Serial.write( (retVal >> 16 & 0xFF) );
      Serial.write( (retVal >>  8 & 0xFF) );
      Serial.write( (retVal >>  0 & 0xFF) );
     break;

And some snips of what I called SONAR.vi and READ_PARALLAX_PING.vi

ContextHelp.PNG

Read_PARALAX.PNG

Sonar.PNG

I hope this does it... I was looking for the right way to sneak in code snippets?

Tim

0 Kudos
Message 4 of 13
(4,712 Views)

And as NATHAN_B said...

You must edit your LIFA_Base.pde or .ino depending on your version.

The file within your version has a tab called LABVIEWInterface.

Within that file, look for the function "processCommand()".

This function accepts commands accross the interface from LabView for functions that should be performed on the Arduino hardware like the Serial.print command that cannot be implemented on the labview side.

You would edit that function to include a new case in the switch(command[1] area. One suggestion is to use my case from the snippet of code which matched my vi code, then compile and load your now new (and hopefully improved) LIFA to the arduino. Now it is prepared to accept a your new, special purpose command code from labView side.

Another good suggestion is to change it to case 0xFF so you won't potentially interfere with additions to the LIFA from time to time which usually may just be slightly higher case code numbers in new version releases.

That way you can add your own in decending order.

Then in your labView code you will reference that function code (0x40) in the send receive vi to accomplish your new command behaviour.

With regards to that request for code...

I am sorry if I am being sort of difficult about just sending you the vi's just now... but outgoing email is blocked for me and I can't for the life of me (I am new at this) figure out how to do a simple attachment... apparently you can only do videos and pictures in this thing.. or go through the steps (potentially) of creating a document, doing some descriptive texts regarding what it is you are uploading, put tags in it, and then link to it in the document. Hardly convenient, but understandable for the community's sake. I'll get used to it.

When I get somewhere else, I can do things directly, but that is later...

Tim

0 Kudos
Message 5 of 13
(4,712 Views)

Thanks for all your help Tim, your info has been very helpful.

I tried this and I am getting a timeout Error. The exact message is:

"Error 5003 occurred at ping-test.viLabVIEW Interface for Arduino.lvlib:Init.viUntitled 1LabVIEW Interface for Arduino.lvlib:Digital Write Pin.viLabVIEW Interface for Arduino.lvlib:Set Digital Pin Mode.vi.  A timeout occurred while trying to read form the Arduino."

Any ideas?

0 Kudos
Message 6 of 13
(4,712 Views)

I have seen that error which indicates you may not be communicating across the usb.

If you look inside the sendReceive vi, you may find that it is going to express that error by default if it doesn't get a response back in time.

So please check your comports, making sure you are expressing YOUR setup, and especially if you haven't yet implemented the new command in your LIFA and loaded it onto your Arduino, because the Arduino would just drop a new command on the floor if it didn't recognize it, and then sendReceive would time out, and then you will get that error...

So... two things.... implement the command code in Lifa... and ensure all the comports are happy.

My experience also says... always STOP your vi using your vi stop button that YOU implemented... NOT the one on the labview bar and not by pulling the USB cord out or re-powering.

Sometimes... if you have done those things... things do not get back to normal until you close all vi's, close labview, re-open... and if still persisting... uninstall/reinstall the port driver for the appropriate device.

You might not know you are really not in communication with labview (it would be nice to know that)...

Then, when executing your labview vi... you will run until sendReceive... and (you know...)

Check the ports and check a simple vi to see if IT works fine.

Cheers...

Tim

0 Kudos
Message 7 of 13
(4,712 Views)

Thank for the reply. I did a small VI to turn on/off the onboard led with a push button and that works lke a charm. And also, I did include LIFA code to the firmware file as you mentioned and uploaded it.

Then I saw the lines:

                            // Read duration of pulse return echo in micro seconds uS

                           // If using a timeout (optional), number of uS to wait for the pulse to start

                           // retVal = pulseIn(command[3], HIGH, 35000); 

                           retVal = pulseIn(command[2], HIGH);

So I uncommented line 3 and commented line 4. Now the error is completely gone. But the value is reading as 1.27 all the time when i just run the read_Parralax_PING.vi part, and when I run the full vi of yours it shows the 1.27 once ad then goes to 0.

Happy the error is gone but seems like there is another obstivle now.. hahaha... again thank you and any help is highly apriciated

0 Kudos
Message 8 of 13
(4,712 Views)

Which begs the question...

I am sorry for the comments I left in that way... it is confusing.

I had done this originally with two parameters passed in by labview. One for a trigger pin and one for a pulse return pin. I since found it better to just change the output pin to an input and so getting a command line argument from command[3] would be invalid.

Since pulseIn takes a pin number for an input... where would you get that from? labview sent it. One byte.

You are reading a zero (or trash) from the command array if looking beyond one parameter. The PIN to read should be read from command[2].

Take a peak at all the other function commands and most just take from command[2] which I assume to be like a function call parameter. Since it is just one byte sent from labview... it should be there.

If you use command[3]... you don't know what  you are getting or from where.

Solve the problem of what pin you are using and where to get it from.

You could have gotten a pin pulse from the serial interface pin that way at least once... then all bets are off...

Maybe you could show a picture of your vi?

Ensure the appropriate pins are mentioned for input output (same pin).

Have fun..

Tim

0 Kudos
Message 9 of 13
(4,712 Views)

Oh... and...

Make sure in labview that you set the pin back to be an output before you ping again or you won't even know you are not pinging. I don't think there will be any complaint offered while trying to output on a pin that is set up for input.

Maybe turn on your LED (pin13) while attempting pinging... which may give you a clue as to wether it is trying or not. The timer was suggested so that you can see the ouput flash... and a perioud of silence.

Tim

0 Kudos
Message 10 of 13
(4,712 Views)