Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview serial communication with Arduino to actuate relays

 I've created the attached VI to communicate over comm port with an Arduino that I want to use to control a couple relays. The Arduino actuates the relays quickly when triggered through the Arduino IDE, but I haven't been able to get it to work with LabView without including at least 1.516 seconds of delay before the VISA Write subVI I'm using to dump an integer into the serial channel as a trigger. My first thought was increase the baud rate from 9600, but after trying a couple higher rates including 115200, I saw no change in behavior. Open to suggestions if anyone is willing to offer. My Arduino code is below. Thanks in advance.
________________________________________________________________________________________
int Relay1 = 4;
int Relay2 = 2;
int incomingByte1;

void setup() {
  pinMode(13, OUTPUT);     //Set Pin13 as output
  digitalWrite(13, HIGH);  //Set Pin13 High
  pinMode(Relay1, OUTPUT); //Set Pin4 as output
  pinMode(Relay2, OUTPUT); //Set Pin2 as output
  Serial.begin(9600); //Start serial communication at 9600 baud
}
void loop() {
 if (Serial.available() > 0) {
  incomingByte1 = Serial.read();
  if (incomingByte1 == 50)  //Sets negative polarity to relays on 2 input
  {digitalWrite(Relay1, LOW);
  digitalWrite(Relay2, HIGH);
  Serial.println("DOWN");    //Negative polarity string to indicator
  }
  else if (incomingByte1 == 51)  //Sets positive polarity to relays on 3 input
  {digitalWrite(Relay1, HIGH);
  digitalWrite(Relay2, LOW);
  Serial.println("UP");    //Positive polarity string to indicator
  }
  else {Serial.println(incomingByte1);}  //Sends trigger byte to indicator in all other cases
  }
}
 
What_a_Wookiee_0-1778621337194.png

 

0 Kudos
Message 1 of 5
(256 Views)

If you just want to get it done, use the LabVIEW Hobbyist Toolkit Download - NI and control the Digital Output lines from LabVIEW.

 

 

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution
0 Kudos
Message 2 of 5
(218 Views)

1. You should not need to flush the buffer on either end of your transaction.

2. That delay really should not be needed. You might want to try making a proper loop with an Event Structure in it so you can interactively control the Boolean control and send the command when required. Initialize the serial port before the loop and close the resource after the loop.



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 3 of 5
(190 Views)

I don't want to just "get it done".  I want to know what's causing the issue with my current iteration.

0 Kudos
Message 4 of 5
(87 Views)

Not flushing the buffer on one or both sides did not change the behavior.  I started with no delay and the VI didn't work at all.  It only works when I add in the delay with minimum 1.516 s of delay time.  Anything less than that and it stops working.  I also had it with a while loop structure to begin with, but it did not affect the behavior with or without the loop.  I'm wanting to use that VI as a subVI for a larger program, so I don't really have need for a loop structure in there in the final version.

0 Kudos
Message 5 of 5
(82 Views)