LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial communication to arduino not happening

Hi,

I am a complete beginner to labview. I completed all the basic tutorials including math operations and wanted to try something a bit more sophisticated. I want to connect my arduino uno to labview via serial communication and print the data in labview GUI that arduino is sending. For that I wrote super simple arduino uno code and built a labview instrument (that sadly is not working)

void setup() {
  // Initialize serial communication at 9600 baud rate with 8 data bits and no parity
  Serial.begin(9600, SERIAL_8N1);
}

void loop() {
  static int number = 1; // Starting number
  
  // Send the current number over serial
  Serial.println(number);
  
  // Increment the number
  number++;
  
  // If the number reaches 360, reset it to 1
  if (number > 360) {
    number = 1;
  }
  
  // Delay for 1 second
  delay(1000);
}

 I have checked all the COM ports and baud rate, everything seems to match, but when I run my instrument, I have no data depicted in the buffer. It may seem like silly mistake, but please excuse and help the absolute beginner I am. Thank you in advance.
 

Download All
0 Kudos
Message 1 of 8
(315 Views)

I guess for starters, you're only reading 1 byte and your numbers will only be 1 byte for the first 10 digits (assuming start at 0). 

 

Have you probed your error cluster while it's running?

 

Do you see in your Arduino IDE data actually being posted to help confirm your code is running?

 

Are you 100% confident COM4 is the Serial Port representative or the Arduino?

 

I also believe you do want your termination character enabled.  Not sure I remember entirely what comes out of Arduino, but I believe it terminates (especially println).

0 Kudos
Message 2 of 8
(306 Views)

VISA is "different".  Tim Robinson has a video here  describing "How To" use VISA with LabVIEW.  The basic idea is that you assume (!!) that the sending instrument (Arduino) is sending "text" as strings terminated by <CR><LF>, and that the strings are fairly short (say 5-50 characters).  So you configure your VISA with the defaults, which means you make "Use Termination Character" to True, not False.  When you are ready to read, you ask VISA to "Read 1000 characters" (personally, I always ask it to read 1024 characters ...).  If the device isn't sending, the Read will Time Out, but if it is behaving, you'll get an ASCII (text) string that has whatever the Arduino is trying to send to you (perhaps a number, so you'll get the characters "143.5<CR><LF>".  Because you asked for 1000 characters but specified "Use Termination Character", you'[l bet only 5, "143.5" as a String.  If you print out the string, you'll see ... "143.5".

 

"But", you say, "I want a number!".  OK, use the LabVIEW "Scan from String" function and it will turn it into the number 143.5.

 

Now go hear Tim explain it better than I can ...

 

Bob Schor

0 Kudos
Message 3 of 8
(280 Views)

Here is how I would clean up your code.

1. There is no need for the wait in this loop because the VISA Read will be waiting for the data to be coming in.  As long as the arduino is looping correctly, the VISA Read loop will match it.

2. Enable the Termination Character.  The PrintLn() function appends the termination character (I think just the line feed), which VISA should be configured to stop the read on.

3. Read more than 1 byte.  As previously stated, the VISA Read will stop when the termination character.  So attempt to read more bytes than your message will ever be.  I tend to use 50 or 100.  In my reuse library, it is set to 4096.

4. For these simple interfaces, I like to stop the loop when there is an error.  Additionally, you need a way to capture that error.  In this case, a simple error indicator will work.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Download All
0 Kudos
Message 4 of 8
(239 Views)

I want to thank all 3 of you. I examined the causes and convinced myself what was the error and what must have been the solution. Thank you once again.

0 Kudos
Message 5 of 8
(220 Views)

I was also wondering, would it be possible to create some kind of radar looking GUI to draw a radius at an angle corresponding to the number I received via serial? (Picture of what I am after is in the attachments.) Since I am complete beginner to labview, I also wanted to ask an advice how do you create something from zero when you dont have a clue on how to do it? 

I have already convinced myself that labview is very powerful software with huge capabilities, but it has such unbelievably steep learning curve at the same time. Despite the logic in loops etc. this is a ,,know where to click" software that does not bring any advantages if you dont know the exact location of a needed block in the instrument cluster (if you know that such block exists at all.) AI wont help you much also...

For now, I am sure that my application is relatively easy, but I am really interested in some GPIB instrument creation to make a GUI for an old analog oscilloscope in the future. So my question again is:

What is the easiest and fastest way to visualize the path to your instrument when you dont even know how to start?

Untitled.png

0 Kudos
Message 6 of 8
(143 Views)

@ViliusZalenas wrote:


What is the easiest and fastest way to visualize the path to your instrument when you dont even know how to start?


You (instead of AI) work for it.  I've been doing it for 10 years and I'm still learning about its capabilities.  Many of the questions you are likely to have will have already been asked and all you have to do is search the internet.  One of the best things you can learn is learn how to ask your question and better understand your problem.  If you can't properly voice your issue then that generally means you don't understand the problem nor do you really know what it is you're trying to do.

 

You can also look up on youtube for LabVIEW training courses.  You can also use the available training provided by NI.

 

https://www.ni.com/en-us/shop/product/labview-core-1-course.html

0 Kudos
Message 7 of 8
(119 Views)

there are several wasy to achieve the diagram you're asking. 

 

You can plot a compass plot (right click on front pannel, select graph -> compass plot. 

There you have to wire an array for the radius and the angle (theta). Wire the signal you read from serial (after converting string to double ) and it will plot for you. 

 

As for the GPIB oscilloscope, the best way to start is to visit this site Instrument Driver Network (IDNet) - NI

and search for the instrument you are trying to use, most likely somebody has already developed a driver for that. 

If not at least you can have an idea how to develop your own ( you nee to know the protocol and the commands you're sending/receiving from the instrument. 

 

 

0 Kudos
Message 8 of 8
(110 Views)