LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial read continuously data and write from labview to arduino problem

Hi,I have a problem about contuniously reading analog data from arduino to labview.I tried to control 16 relays and taking analog data at the same time at same arduino and labview program and saving these data in txt. file but I cant achieve to take data continuously and controling relays. I achieved separately to control relays with labview and taking data from arduino to labview.But I cant combine succesfully these two different program in one program.Now i can read data only i change buttons position which is in labview and i can change relay position accurately and some time later there was a problem for reading and program was freeze. in this time period arduino RX and TX leds are lighting contuniously. I'm adding arduino and labview programs for controling three relays.I want to take data and at the same time I can control the relay by means of labview.Please help me for solve this communication problem.Thanks.


0 Kudos
Message 1 of 6
(8,182 Views)

What errors are you getting in LabVIEW?

Could you please save your VI for LabVIEW 2011 (that's the only version I have available currently).

0 Kudos
Message 2 of 6
(5,063 Views)

I can't read continuously data.If I change each of one button position i can see this time data and i can change relay position and after some time later nearly 15-20 seconds programme gave timeout error and freeze.There is a "read data" function in my arduino program.When I change this function position in arduino program and write to after  "ActuateComponents(inParams);" command also i can read data and control relay only when i change button position but there is not freeze in labview program.

I saved as a 2011 version if it is correct(I chose my current labview program and file>save for previous version>11.0)

0 Kudos
Message 3 of 6
(5,063 Views)

There are several issues with your LabVIEW program that prevent it from working correctly.  I would recommend that you take some time to learn the LabVIEW basics to learn about data flow and race conditions.  For example, when you use a local variable for the "read buffer", it creates a race condition where you may or may not be reading the same data multiple times.  The same goes with all of your numeric data (number1, number2, etc.).  Always wire things directly if at all possible.

While an event structure can be used effectively in this application, I don't think I would recommend it for very inexperienced LabVIEW coders.  I'd probably recommend, as a first step, to use a "Latched when released" front panel button that connectes to a case statement in which would be a Serial Write function to act upon one of your relays.

However, I just thought of this, you could probably wire a 0 or a 1 to the timeout terminal on the event structure to get it to run OK.  You currently have nothing wired to it meaning that it will stop execution of the program until an event occurs (this is actually what is causing you to read data only when a button is pressed).  If you choose to go this route, you will need to move the Serial Write function into each of the event cases so that you are not sending empty strings.  Also, you need to add back the timeout case that will just pass the VISA resource and error wires straight through.

Regarding the VISA stuff.  You shouldn't be using the event stuff.  I'd recommend that you take a look at an example that I made for communicating with the Arduino with LIFA or LINX which can be found here.

Now, the Arduino code could probably use some improvement (take a look at the example I just referenced above).  Also, any time that you put a delay in the Arduino code, it will stop all execution of the code which may or may not affect the responsiveness of a serial write function from LabVIEW.

I know it's a lot o information and I may not explain it the best but I hope you can learn from it.  But, again, I highly recommend that you spend some time learning the LabVIEW basics.

0 Kudos
Message 4 of 6
(5,063 Views)

At first I'm grateful for your detailed answer.Thanks a lot.I will apply your corrections in my Labview and arduino program.I will give information what will happened.

0 Kudos
Message 5 of 6
(5,063 Views)

Hi,

I applied your corrections to my programI write here what i do step by step;

1-I deleted read data local variable and from number1 to number16 local variable and i wired their outputs directly.

2-I added a timeout event in event structure as a 0 event in event loop.

3-I carried visa write block inside to each of event.

4-I changed "Seri Porta Yazma Aktif" named button mechanical property as a "Latched when released".

5-I deleted delay commands in arduino program.(Also i tried arduino code with delay commands after the making first four changes there is no different)

As a result of these changes

I can read analog outputs data continiously as a consequence of adding timeout event in event structre loop.While labview program is running i pushed "Seri Porta Yazma Aktif" button.For a short time if i success to do open and close for example "MOSFET" named relay button the relay is open and close.But to do this i have to change button position in a 2-3 seconds.And after 2-3 seconds later labview program is frozen and i cant change any button position but in this time data are coming continiously.

Now i tried to do basic example for reading and writing between labview and arduino and i want to talk with each other for a long time.I looked that you said example also i looked them before times.I cant run your examples that you give in this link.There is a error which oathkeeper said.Also oathkeeper gave a example but i cant understand how is this program running logic or is it running correctly.I added corrected program.I'm waiting your thoughts.Thanks a lot.

0 Kudos
Message 6 of 6
(5,063 Views)