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.

Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

ArduinoDUE and Labview

Hello.

 

I am trying to communicate between Labview and Arduino DUE for DC motor control.

and now i can control the DC motor using PWM signal given from Labview(by serial communication)

but i face the problem here. the problem is that serial communication speed is very slow..  i think Loop time period is about 1sec.

 

when i set the byte count of VISA Read function to zero these communicate very fast

but in other settings there is a problem.

 

Can i get some help, please.

thank you.  

그림2.gif

0 Kudos
Message 1 of 5
(4,986 Views)

The serial read is probably timing out while waiting for a termination character. Try sending text instead of binary; replace the Serial.write() call with Serial.println() (using println instead of print puts a linefeed at the end, which LabView's Serial Read can detect as a termination character). You'll of course need to use a string to number conversion routine in your VI. 

0 Kudos
Message 2 of 5
(4,931 Views)

Thank you!!

 

I use the println() and it is be much better!

 

But sometimes communication stops short and there is a error between writePWM and ReadPWM..

 

Could you tell me What the cause?

 

 

 

0 Kudos
Message 3 of 5
(4,884 Views)

What sort of error is thrown?

 

Looking at your Arduino code, it is set up to respond to serial inquiries only for one minute after boot/reset, and subsequently just writes 0 to R_PWM over and over again. 

 

while (newtime < 60) { //units : sec
    newtime = micros() * 0.000001; //units : sec

    if ( Serial.available()) {
      // cast the string read in an integer
      readNumber = Serial.parseInt();
    }
    
    digitalWrite(R_in1, LOW);//Motor rotation direction control
    digitalWrite(R_in2, HIGH);//Motor rotation direction control
    analogWrite(R_PWM, readNumber);//PWM write
    Serial.println(readNumber);
    

  }
  analogWrite(R_PWM, 0);

That conditional on the while loop only triggers for the first minute of the program running (the Arduino program, not the LabView VI). After that, there's no data printed to the serial port for LabView to read. A cleaner way to shut the motor down would be to have the Arduino continuously reading values from LabView, and to have LabView send a PWM=0 value after the stop button in the loop is active:

 

void loop() {
    if ( Serial.available()) {
      // cast the string read in an integer
      readNumber = Serial.parseInt();
    }
    
    digitalWrite(R_in1, LOW);//Motor rotation direction control
    digitalWrite(R_in2, HIGH);//Motor rotation direction control
    analogWrite(R_PWM, readNumber);//PWM write
    Serial.println(readNumber);
    delay(50); //50 ms loop interval
}
0 Kudos
Message 4 of 5
(4,862 Views)

Thank you.

 

I apply your source to arduino.

 

and communication  does not gain speed as ever.

 

캡처.JPG

0 Kudos
Message 5 of 5
(4,839 Views)