02-03-2013 01:48 PM
Hey, I am relatively new to the Arduino/LIFA community. That being said, forgive me for not knowing the answer to this question if it seems relatively obvious.
I am working on a project which requires me to take data from a breakout board that consists of an accelerometer and angular rate sensor. The breakout board has pre-existing Arduino sketch code which turns the data being sent from the breakout board into tangible values that can displayed on the serial monitor on the Arduino IDE. However, I would like to process some of the data using LabVIEW. I tried copying and pasting the sketch with the LIFA_Base.ino on order to retrieve the data in the form that I can already use. Although I can still observe the values on the serial monitor, my Arduino cannot interface with LabVIEW at all in order to display and process the data. I was wondering then, is there a way that I can use the pre-existing sketch with the LIFA_Base.ino at the same time? Or is the only way that I can get the values is to convert the pre-existing sketch into a .vi after LIFA passes the data packets through?
Thanks you for your help!
02-04-2013 12:25 AM
You will either need to recreate everything in LabVIEW (assuming it's possible with existing LIFA functions) or you will need to create custom LIFA functions (in LabVIEW and in the LIFA firmeware/sketch). In the latter situation, you can process the raw data into the the real values and then send that back to LabVIEW.
02-04-2013 10:36 AM
Hey, Nathan.
That's what I thought. Thank you for your response!
02-08-2013 02:29 PM
You can also add custom Arduino code to the LIFA firmwar in the main() loop. Just make to leave the processCommand() function in there and keep in mind that anything you add to the firmware will slow down the communication with LabVIEW (ie slower loop rates in LV).
-Sam K
LIFA Developer
03-05-2013 09:24 PM
Sammy, I could use some guidance here. I tried this earlier but it didn't work. I just wanted an LED to blink automaticallly by a sketch and have another LED blink via Labview. Here's what I did on the LIFA_BASE:
/*********************************************************************************
**
** LVFA_Firmware - Provides Basic Arduino Sketch For Interfacing With LabVIEW.
**
** Written By: Sam Kristoff - National Instruments
** Written On: November 2010
** Last Updated: Dec 2011 - Kevin Fort - National Instruments
**
** This File May Be Modified And Re-Distributed Freely. Original File Content
** Written By Sam Kristoff And Available At www.ni.com/arduino.
**
*********************************************************************************/
/*********************************************************************************
**
** Includes.
**
********************************************************************************/
// Standard includes. These should always be included.
#include <Wire.h>
#include <SPI.h>
#include <Servo.h>
#include "LabVIEWInterface.h"
int led = 13; <---my addition
/*********************************************************************************
** setup()
**
** Initialize the Arduino and setup serial communication.
**
** Input: None
** Output: None
*********************************************************************************/
void setup()
{
// Initialize Serial Port With The Default Baud Rate
syncLV();
// Place your custom setup code here
pinMode(led, OUTPUT); <---my addition
}
/*********************************************************************************
** loop()
**
** The main loop. This loop runs continuously on the Arduino. It
** receives and processes serial commands from LabVIEW.
**
** Input: None
** Output: None
*********************************************************************************/
void loop()
{
// Check for commands from LabVIEW and process them.
checkForCommand();
// Place your custom loop code here (this may slow down communication with LabVIEW)
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) <---my additions
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000);
if(acqMode==1)
{
sampleContinously();
}
}
The LED on pin 13 fails to blink automatically but I have communication with the Arduino via Labview. What is this processCommand() do you talk about? Thank you in advance.
03-05-2013 11:00 PM
processCommand() is called by checkForCommand() and is the code that communicates with LabVIEW (essentially), it contains all the functions available in LabVIEW.
Honestly, I'm surprised LabVIEW doesn't timeout because it has to wait 2 full seconds to process anything from LabVIEW over serial. Are you sure you compiled AND uploaded the new code to Arduino?
For the blinking light and to still process code from LabVIEW in more timely manner, you can use a conditional to check if 1 second (1000 ms) has passed then toggle the LED then.
03-06-2013 01:47 PM
Ok, I played around and noticed something strange. When my
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
were below the checkForCommand();, the LED blinked continuously but failed to communicate with Labview; I couldn't control my OTHER LED with button on Labview.
However, when the
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
were below sampleContinously();, the LED failed to blink automatically but I did have communication with Labview with my OTHER LED. I'm a bit lost. I just want one LED to blink from a sketch and another to be controlled by Labview. Obviously, there's something wrong with my setup in LIFA_Base.
03-06-2013 03:01 PM
Have you tried the thing that I stated in the last sentence of my last post?
Should be something like this psuedo code:
if now > next
if state = HIGH
digitalWrite(led, LOW)
state = LOW
else
digitalWrite(led, HIGH)
state = HIGH
endif
next = now + 1000ms
endif
03-06-2013 06:34 PM
Didn't really work out for me. Can I make just make a cpp with a header file along side the LIFA? It'd be great if someone could point me to a place where I can just write any sketch I want that'll work along side with Labview.
03-06-2013 07:26 PM
Everything that you put in that area should be executed just fine. Notice how sampleContinously() will run while acqMode is 1. Another C file to include will just be the same thing as putting code in that loop (if you use a function from that C file in the loop) since your function must be in that loop somewhere.
I can't think of anything obvious that would be causing this. My last resort would be to request that you attach the firmware files that you have modified (preferrably the last method that I mentioned).