11-22-2013 10:52 AM
Hey,
I am trying to build a code to read the distance through an ultrasonic sensor and i want to use Arduino. I know that LIFA is used to extract information from arduino so i set up a GH-311 sonar sensor to arduino and connecte the interface to my PC.
My question is if i wanted the sensor to work i need to have both an arduino code and another one on labview for ping pong? or a code on labview only would be enough?
Sincerely,
Chimof
11-22-2013 11:01 AM
Using LIFA requires you to upload the LIFA Firmware to the Arduino. Then, you would create a LabVIEW VI to request information from the Arduino.
That sensor looks like it is very similar to the Parallax PING))) Ultrasonic sensor or the SRF04 (or SR-04) for which myself and others have written code. So, there are several threads discussing these types of sensors and I've also created a document for the custom LIFA Firmware and LabVIEW functions for interacting with the PING))) sensor.
11-22-2013 11:19 AM
Hey Chimof,
That sonar sensor generates a digital pulse to indicate the distance measured. Unfortunatly this doesn't mesh well with the way LIFA or LINX works. LIFA and LINX assume LabVIEW is the master and the device (arduino / chipkit / myRIO / etc) is the slave. Even if you poll the DI pin on the device as fast as you can from LabVIEW you won't be fast enough to accurately measure the pulse width (myRIO is the exception to this since LINX runs natively on myRIO rather than simply 'talking to it').
There are several ways you can make this work, however I don't have a good, general purpose way to support this in LIFA or LINX by default. You could add a custom command to LINX that uses an external inturrupt and timer on your board to measure the pulse width, but this would end up being specific to the device you're using.
I'm trying to think of a better way support sensors like this across all device. If I can come up with something I'll build it into LINX.
-Sam K
LabVIEW Hacker
Join / Follow the LabVIEW Hacker Group on google+
11-22-2013 11:22 AM
Is the pulseIn() functionality not a common thing on uProcessors? That is what is needed in Arduino to make it work.
11-22-2013 11:31 AM
Ok, I take some of that back. I didn't read the spec sheet for the sensor close enough. Since you trigger the sensor by sending a pulse, before receiving the pulse that makes it much easier. I was under the asumption that the sensor was continuously pumping out pulses you had to read.
The pulseIn() functionality provided by the Arduino API basically polls the specified pin until it goes high, then polls again until it goes low or times out. It keeps track of the number of iterations of the second loop and uses that to determine how much time has elapsed.
This is something that is relatively easy to support in general. I'll add this to LINX.
-Sam K
LabVIEW Hacker
Join / Follow the LabVIEW Hacker Group on google+
11-22-2013 03:49 PM
Sammy! Nathan!
Thank you for our quick, accurate replies. I have been working on an accelerometer ADXL 345 and Ultrasonic Sensor GH-311 trying to operate them simultaneously, Until that moment i have tried everything using LIFA and am still getting errors 5001 5002 and 5003 on arduino vi's the thing is i'm new to all of that and i'm not sure what i'm doing however i got logical values for the accelerometer using arduino without labview but unforntunately couldn't use the sonar sensor for distance measurement yet. Any thoughts on the errors i'm getting?
Sincerely,
Chimof
11-22-2013 10:43 PM
Well, the first thing to do when you get errors is to look up the official error documentation for an explanation of what it means and possible trouble shooting techniques (I usually search for "lifa 5002" to find the documentation). If you check/do all of the troubleshooting that is recommended and you are still having issues, then it is usually helpful to find out where exactly in your VI the error is occuring (you can use Execution Highlighting to do this).
Note: The default baud rate in the firmware for the Arduino Mega 2560 is 9600 and you need to make sure that you wire that to the "baud rate" input of Init.vi in addition to selecting the Mega as the board type.
Regarding the sensors, what VIs are you using for the ADXL345?
11-23-2013 11:34 AM
Nathan!
Thanks for the great feedback!
As you already explained, i have read all the documents you posted and applied everything: I used LIFA base 2.1.1.69 you posted or the LV9 sonar Sensor code and LIFA firmware: nothing works! I always get error 5002/5003.
I think that ill be able to work wih everything if i get this problem solved
The same goes for the ADXL 345 where i used a certain code in arduino that gives logical values; I know that it works fine but not on labview since i'm not sure about the VI for the accelerometer, I got it from the forum example and other posts you commented on, even from yours https://decibel.ni.com/content/docs/DOC-28504
I am still having the same problems!
Sincerely
11-23-2013 02:30 PM
Did you find out which VI is causing the errors?
Unfortunately, with the given information, I won't be able to help you further. The only last thing that I can think of is for you to attach you VI so I can see if I notice anything out of the ordinary. But, find out which VI is causing the errors first.
11-26-2013 11:11 AM
The latest build for LINX includes beta support for this sensor. I don't have one to test it so please let me know if it works by posting in the LINX forums when you get a chance to try it:https://www.labviewhacker.com/forums/viewforum.php?f=12
The sensor VI is on the functions palette under LabVIEW Hacker>>LINX>>Sensors>>Beta>>Ultrasonic
LINX download instrucitons here: https://www.labviewhacker.com/forums/viewtopic.php?f=12&t=6
Thanks!
-Sam K
LabVIEW Hacker
Join / Follow the LabVIEW Hacker Group on google+