LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Is event-based programming possible, with Arduino-originated events?

Solved!
Go to solution

First, thanks for the great products. (Both LabVIEW and LIFA.) Both work very well.

Having taken Core 1 and Core 2, I see the value of event-based programming. Is this possible with the Arduino, where LV sleeps until the Arduino notifies it of some event? For example, right now anytime I need to read a button press, I have to poll the Arduino. The RX and TX lights on the board don't get a break. It would be great if LV and Arduino could coordinate things such that I could create an event in my VI that executes only when a certain digital pin is asserted.

An alternate way of asking this: there's already a Digital Read low-level function. It returns a value no matter what. I want a Digital Read Blocking function that'll block (on the Arduino side! No polling!) until I get the value I am looking for.

0 Kudos
Message 1 of 8
(9,835 Views)

Hey,

You can set upa digital read function with no timeout that just waits until a byte is written to the serial port by the Arduino. You will have to set it up so that it polls the serial port every once in a while to see if the byte is available though.

Kevin Fort
Principal Software Engineer
NI
0 Kudos
Message 2 of 8
(4,887 Views)

Kevin, can you elaborate on how this works? The function waits until a byte is written, yet it still polls? Is it just an abstraction for a while loop that polls every X ms and stops once it gets the right value?

My experience is with programming languages like C++, so I am trying to map my knowledge of C++, with its powerful callback / asynchronous IO capabilities, to LabVIEW.

Right now my VI consists of two threads: one that continuously polls a digital pin and generates a notification if the pin is asserted (button is pressed), and another thread that waits for a notification and runs the main logic. The latter thread also clears any pending notifications at the end of its iteration, since as a side effect, the tight loop occasionally generates multiple notifications for a single button press. This works well.

But I dream of a way to tie an indicator to a special function (and maybe it's one you mentioned, which waits for a byte) that'll block until my button is pressed. The key is that it should block until the Arduino notifies it of a new digital value, rather than polling.

0 Kudos
Message 3 of 8
(4,887 Views)

What I was describing is essentially an abstraction of a while loop which polls every Xms. Since the communication between the Arduino and the PC is over serial there is no good way to set up a method other than polling. Is there a reason you can't use polling in your application? You shouldn't see any performance hit as long as you don't set it up to poll as quickly as possible -adding a 10ms wait in the check for bytes at port loop for example.

Kevin Fort
Principal Software Engineer
NI
Message 4 of 8
(4,887 Views)

No, there's no reason I cannot use polling. I just wanted to avoid polling since it's not as efficient as the Arduino sending a single notification when the value changes. (Similar to how Core 2 teaches us to use events instead of a simple while loop for acting on UI controls.)

If polling pins is the recommended (or the only) way, then that's fine with me. Thanks.

0 Kudos
Message 5 of 8
(4,887 Views)
Solution
Accepted by topic author IowaPhilip

National Instruments has other software better suited for event driven programming than LIFA.  See:

<https://www.ni.com/en/support/documentation/supplemental/06/event-driven-programming-in-labview.html>

<https://www.ni.com/en/support/documentation/supplemental/21/getting-started-with-daqmx-daqmx-events....>

 

Then there is also event driven programming available for Arduino.  See:

<http://www.state-machine.com/arduino/>

 

Howard

0 Kudos
Message 6 of 8
(4,887 Views)

Thanks, hrh1818, that's very helpful. But is DAQmx compatible with Arduino?

Also, thank you for the pointer to state-machine.com. Their software is very appealing.

0 Kudos
Message 7 of 8
(4,887 Views)

NO.  DAQmx is not directly compatible with Arduino.  Depending upon what you are trying to accomplish you possibly could use a digital I/O interface like the following with a DAQmx driver to interface the events your Arduino program generates to Labview.

 

<https://www.ni.com/en-us/shop/model/usb-6501.html>

Or

<https://www.ni.com/en-us/support/model.usb-6008.html>

 

Howard

0 Kudos
Message 8 of 8
(4,887 Views)