From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

activating LED with Visa Write causes value changes to the sensors (Visa Read)

Hi guys, 

 

When I want to activate a LED with the Visa Write, it changes the values of the sensors. I tried different methods, different delay values... But nothing seems to work. I don't know if it has to do something with my arduino or labview  code. The Led shouldn't have an impact on the values.

Could you guys help me out with this.

 

I'm Going to put the whole project here, you guys should only pay attention to the 'Visa write and read' part.

Hope you guys can help me out. 

 

My arduino code:

 

int LedY1 = 12;
int LedY2 = 13;
int LedG1 = 11;
int LedG2 = 10;
int LedR = 9;
String L1;
String L2;
String T1;
int data;
String string, c;


void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  pinMode(LedY1,OUTPUT);
  pinMode(LedY2,OUTPUT);
  pinMode(LedG1,OUTPUT);
  pinMode(LedG2,OUTPUT);
  pinMode(LedR,OUTPUT);
}

 

 

void loop() {

  if(Serial.available()>0)

  {

  data=Serial.read();

  if(data=='1')

  {
  digitalWrite(LedY2,HIGH);

  }

  else if(data=='0')

  {

  digitalWrite(LedY2,LOW);

  }

  }


  delay(200);

  // reads the input on analog pin A0 (value between 0 and 1023)
  int analogValue = analogRead(A0); //lichtsensor 1
  int analogValue2 = analogRead(A1); //lichtsensor 2
  int analogValue3 = analogRead(A2); // temp

  L1 = analogValue;
  L2 = analogValue2;
  T1 = analogValue3;

  Serial.println("T=" + T1 + "L2=" + L2 + "L1=" + L1);
}

 

0 Kudos
Message 1 of 6
(999 Views)

Here is also my subvi if needed

0 Kudos
Message 2 of 6
(998 Views)

Please use block diagram cleanup.  There is a lot of white space.  It takes it from 4 screens of code down to something that fits in 1 screen with just a single click!

 

What exactly are your sensors?  The only thing I see is a sort of simulation with your subVI.

 

Why do you have the i terminal of the while loop wired to the VISA read?

 

First iteration read 0 bytes, 2nd read 1 byte, 3rd read 2 bytes, ....   1,000,000 iteration read 999,999 bytes (which will take forever and time out!)  It makes no sense.

0 Kudos
Message 3 of 6
(951 Views)

@RavensFan wrote:

Please use block diagram cleanup.  There is a lot of white space.  It takes it from 4 screens of code down to something that fits in 1 screen with just a single click!

 

What exactly are your sensors?  The only thing I see is a sort of simulation with your subVI.

 

Why do you have the i terminal of the while loop wired to the VISA read?

 

First iteration read 0 bytes, 2nd read 1 byte, 3rd read 2 bytes, ....   1,000,000 iteration read 999,999 bytes (which will take forever and time out!)  It makes no sense.


I'd have to say that's pretty ugly code for a self-proclaimed "Labview" master.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 4 of 6
(941 Views)

The first thing I would do is change the format of the data you are sending form the Arudino.  I would change it to:

Serial.println(T1 + ";" + L2 + ";" + L1);

 

With that update, you can eliminate the code you use to format your file data.  You can just write the string straight from the VISA Read.

 

As far as your serial port usage, I don't see why you need 2 ports; you should just be using the one port.  A single port can read and write.

 

Next, get rid of all of the VISA Clear and Flush IO Buffer functions.  They are not needed.

 

For the read, just tell the VISA Read to read more bytes than you expect in a message.  You have the termination character turned on and set correctly since the println command will append the termination character for you.  So just wire a constant 50 to the number of bytes to read and the read will stop when the termination character is read.

 

For parsing the read data, just use the Scan From String with a format of "%f;%f;%f" (assuming you follow my advice above).

 

There is no reason to use a shift register to store string data you already wrote to the file.

 

You should consider using the actual File IO functions to create/open the file and write the header before the loop, close the file after the loop, and use Write To Text File to write the data as much as you want inside of the loop.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 6
(906 Views)

@billko wrote:

@RavensFan wrote:

Please use block diagram cleanup.  There is a lot of white space.  It takes it from 4 screens of code down to something that fits in 1 screen with just a single click!

 

What exactly are your sensors?  The only thing I see is a sort of simulation with your subVI.

 

Why do you have the i terminal of the while loop wired to the VISA read?

 

First iteration read 0 bytes, 2nd read 1 byte, 3rd read 2 bytes, ....   1,000,000 iteration read 999,999 bytes (which will take forever and time out!)  It makes no sense.


I'd have to say that's pretty ugly code for a self-proclaimed "Labview" master.


There is now no reason for my post because the user chose a new user name that no longer describes a level of experience.  😄

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 6
(870 Views)