03-28-2017 10:58 AM
Hello everyone, I am new to LabView VISA.
My application is to read data from LDR and turn on and off bulb accordingly, the switching of bulbs is to be displayed in LabView. The program runs perfectly in Arduino and I want to indicate the bulb on/off in labview. I am using VISA for displaying the switching of bulbs.
Arduino program:
volatile int glight,Lstate;
void setup()
{
pinMode(5,OUTPUT);
Serial.begin(9600);
}
void loop()
{
glight=analogRead(A0); //ldr sensor
if(glight<140)
{
digitalWrite(5,HIGH);
Lstate=0;
}
else if(150< glight < 300)
{
digitalWrite(5,LOW);
Lstate=1;
}
Serial.print("L");
Serial.print(Lstate);
}
In LabView I sometimes get correct output indicating that the bulb is ON but that occurs only once and after that it does not run(after it executives once it shows error 85 or sometimes 1 but I assure you the connections are tight and correct). Also a point I should mention is that when I run the LabView program(Highlight Execution: ON) on the "Read buffer" from VISA Read the value that gets passed is "L0L0L0" or "L1L1L1" why does it do this? it should only show L0 or L1. Please Help!
Solved! Go to Solution.
03-28-2017 11:46 AM
In your Arduino code, use "Serial.println(Lstate);". The println adds a termination character to the end of the message. Since you already have VISA configured to use the termination character, you might as well send it. This will limit the read to just your single message instead of all of the messages up to 2000 characters.
From what I am seeing, you should also remove the VISA Write from the LabVIEW code. I do not see where your Arduino is reading it, so that part is worthless.
And finally, you might want to add a wait of some sort to your Arduino loop so you can have more deterministic message rates.
03-28-2017 11:59 AM
Hi
In VISA you are writing to and reading from the Arduino.
The Arduino is not listening, so why writing to it?
You are also reading 2000 characters from the Arduino in LabVIEW why not 2?
So just read two characters or 4 if CR LF is added but I believe it is not.
Check in LabVIEW if a 1 or a 0 occurs in that string and read again.
I send the modified version back. Only thing you need to do is eventually change the wait to longer or shorter and more important fill in the port to listen to.
03-28-2017 12:09 PM - edited 03-28-2017 12:11 PM
And just to confuse you some more, here is another simplified version. It does make the assumption you changed that line in the Arduino like I told you above (println). Also note that your VISA Read will limit the loop rate. So no need for an additional wait which will likely force you to be behind in the message retrieval.
03-29-2017 08:48 AM
I can't thank you and '@Albert. Geven'!
I did as you two asked me to, removed the Serial Write because it was not necessary as I was only reading the data from Arduino and secondly the 'Serial.println()' to terminate the continuous read of the data which was causing the error. though I should mention that I used 'Scan from string' function as I had multiple outputs to read at once.
01-29-2018 11:48 PM
Hi all,
I've some problem with reading serial data from arduino too. i already test the serial data are works at serial monitor in arduino software, but it not show at my lab view project.
This is my arduino program.
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println(analogRead(0));
}
Please help me
02-01-2018 11:39 AM
caturpermadi,
You are using a different methodology than the original poster as you are using the LIFA toolkit vi's. If you are going to continue to use LIFA you must load their firmware onto your arduino. Note that LIFA is old and the person who developed it has replaced it with LINX. If you have questions about LINX after going through their tutorials you should probably post them to their website forums.