04-02-2012 11:08 AM
Can somebody please tell me if LIFA supports interrupt handling? Or can we write our own function for handling interrupts with LIFA?
Any help is greatly appreciated. Thanks.
/Manjula
Solved! Go to Solution.
04-02-2012 04:14 PM
04-02-2012 04:35 PM
Thank you for your response, Albert. Acutally, I do not plan to run the Arduino coupled to the PC, what I need to develop the VI that handle interrupts correctly and download it to Arduino and run it stand alone. Please let me know if I am mistaken with something here.
04-02-2012 05:15 PM
Hello,
thank you for posting this question, it is an interesting subject.
I think Albert is right, although I hope Arduino interrupt function in LV will be implemented in future.
I have been using AttachInterrupt() right now successfully on Arduino UNO pin 3 to detect changes (rising and falling edges) from a rotary encoder and increment a counter, (1 to 360) but then I developed the code and the graphics further in Arduino IDE. I am also checking Processing, better for graphics.
Problem 1 whith LIFA:
When I compile this sketch I get an error (blink not declared in the scope)
Problem 2 with variable:
I have not been able, by now, to transfer the counter value to Labview 2011.
I was also thinking to write the counter value (from 1 to 360) on an analog pin (using analogWrite) and have it read by the corresponding function in the Arduino palette, but I discovered that you cannot use analogWrite for that, it is only possible to use it on these digital pins 3,5,6,9,10,11 for PWM. Furthermore, analogWrite has a range of 0-255, the value should be remapped i.e. y = map(x, 0, 255, 0, 360); and I am not sure about accuracy and timing.
I wonder if a variable in Arduino sketch could be displayed by an indicator in Labview?
The attached test LIFA is NOT working. If anybody has suggestions, thank you in advance.
I paste the code, I was not able to send as attachment
#include <Wire.h>
#include <SPI.h>
#include <Servo.h>
#include "LabVIEWInterface.h"
int pin = 13;
volatile int state = LOW;
int counter = 0;
void setup()
{
// Initialize Serial Port With The Default Baud Rate
syncLV();
// interrupt and variable definitions
pinMode(pin, OUTPUT);
pinMode(3, INPUT);
digitalWrite(3, HIGH); //attiva resistore pullup pin 3
attachInterrupt(1, blink, CHANGE); //definisci interrupt,detect change on D3 and start blink function
Serial.begin(115200);
}
void loop()
{
// Check for commands from LabVIEW and process them.
checkForCommand();
// Here is the custom loop code (this may slow down communication with LabVIEW)
{
digitalWrite(pin, state); //
Serial.println(state);
Serial.println(counter/2); // I am counting changes, thus both rising and falling edges, therefore divide by 2
}
void blink()
{ state = !state;
counter = counter++;
//analogWrite(1, counter); //WRONG, cannot be used to write the counter value on A1 and have it read by Labview
}
if(acqMode==1)
{
sampleContinously();
}
}
04-03-2012 12:07 PM
08-08-2012 09:26 AM
I am posting this to add a conclusion to this thread. I was teaching Arduino controller to some mechanical engineering students who had the background on some basic LabView. That was the reason for me to originally ask for any available interrupt routines on LIFA.
After your feedback, I decided LIFA is not a complete solution for Arduino still and rewrote our lab for stundets to learn Arduino code and program. It worked really well, thought most of the students had Matlab as their only computing backgorund.
Now we do not have a reason to go back to LIFA.
Thanks you all for participating the discussion.