LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can LabVIEW VIs and arduino code run simultaneously through LIFA_BASE?


@ruaMaidrin wrote:

I need the delay so that the servo will stay the up position for several seconds


Or you could have a variable keep track of it like a state machine, and perform an operation then set a variable, keeping a tick counter that doesn't do the next step until some amount of time has gone by, thereby allowing the other parts of the code to continue to execute.

0 Kudos
Message 11 of 15
(1,608 Views)

Here's the code when i enter my code to the LIFA_Base, as you said. In what part do you think makes my attempt wrong?

 

 

/*********************************************************************************
**
** LVFA_Firmware - Provides Basic Arduino Sketch For Interfacing With LabVIEW.
**
** Written By: Sam Kristoff - National Instruments
** Written On: November 2010
** Last Updated: Dec 2011 - Kevin Fort - National Instruments
**
** This File May Be Modified And Re-Distributed Freely. Original File Content
** Written By Sam Kristoff And Available At www.ni.com/arduino.
**
*********************************************************************************/


/*********************************************************************************
**
** Includes.
**
********************************************************************************/
// Standard includes. These should always be included.
#include <Wire.h>
#include <SPI.h>
#include <Servo.h>
#include "LabVIEWInterface.h"

Servo entryServo; // create servo object to control a servo
Servo exitServo;

#define entryServoPin 11
#define exitServoPin 12 //Connected to the servo motor.

#define Exit 10 //Pin connected to the EXIT button.
#define Entry 9 //Pin connected to the IN button.
#define CAPACITY 6 //Capacity of the parking lot.
#define BarLow 177 //Low position of the barrier.
#define BarUp 95 //Up position of the barrier.

/*********************************************************************************
** setup()
**
** Initialize the Arduino and setup serial communication.
**
** Input: None
** Output: None
*********************************************************************************/
void setup()
{
// Initialize Serial Port With The Default Baud Rate
syncLV();

// Place your custom setup code here
entryServo.attach(entryServoPin);
exitServo.attach(exitServoPin); // attaches the servo.
pinMode(Exit, INPUT); // set "EXIT" button pin to input
pinMode(Entry, INPUT); // set "IN" button pin to input
digitalWrite(Exit, HIGH); // Connect Pull-Up resistor.
digitalWrite(Entry, HIGH); // Connect Pull-Up resistor.


entryServo.write(BarLow);
exitServo.write(BarLow); //Barrier in the low position


}


/*********************************************************************************
** loop()
**
** The main loop. This loop runs continuously on the Arduino. It
** receives and processes serial commands from LabVIEW.
**
** Input: None
** Output: None
*********************************************************************************/
int Available= 7;
void loop()
{
// Check for commands from LabVIEW and process them.

checkForCommand();
// Place your custom loop code here (this may slow down communication with LabVIEW)

if(digitalRead(Entry)==0)
{
if(Available != 0){
Available--;
entryServo.write(BarUp);
delay(3000);
entryServo.write(BarLow);
}
}
if(digitalRead(Exit)==0)
{
if(Available != CAPACITY){
Available++;
exitServo.write(BarUp);
delay(3000);
exitServo.write(BarLow);
}
}

if(acqMode==1)
{
sampleContinously();
}

}

 

 

 

 

 

 

 

0 Kudos
Message 12 of 15
(1,607 Views)

LIFA isn't designed to work the way you're using it; all of those 3 second delays in your main loop are going to do ...interesting things to the serial synching process. I think you'd be better off using LIFA's servo-control VIs, and keeping all of the delay logic and so forth inside the LabView code.

 

Also, worth noting that LIFA has been deprecated; there's a replacement library called LINX which is essentially a superset of LIFA's functionality. 

0 Kudos
Message 13 of 15
(1,565 Views)

@dmsilev wrote:

LIFA isn't designed to work the way you're using it; all of those 3 second delays in your main loop are going to do ...interesting things to the serial synching process. I think you'd be better off using LIFA's servo-control VIs, and keeping all of the delay logic and so forth inside the LabView code.

 

Also, worth noting that LIFA has been deprecated; there's a replacement library called LINX which is essentially a superset of LIFA's functionality. 



So you say, LIFA_Base is just a "KEY" code for the arduino board to execute a LabVIEW VI with arduino components? 

With that, I've already tried your suggestion, using the LabVIEW interface with the SERVO components. But I got again some problems synching the two features of our project. I have already read about LINX and VISA components, but I feel more comfortable with LIFA components. 

I hope you can help me again with another problem once I post it. 

  

Thank you guys, anyways.

 

0 Kudos
Message 14 of 15
(1,546 Views)

Essentially, yes. LIFA and LINX are designed around a master-slave model. The computer running LabView issues commands and queries, and the Arduino listens for those messages and carries out the instructions. As I understand your project, you should be able to just use the stock firmware with no custom modifications, and then the computer send the necessary LED and servo commands. 

 

It's possible to offload more of the logic and intelligence onto the Arduino, but if it involves substantial multi-second delays you need to look carefully at what that will do to the communications link, since you then have to worry about serial timeouts and similar issues. For what you're trying to do, I don't think it's worthwhile. Just keep the logic in the LabView code.

0 Kudos
Message 15 of 15
(1,511 Views)