LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with LIFA_Base

I'm having problem to update te LIFA_Base to my arduino. First I opened the LIFA_Base in the arduino.exe program, than I verified the code and everything went right. Then I try to edit the LIFA_Base putting my code (the code that I'm using is shown bellow). When I verify the code after editing it shows an error. Somebody can help me? Thanks

Error when compiling:

       

LabVIEWInterface.ino: In function 'void loop()':

LabVIEWInterface:43: error: a function-definition is not allowed here before '{' token

LabVIEWInterface:46: error: a function-definition is not allowed here before '{' token

LabVIEWInterface:50: error: a function-definition is not allowed here before '{' token

LabVIEWInterface:53: error: a function-definition is not allowed here before '{' token

LabVIEWInterface:81: error: a function-definition is not allowed here before '{' token

LabVIEWInterface:87: error: a function-definition is not allowed here before '{' token

LabVIEWInterface:870: error: expected `}' at end of input

Code that I'm using

/******************************************************************************* **

**

**  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"

int ledPin = 13; //led no pino 13

int Botao = 2; //botao no pino 2

int EstadoBotao = 0; //Variavel para ler o status do pushbutton

/******************************************************************************* **

**  setup()

**

**  Initialize the Arduino and setup serial communication.

**

**  Input:  None

**  Output: None

******************************************************************************* **/

void setup()

{

pinMode(ledPin, OUTPUT); //Pino do led será saída

pinMode(Botao, INPUT); //Pino com botão será entrada

  // Initialize Serial Port With The Default Baud Rate

  syncLV();

  // Place your custom setup code here

}

/******************************************************************************* **

**  loop()

**

**  The main loop.  This loop runs continuously on the Arduino.  It

**  receives and processes serial commands from LabVIEW.

**

**  Input:  None

**  Output: None

******************************************************************************* **/

void loop()

EstadoBotao = digitalRead(Botao); /*novo estado do botão vai ser igual ao que

Arduino ler no pino onde está o botão.

Poderá ser ALTO (HIGH)se o botão estiver

Pressionado, ou BAIXO (LOW),se o botão

estiver solto */

if (EstadoBotao == HIGH){ //Se botão estiver pressionado (HIGH)

digitalWrite(ledPin, HIGH);// acende o led do pino 13.

}

else{ //se não estiver pressionado

digitalWrite(ledPin, LOW); //deixa o led do pino 13 apagado

  // Check for commands from LabVIEW and process them. 

  checkForCommand();

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

  if(acqMode==1)

  {

    sampleContinously();

  }

}

0 Kudos
Message 1 of 7
(8,088 Views)

That last error is because you haven't closed all your braces.  I'm guessing it's the one for you else statement.  I'm not sure where the errors with the open brace are but I would first try fixing the one that I noted and see if that helps.

0 Kudos
Message 2 of 7
(4,405 Views)

Thanks Nathan it was the braces. Now I'm having another problem. I can't make labview read the data produced by arduino. I made the thermistor read example and I cant see the temperatures, It only shows NaN in the temperature fields. I tryed to do some digitals and analogs reads but nothing happens too. It seems that labview can detect arduino because when I press run the litle leds of arduino starts to blink. Can you help me again? Thanks

0 Kudos
Message 3 of 7
(4,405 Views)

I forgot. This is the code that I'm using:

/*********************************************************************************

**

**  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"

const int PinoSensor = 0;//pino Anlógico de Entrada 0

int ValorSensor = 0;

/*********************************************************************************

**  setup()

**

**  Initialize the Arduino and setup serial communication.

**

**  Input:  None

**  Output: None

*********************************************************************************/

void setup()

  // Initialize Serial Port With The Default Baud Rate

  syncLV();

Serial.begin(9600);

  // Place your custom setup code here

 

}

/*********************************************************************************

**  loop()

**

**  The main loop.  This loop runs continuously on the Arduino.  It

**  receives and processes serial commands from LabVIEW.

**

**  Input:  None

**  Output: None

*********************************************************************************/

void loop()

{  

  // Check for commands from LabVIEW and process them.  

  checkForCommand();

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

ValorSensor = analogRead(PinoSensor);

Serial.println(ValorSensor);

delay(50);

 

  if(acqMode==1)

  {

    sampleContinously();

  }

}

0 Kudos
Message 4 of 7
(4,405 Views)

If you want to use LabVIEW for this you should use the existing LIFA functions or integrate your custom function into the LIFA command structure.  Since you are just reading an analog pin, you should simply use the "Analog Read Pin" VI provided with LIFA.

0 Kudos
Message 5 of 7
(4,405 Views)

I tried this (Analog Read Pin) but didnt work. When I press run the led lights of my arduino stars to blink and no

comunication error is shown, but it doesn't show the correct voltage. It shows an absurd fix value of 68. And if i

change the pin port the same results are shown. I dont know what im doing wrong.

Run.jpg

AnalogPinRead.jpg

0 Kudos
Message 6 of 7
(4,405 Views)

I think we need to get the basic questions out of the way to make sure that we are on the same page.

Are you using the latest version of LIFA?  If no, then you should upgrade to the latest version and make sure that you get the new version of the firmware and upload it to you board.

Next, here is how a basic program using LIFA should look:

ExampleAnalogReadPin.PNG

It is important that you always use the Close.vi when working with Arduino.  Never use the "abort execution" button.  Close.vi must run to avoid issues.

Init.vi defaults to an UNO with a 115200 baud rate (this is how the firmware will default for an Uno) and will automatically search for the correct COM port.

So,  upgrade to the latest version of LIFA and uploade an unmodified version of the firmware then create a VI as shown above.  This should get your desired results.  If it is unable to find the Arduino, add the COM port constant back to Init.vi and try again.  If it still does not work then there may be bigger issues.

Also, make sure that you are able to run the Blink example in LabVIEW.  That will tell you if there is something more fundamental wrong with your setup.

0 Kudos
Message 7 of 7
(4,405 Views)