LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Visa serial communication problem with Arduino

Hello,

 

I made a movable shutter with Servo motor and Arduino board. The program that I made is that when 'y' value is sent to the Arduino board, the motor turns 60 degree. If 'n' value is sent, the motor turns 0 degree (going back to its original position).

 

I checked that the programming is working well.  Below is the part of my code:

void recvOneChar() {
  if (Serial.available() > 0) {
      char c = Serial.read();
      if(c == 'y') {
        myservo.write(60);
      
      }
      if(c == 'n') {
        myservo.write(0);
      }

 

I want to send the serial input value by Labview. I also attached the block diagram of the shutter VI. When I type 'y'  or 'n' to "the string to the write", the Arduino board looks like receiving some signal but the motor does not move at all. I don't know what is the problem. I double-checked that the correct COM port was selected! Please give me any advice which makes the VI work!

 

Thanks!

 

Download All
0 Kudos
Message 1 of 6
(3,267 Views)

Your VI looks okay considering it is just the basic serial example.  You can eliminate the bytes at port (almost never the right thing to use) and the VISA Read since you are never reading any data back from the Ardunio.

 

So do you know that the Arduino is receiving any data?  Do you have the right cable?  Serial parameters match, not just com port but baud rate, data bits, stop bits, parity?

Do you know if your MyServo.Write function actually works?

0 Kudos
Message 2 of 6
(3,240 Views)

Thanks for your reply.

 

I think the Arduino is receiving data from the PC. When I input "y" in the string box and run the VI, the lamp on the Arduino board is blinking. It looks like something happens. I think I use the right cable: USB A/B. Also, I do match the baud rate as 9600 when I programmed the Arduino. However, I'm not sure I have to change data bits, parity, stop bits. How can I find the right value for the Arduino?

Also, I already checked the code itself. The code is working well, and I can see the servo is moving when I control the servo via the Arduino program. 

0 Kudos
Message 3 of 6
(3,219 Views)

No idea.  You'd have to ask on an Arduino forum about that.

 

With the Arduino code you show, it looks like only a single subroutine.  Is there any other code?  Somewhere you must have a loop so that it can continually check for data coming in.

0 Kudos
Message 4 of 6
(3,215 Views)

Here is the whole code. There is no problem with the code for the Arduino so I thought the problem is related with the Labview. Here is the whole Arduino code for your information.

 

#include "Servo.h"

Servo myservo;  // create servo object to control a servo

void setup() {
   myservo.attach(9);  // attaches the servo on pin 9 to the servo object
   Serial.begin(9600);  
   myservo.write(0);
}

void loop () {
      
  recvOneChar();
}

void recvOneChar() {
  if (Serial.available() > 0) {
      char c = Serial.read();
      if(c == 'y') {
        myservo.write(60);
      
      }
      if(c == 'n') {
        myservo.write(0);
      }
}}

0 Kudos
Message 5 of 6
(3,211 Views)

How are you sure it is not a problem with your Arduino code?

 

Have you written a program that doesn't involve the serial port or LabVIEW that makes the servo move?

 

One thing I see when I changed your VISA Write to hex display is that you are actually sending a "y" and carriage return.  Not just a "y".  Eliminate the carriage return.  But I don't think that would cause a problem.

0 Kudos
Message 6 of 6
(3,193 Views)