06-23-2015 02:11 AM
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!
06-23-2015 03:29 AM
06-23-2015 06:47 AM
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.
06-23-2015 08:42 AM
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?
06-23-2015 09:13 AM
06-24-2015 01:40 AM - edited 06-24-2015 01:41 AM
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.
06-24-2015 01:57 AM
06-24-2015 02:41 AM
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.