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: 

Arduino won't accept my string from Labview

Solved!
Go to solution

Please tell me what I'm doing wrong.  I am just trying to send a simple string to the Arduino in this case "1,1,1" which tells the Arduino to turn on pin 13 for 5 seconds.  If I send the string via Serial Monitor on the Arduino IDE it works fine, but if I send it through labview it won't perform said action I want.  I apologize if this is similar to another forum post, but I've looked through what seems like thousands of posts and cannot get this to work with any of the solutions.  Thank you in advance.  Here is my block diagram and code:

 

abstrak_0-1634243835988.png

int led = 13;
char val;
String value;

 

void setup() {
Serial.begin(115200);
pinMode(led,OUTPUT);
}

 

void loop() {

if (Serial.available()>0){
value = "";
while (Serial.available()>0){
val = (char) Serial.read();
Serial.println(val);
value += val;
Serial.println(value);
delay(10);
}
if(value == "1,1,1"){
digitalWrite(led, HIGH);
delay(5000);
digitalWrite(led, LOW);
}
else {
digitalWrite(led, LOW);
}
}
}

0 Kudos
Message 1 of 6
(1,123 Views)

I suspect you are missing the carriage return/line feed at the end of your command. At a minimum you should terminate any strings you are sending with a Line Feed character.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 2 of 6
(1,108 Views)

You might want to add a delay after the VISA Write.  I suspect you are closing the port before the hardware has had a chance to send all of the data.

 

Also, you do not need the VISA Open.


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 3 of 6
(1,089 Views)

Hey guys,  I tried both of your suggestions and still nothing.  All that that happens is RX blinks once and pin 13 blinks repeatedly for a couple of seconds, waits a second and then blinks once, like it's receiving information (even though it's not the RX pin) and that's it.  When I send it through the Serial monitor RX blinks once and pin 13 goes high immediately for 5 seconds and turns off as intended (Just as an aside, I have no termination character set on the Serial monitor).  I just tried a different board and it's the same behavior.  If anyone can try this on their end and get it to work, I would appreciate it very much.  Thanks.

 

abstrak_0-1634304685884.png

 

0 Kudos
Message 4 of 6
(1,060 Views)

Also, another piece of information is that it exhibits the same behavior with RX blinking once and pin 13 blinking repeatedly, pausing for a second, and then blinking once more when I open the Serial Monitor on the Arduino IDE.  It might be relevant to the issue.

0 Kudos
Message 5 of 6
(1,057 Views)
Solution
Accepted by topic author abstrak

That last tidbit was the problem.  I added a two second delay after the serial port configuration vi and it worked as intended.

 

abstrak_0-1634305466789.png

 

0 Kudos
Message 6 of 6
(1,056 Views)