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.
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.
07-24-2015 02:20 AM - edited 07-24-2015 02:23 AM
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.
07-24-2015 07:27 AM
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.
07-27-2015 03:55 AM
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?
07-27-2015 08:22 AM
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 }
07-27-2015 09:18 PM
Thank you.
I apply your source to arduino.
and communication does not gain speed as ever.