LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with serial port readings from LabVIEW to Arduino

Hello all,

 

Please forgive the ignorance of a beginner. I have searched through all relevant boards and have so far been unable to find a solution to my problem, I am hoping someone here can help me out.

 

The goal I am trying to accomplish is to control an Arduino via a joystick interfaced through LabVIEW. I found a joystick.vi online which is perfect for the one I am using (made for the same model) and now I would like to have it communicate characters to a serial port which connects to an Arduino. For exampel; if I press the trigger button, LabVIEW will send an 'A' to the serial port that the Arduino will read and react accordingly.

 

The step I am stuck on is writing to the serial port. I opened up the Serial Read and Write example in LabVIEW and tried setting it to read COM4 where the Arduino was connected. This worked fine and the message I wrote from Arduino displayed in LabVIEW. Now, same thing but writing 'A' in LabVIEW to trigger a pin connected to an LED does not work! I've set up a variable char in the Arduino code and set an if statement that commands it to set the pin to high if serial.read() == variableChar (which is A) but no matter how many times I send it the darn thing will not light up!

 

I am wondering if the problem could be the variable type but then again LabVIEW receives that same format and prints it fine!

 

Please help, I will really appreciate it! 

0 Kudos
Message 1 of 12
(5,598 Views)

Hi Akello,

 

Your syntax sounds correct to me; I would try a loopback test, wherein you write the character that the Arduino is receiving back to Labview, to make sure that the character you think you are sending is the one that you are actually sending.

 

Also, I don't know if you're aware of the Labview Interface for Arduino (LIFA) Toolkit, but it is a great resource for programming an Arduino with Labview. You can find it here. As a side note, if you have any questions about the LIFA Toolkit, there are dedicated forums linked on that page for supporting it.

 

Best,

Dan N

Applications Engineer

National Instruments  

0 Kudos
Message 2 of 12
(5,558 Views)

Thank you very much for the reply. I tried the loopback test and Arduino was having a problem reading/sending back what I sent. I would recieve things like FF followed by \n\r and then empty space when I ran the write/read several times in a row. I searched the forums and some people suggested LabVIEW could be sending things over in hexadecimal thereby causing an incompatibility problem. While looking for ways to convert from hex to char, I found a post by someone who said their Arduino read chars and had a code practically indentical to mine. The only difference was that they set the variable to int instead of char and though I am not sure why it worked, it solved my problem!

 

As for the LIFA, the project I am working on is going to be controlled remotely; the LabVIEW is only there to read a joystick and send commands as strings to a Wifly Shield mounted on an Arduino. Since the communication is different and not something I have a whole lot of experience with, I would rather keep this simple.

 

Thanks again,

Yusif Nurizade

0 Kudos
Message 3 of 12
(5,536 Views)

Hi Yusif,

 

Glad I could help out. And if you don't need LIFA for your application, that's totally ok; I just wanted to make sure you knew it existed.

 

Best,

Dan N

Applications Engineer

National Instruments 

0 Kudos
Message 4 of 12
(5,522 Views)

Hi Dan im using the VISA serial port method as im using a chipkit microcontroller which although is similar to the arduino but isn;t picked up by the LIFA tool kit. I my project is based on controlling an R.O.V through labview using an arduino as a DAQ. my controller is connected to the computer through usb and works fine with the vi i created to read any button pressed, now the problem is i want to pwm the xbox joystick through the arduino and just cant seem to get it working, any ideas?

 

thank you,

regards,

 

The developer.

0 Kudos
Message 5 of 12
(5,480 Views)

A good place to go for advice on arduino and other microcontrollers is our NI community page at ni.com/arduino. There, some of our engineers and other enthusiasts in our community will be able to help with your microcontroller issues.

 

Hope this Helps,

 

Doug B

Applications Engineer

Applications Engineer
National Instruments
0 Kudos
Message 6 of 12
(5,457 Views)

Hello  all

            The problem I face is quite erratic . When I interfaced LabVIEW with arduino, the first time I run the program, such as turning an led on or off, it works. But when I run it the second time, it fails. as in the TXD RXD pin themselves are not glowing and my error shows that my digital pin doesnt exist at all. I ve attached a screenshot of it. help me!

0 Kudos
Message 7 of 12
(4,638 Views)

@aarthiem wrote:

Hello  all

            The problem I face is quite erratic . When I interfaced LabVIEW with arduino, the first time I run the program, such as turning an led on or off, it works. But when I run it the second time, it fails. as in the TXD RXD pin themselves are not glowing and my error shows that my digital pin doesnt exist at all. I ve attached a screenshot of it. help me!



How are you stopping that VI?  Are you hitting the big red stop button that you should never use ever?  If so then then analogy is you are stopping a car by crashing it into a tree instead of using the brakes.  

 

Stop your program gracefully by stopping the while loop and performing cleanup.  If you don't do this then LabVIEW never releases the serial port resource and you can't use it again.

Message 8 of 12
(4,635 Views)

anks a lot! and especially for your prompt reply 🙂  you saved me 🙂 yeah I was doing the stop button clicking. Will follow as you mentioned yaar 🙂 thank you so so much really!!

I think now it should work! but anyway, i ll let you know if it does work now:)

0 Kudos
Message 9 of 12
(4,620 Views)

I have yet another problem. The output value of a my voltage is an array and am unabke to connect it to the error in and out of the CLOSE arduino icon. The following is the error message in the VI. Can anyone help me pls

0 Kudos
Message 10 of 12
(4,576 Views)