LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read value in arduino from labview

Solved!
Go to solution

Hi Friendly Smart Labview Community,
I'm Dong, a student in Thailand. I'm doing my tiny research but I got problem when I try to read value from labview to arduino. I can't get data and I don't know what wrong in my code. I hope the community can give me some solutions or advices. Thank you so much, you guys!!!

 

 

 

int ledPin = 8; 
void setup() {
  Serial.begin(9600); 
  pinMode(ledPin, OUTPUT); 
}

void loop() {
  if (Serial.available() > 0) {
    String receivedString = Serial.readStringUntil('\n');
    float receivedFloat = receivedString.toFloat();
    int receivedValue = int(receivedFloat + 0.5); 
    if (receivedValue >= 5) { 
      digitalWrite(ledPin, HIGH); 
    } else {
      digitalWrite(ledPin, LOW);
    }
  }
}

 

 

 

 

0 Kudos
Message 1 of 3
(960 Views)
Solution
Accepted by topic author phuocdong147@gmail.com

Your main problem is that you are not sending the Line Feed.

 

1. Change your VISA Open to VISA Configure Serial Port.  This will set up your serial port more exactly instead of trusting the defaults.

2. Change your Number To Fractional String to a Format String.  This will allow you to easily append the Line Feed character.


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 2 of 3
(953 Views)

Thank you so much KNIGHT OF NI !!!!!!
I already tried and it sucessed. I'll find out reference about "Format into string" to study more

0 Kudos
Message 3 of 3
(942 Views)