LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Controlling arduino variable values using LabVIEW

I am fairly new to Arduino and I was wondering if there is a way to pass values to a sketch variable from LabVIEW? I am trying to update the sketch variable value through LabVIEW every 10 minutes and then close the serial port, after which my infinite loop will check if the variable is over a threshold level. I added a case to the processCommand function so that when I send a hex command from LabVIEW it should update the variable.

case 0x2E:   

      Var == 12  //This is in the labviewinterface.h where I am trying to update the variable value to 12 on receiving a command of x 2E from LabVIEW.

      Serial.println("success");

       break;

I have defined it as a global variable in my main sketch and  am trying to check its updated value

if (Var > 10)

{

Serial.println("variable value is over limit");

}

Any suggestions would be much appreciated. Thanks!

Board: Arduino Uno Rev 2

LabVIEW: 2011

0 Kudos
Message 1 of 7
(6,380 Views)

Hey,

Using the LIFA sketch this way isn't really intended behavior. To achieve similar logic I would set up framework something like:

-Send/Receive command from LIFA which calls a new command which activates "loop mode". Have the send/receive code expect 1 byte in response

-When command is called on Arduino put code into "loop mode" (could use something similar to how continuous aquisition mode is done)

-When loop completes write a confirm byte back to LIFA (something like Serial.write('0');)

-The Send/Receive will then recognize the loop mode completed succesfully (you may need to increase the timeout)

Let me know if you have questions with this- we could also provide a better answer with a better understanding of what the big picture goal of this functionality is.

Kevin Fort
Principal Software Engineer
NI
Message 2 of 7
(4,234 Views)

Kevin,

I am designing on a test fixture at my work and I am trying to use Arduino Uno to control it.

Expected sequence of actions:

1) PC communicates with Arduino and e.g. sets test voltage and pressure at 3V and 5psi.

2) PC ceases communication with Arduino and is available for other tests.

3) Arduino in response to a push-button runs a certain test using the above set pressure and voltage values.

4)This continues until new values are passed on to Arduino Uno.

Unfotunately I won't be able to give  the actual test details because of company policy.

I will try your suggestion above and let you know in a few days if it works.

Thanks again,

NV

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

NV,

One thing to note is that when you are using a USB connection the Arduino Open VI resets the Arduino (just the same as pressing the reset button).  This happens because VISA Open in the Arduino Open toggles the DTR serial line.  This line is used by the Arduino IDE to reset the Arduino when you program it so that you don't have to manually reset the board.

Best of luck.

-Sam K

LIFA Developer

Message 4 of 7
(4,234 Views)

Kevin,

I added the following to the Labview Interface.ino

case 0x0E:   

      Test==1;

     Serial.write('0');

      break;

    case 0x1A:   

      Test==0;

      Serial.write('0');

      break;

I added Serial.print(Test) to the main code to verify through the serial monitor if the value was set. After sending x0E from send/receive VI in LabVIEW, I got a 0 on the read buffer but when I closed the port and opened serial monitor it was still giving me 0 as the value of Test.

After that I removed the serial print command, set 13 as digital output and told the program to blink led 13 if Test ==1 and still it does nothing, what am i missing?. Another question , why do you want me to loop on the command in LabviewInterface.ino?

Thanks for all your help!

Naren

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

Sammy,

Would the reset action erase my global variable values? If so, can I programatically disable it? Thanks,

Naren

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

Hey Naren,

The reset will erase any global variables you had set before the last iteration. I don't think there is a way to change that behavior on the Arduino side but you may be able to do it in LabVIEW by setting the DTR line state (with a property node) before the open. I'm not sure if that will actually work but its probably worth a try.

Kevin Fort
Principal Software Engineer
NI
0 Kudos
Message 7 of 7
(4,234 Views)