LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial communication with the Arduino Nano

Hello

 

I am working on a project which uses an Arduino Nano to acquire data from a sensor and store it in memory. The data can then be requested by sending a trigger character (in my case the letter s in small). However, (frustratingly) I can't seem to get it working. I am first trying with a very simple hellow world example. The code is showin below, it works on the Arduinos serial mointor, a third party serial monitor and the VISA test panel in the Measurement and Automation Explorer. The place it isn't working is when I use a VI.

 

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);

}

void loop() {

 
  // put your main code here, to run repeatedly:

//if (Serial.available() > 0)
//{
 if(Serial.read()==115)
  Serial.println("Hello World!");
  //}
}

 

I have made the same configuration in VISA test panl.  I just can't seem to get my head across the problem. the VI I use is a variant of the basic Serial Read and Write example so I don't think I have made any mistakes. Can somebody please help?

 

PS: I find a similar problem when trying Matlab to do the same too!

 

 

 

0 Kudos
Message 1 of 8
(4,821 Views)
Set your string control to enable \ Codes Display and try appending \r or \n, enable termination character with the VISA Configure Serial Port, and get rid of the Bytes at Serial Port.
0 Kudos
Message 2 of 8
(4,797 Views)

Your arduino sends the Line Feed character as part of the Serial.println() function.  Therefore, you want to have your termination character in LabVIEW to be enabled.  And for your read, set the bytes to read to be larger than the largest message you would ever expect.  The VISA Read will stop when it finds the termination character (default is the Line Feed).  With that setup, you do not need the Bytes At Port property node.

 

I would also remove the case structures just to make sure all of your code is actually done.  If you have those Write and Read buttons set to FALSE, then they will not run and your program will not work properly.


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
0 Kudos
Message 3 of 8
(4,779 Views)

Hi

 

Thank you for your responses. I have tried your suggestions, however, I get a time out error.

 

To troubleshoot this further, I noticed that I can receive data continuously i.e. continuous transmission (without the trigger thing employed) in LabVIEW with no issue.

 

The problem comes when I try to send data from a VI in LabVIEW. When I send the trigger character, the LED on pin 13 on the Arduino Nano boards lights up (I haven't included this in the program). However when I send the trigger character from the three programs (Arduino Serial Monitor, third party serial monitor or VISA test panel) it does not light up and get the correct response back (in this case Hello World!).

 

I don't understand why should this happen. As far as my understanding goes, if you can perform a Write/Read in VISA test panel then a VI should not have issues talking to that port right?

0 Kudos
Message 4 of 8
(4,763 Views)
As long as you've programmed your VI to work like the VISA test panel, you should not have any issues. The default behaviour of a VI that you create is not the same, however. Did you actually change to \ Codes Display? If you did, what code are you appending with the write?
0 Kudos
Message 5 of 8
(4,759 Views)

Hello

 

I am not appending any code to the write operation.

 

I wanted to post an update. I have been able to get it to work (I still need to get the timing correct in that I sometimes have to press the trigger character send switch for a long duration, it is not like press it one and get the string back).

 

This is the VI. The Arduino restarts when I start a serial session with it so maybe that was causing the problem. What I have done is placed the write and read VI in a while loop and performed the configuration once only.

 

I have also tried it with the bytes at serial port by bringing the read VISA in to the case structure too. I think it is a bit buggy since I do not get responses to the trigger character all the time but will work on it and see if I can make it work smoothly.

 

Thanks for your help in this till now. I will post an update if I am able to get this working smoothly.

0 Kudos
Message 6 of 8
(4,737 Views)
Please append a termination character such as a carriage return or line feed to your write and enable termination character with the configure function. You haven't done what has been suggested for the steering control either so the term character is actually visible.
0 Kudos
Message 7 of 8
(4,729 Views)

Hello Dennis

 

Thank you. I have just tried the carriage return and the line feed as well as enable the termination character in VISA Configure Serial Port. It does give dependable reception with the carriage return. However, after a while I get the error attached in this post.

0 Kudos
Message 8 of 8
(4,720 Views)