LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Joystick Read + Serial Write to Arduino with LabVIEW

Yusif,

 

The delay is there to allow for processing on either end. Usually when you send a command to a device like a oscilloscope it will take a little bit for the device to get the data ready. If you read instantly the device won't be ready to send data back. It is a good idea to leave them in there to allow for the other device to get ready. Depending on your application it may or may not be necessary. 

Kyle Hartley
Senior Embedded Software Engineer

0 Kudos
Message 31 of 36
(1,016 Views)

In my case the joystick is sending commands to a microcontroller and the microcontroller is sending readings back. The commands the joystick sends are independent of the readings that a received and vice versa. Furthermore, the readings are taken off different pins on the microcontroller than the ones that are executing the commands and they would be inherently different (go forward full speed vs. voltage level). I am not positive but since we are using UART and the RX/TX pins are different there should be no overlap between write and read. Finally, the readings should be happening constantly, say once every 0.5 seconds, while the writes will only happen as necessary in terms of sending commands.

 

Given this scenario, do I need the delay? I suspect the answer is no but I would like to confirm. Also, if the answer is in fact no, do I run read and write in parrallel or in series as in the example but without the delay.

 

Thanks so much for the help Smiley Happy,

Yusif

0 Kudos
Message 32 of 36
(1,010 Views)

Akello, 

 

The delay is purely for preparation of data on either devices end. Say when you send a string "ID?" to the Arduino and you want it to send back a long string. LabVIEW would write "ID?" to the serial port. The delay in the LabVIEW code give the Arduino time so it can go to memory, grab the data, and start buffering it back across the serial connection when LabVIEW tries read from the serial connection the string the arduino is sending back. I can't say for certain if your intended use needs it for sure or not. Try it, what could it hurt? The communications may work perfectly or the arduino could not respond to the read request. If it doesn't respond, add the delay.

 

If you run the Read and Write in parallel (2 seperate loops) you run the risk of "starving" the communications line. If the program indexes up a bunch of reads and you want to push a write in there it may come too late. If you want the correction to happen as soon as a value is read then you need to have the write follow the read. For your program I would suggest serial. Using parallel is possible, you just have to take in more considerations but it would achieve the same result.

Kyle Hartley
Senior Embedded Software Engineer

Message 33 of 36
(1,002 Views)

Kyle,

 

I tried to set up a basic serial write and read vi to test on the arduino and have incurred a problem that is impeding my ability to move the read portion into my joystick control. For some reason the basic serial read is not displaying the strings that the Arduino sends to it 95% of the time. This is particularly strange because a small portion of the time it will in fact display what it is supposed to and then become incapable of repeating no matter what I try. What's even stranger is that the basic write and read 2 and advanced write and read work just fine without issue every single time.

 

My Arduino code is very simple which is why I am addressing the LabVIEW side of things in the forum. The Arduino simply initializes a baud rate of 9600 and sends a single character of a string during each loop iterations. In the .vi's that this worked in, the serial read displays as many letters of the string, I just wrote out the alphabet, as there are bits specified to read. For example, it will print abcde if the user specifies reading 5 bits and then fghij if you run it in a loop.

 

At least my delay question is conclusivel answered as I was able to write to the same port while reading from it with no issue whatsoever. I am, however, curious about what on earth could be the causing the erratic behavior of the basic serial write and read. Any suggestions?

 

Thanks again,

Yusif

0 Kudos
Message 34 of 36
(987 Views)

Yusif,

Perhaps the issue is related to LV not reading the data fast enough. Try to reducing the speed of data coming out of the arduino or consider using a queue to prevent data from being over-written before it is read. Also, if the basic read and write work, why not use them instead?

Ben D.
Applications Engineer
National Instruments
Message 35 of 36
(981 Views)

Ben,

 

I took your advice and after spending half of the weekend making adjustments I have the VI working how I wanted it to. Some organizational adjustments need to be made and another team mate will probably need to create a sub-VI for reading and storing the serial read data but it seems we have a solid foundation. It's been a difficult couple of months trying to get this thing working considering I had practicaly no LabVIEW experience prior to this but with the help of the forums I managed to transform a blank page into something functional.

 

Thank you all so much for all your help, please contact me if you would like to see the finished product for your future projects.

 

Yusif Nurizade

0 Kudos
Message 36 of 36
(971 Views)