LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

detect change of status of digital pin and send to counter (indicator)

Solved!
Go to solution

Hello everybody, is there any option to detect the change of status of a digital pin, possibly differentiating a rising or falling edge, and send it to a counter (indicator) on Labview 2011?

This basic test gets the encoder signal on D3 from Arduino UNO, plots it and displays 1 (HIGH) or 0 (LOW) in 'Value'.

If HIGH turns led on DO13 on, if LOW turns DO13 off and increments a shift register.

I am looking to make a X,Y graph with Analog input AI0 and encoder input DI3.

I tried with an the event structure detecting a change in 'Value' indicator but i did not worked.

Thank you.

George

0 Kudos
Message 1 of 16
(11,383 Views)

you can store the value of digital read pin 3 as a variable and compare to it later

if pin 3 starts at 1, or high, declare your variable = 1

if pin 3 starts at 0, or low, declare your variable = 0

then you use the "NOT EQUAL" comparator.  directly connect the Read Digital Pin block to y and the variable to x (or the other way around if you want).  Then if TRUE (you will need a case structure for this), and that they are not equal, thus, a change in value, shift register, or even just have a numeric and increment it by 1 and save the value of digital read as the new variable.

There is probably a more elegant way out there, but this should work.  Just think of things kinda like in the Aduino IDE :).  What would you do if you were there, you know.

UPDATE

I did a little hunting and stuff and here is a most inelegant solution to the problem, but it works.  Please change your COM port back to 9 or whatever, as my arduino was on a different port .  Hope this helps!

0 Kudos
Message 2 of 16
(4,783 Views)

George,

Here is a snippet that I use for this.  I cannot take credit for this since I found it somewhere else on the web but it seems to work great.  I'm sure you can probably change the analog to digitan and still pick up the change of state,  Detect Edge - Analog Signal.png

Message 3 of 16
(4,783 Views)
Solution
Accepted by topic author feanorou

Here is another way to detect and differentiate edges.

0 Kudos
Message 4 of 16
(4,783 Views)

Is there anyway that this could be made available in Labview 2010?  Or atleast show me what the block diagram would look like? 

0 Kudos
Message 5 of 16
(4,783 Views)

I'm not sure if you are asking me so I will post a 2010 version here anyways.

0 Kudos
Message 6 of 16
(4,783 Views)

@NathanB.

Thank you for posting this.  However, I'm still trying to figure out how I can turn this edge detection signal into a usable count for the quadrature encoder I'm using.  This code doesn't have any way of reading encoder pulses or the direction the encoder is spinning, correct? 

0 Kudos
Message 7 of 16
(4,783 Views)

Follow-up...I am also checking the use of interrupts, which are definitely the best way to handle state changes and perfect for quadrature encoders.  I hope attachInterrupt / detachInterrupt (interrupt, function, mode) with examples will be soon added to LIFA palette.

0 Kudos
Message 8 of 16
(4,783 Views)

The code that I posted is not designed for quadrature encoder use, it is extremely simple (meaning it probably wouldn't work for moderate resolution encoders).  I would not recommend using LabVIEW to do the work for a quadrature encoder.  You should have Arduino do it for you then add functions to set/read values from the encoder count.  I have working code for three independednt quadrature encoders (counting done on the arduino using interupt pins) with LabVIEW VIs for LIFA 1.3.0.26 (Had issues with the newest version so we had to downgrade).  It uses the encoder library that you can get through a couple links on the Arduino website.

Note:  I'm using Arduino Mega 2560 which has 3 pairs of interupt pins.  The Uno, IIRC, only has two pair and will only allow for 2 good encoder setups.

0 Kudos
Message 9 of 16
(4,783 Views)

Genesisfactor can you please upload your code for LV 2010. I would appreciate it.

Thanks.

0 Kudos
Message 10 of 16
(4,783 Views)