LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Send data to arduino

Solved!
Go to solution

I'm trying to send commands from Labview to Arduino.

 

The following VI and Arduino program are working perfectly.

 

I just want to know why do I have to connect a Read vi after the Write vi in the labview program?

When I run the program with the Write function only, the Arduino does receive data (can tell it by the Tx blinks on the Arduino board) but doesn't perform like how it should, which means it isn't decoding the data properly.

 

Secondly, why do I have to not connect the Close Visa function? If I connect that, the program won't run, it's giving an error at the Close vi. 

 

Download All
0 Kudos
Message 1 of 8
(1,943 Views)

Hi sarwat,

 


@sarwatsarfaraz wrote:

The following VI and Arduino program are working perfectly.

 

Secondly, why do I have to not connect the Close Visa function? If I connect that, the program won't run, it's giving an error at the Close vi. 


I don't think it works "perfectly", due to several misconceptions…

What's the point of the event structure? Why is there an empty timeout event?

 

You open the serial port in every iteration, but you never close it. That sounds wrong…

Open the port once before the loop, close it once after the loop!

(Which error do you get when you close the port? Please provide all needed information for us!)

 


@sarwatsarfaraz wrote:

When I run the program with the Write function only, the Arduino does receive data (can tell it by the Tx blinks on the Arduino board) but doesn't perform like how it should, which means it isn't decoding the data properly.


That should be a problem in your Arduino code…

Does it wait for a TermChar, which you forgot to send?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 8
(1,913 Views)

I need to see your Arduino code.

 

DON'T USE RAR my company does not allow that to be installed so I can't open it.

 

Arduino code is just text copy and paste it into your post.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 8
(1,876 Views)

Hi. This is my updated vi, have deleted the event structure

 

Here is my Arduino code:

 

 

char x;

void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT);
}

void loop() {

  if (Serial.available() > 0)  {
   x = Serial.read();
   
  Serial.println(x);
}

 if (x=='a') {
    digitalWrite (13, HIGH);
  }
  if (x=='b') {
    digitalWrite (13, LOW);
  }
}

 

 

0 Kudos
Message 4 of 8
(1,797 Views)

This is the error when i connect the Close function:

 

sarwatsarfaraz_0-1671083629881.png

 

The error window never closes, it keeps popping up so I have to end Labview through Task Manager end task

0 Kudos
Message 5 of 8
(1,795 Views)
Solution
Accepted by topic author sarwatsarfaraz

Hello,

 

there are some mistakes in your design.

  1. As GerdW stated, place the VISA Open and VISA Close function outside the loop. Make sure, the Arduio IDE Serial Monitor is not connected to the Arduino, UART access is exclusive.
  2. Feed the VISA wire via a shift register into the loop.
  3. Just send your character when a Button- change is recognized. You can achieve this with an event structure (have a look at the shipped examples via LabVIEW-Menu "Help / Find Examples...") or with a case structure (then make sure, Mechanical Action of your button is set to "Latch when released")
  4. Since your Arduino doesn't send anything, it is not necessary to place the VISA Read. It will always timeout. And this creates an error.

As we can see, your error message says, that the VISA resource is not valid while writing to the port, but opening is OK. The reason could be the Serial Monitor. What happens, if you close the Arduino IDE?

 

Greets, Dave
0 Kudos
Message 6 of 8
(1,771 Views)

I just placed the configure port and VISA select outside the while loop, it's working now.

 

Btw, why should i feed the VISA wire via a shift register into the loop? It's working without this but still curious. 

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

You are right, it's not absolutely necessary.

 

 

Greets, Dave
0 Kudos
Message 8 of 8
(1,741 Views)