LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial communication with Arduino

Solved!
Go to solution

I am using Arduino to detect the temperature change measured by an NTC and want to communicate it to LabVIEW.

 

The problem is that the temperature fluctuates abruptly from 25°C (the one I measure) to 0°C ... I don't know why.

This is my first time writing a program on LabVIEW, so it is definitely not optimized and will be a disaster. Therefore I am providing the code and asking what I am doing wrong and what I need to improve.

 

I cannot attach the Arduino .ino file, but I just tell you that (set the baud rate equal on Arduino and LabVIEW) I am using this line of code to transmit the temperature "Tread" in float: Serial.println(Tread);

 

Thanks to everyone!

Download All
0 Kudos
Message 1 of 8
(2,039 Views)
Solution
Accepted by kalemaxon89

Do not use "Bytes to read", change your code to this below:

GRCK5000_0-1684937597817.png

 

 

0 Kudos
Message 2 of 8
(2,015 Views)

Thank you! Now it seems to be working👍

 

Why 1023?

Why is the "Bytes to read" block incorrect?

 

I also take the opportunity to ask you how should I choose the value to put in the "Wait" block ... I set 500ms but just to test, I don't know how much goes there. Keep in mind that I want to use a Baud Rate of 19200

(if this information is useful to you).

 

 

0 Kudos
Message 3 of 8
(2,007 Views)

Watch this video https://www.youtube.com/watch?v=J8zw0sS6i1c&t=1s            by crossrulz

it tells you  why "Bytes to read" is incorrect.

But I chose 1023 because it is the maximum number you can represent with 10 binary bits. 

I think it’s always a good idea to have the wait there to prevent the processor (CPU) from working too hard. Bear in mind the processor needs to complete tasks such as updating and responding to the user interface. So putting a delay, it's always a good thing.

You don’t have too much in your loop, so I think 500 ms should be fine at baud rate of 19200.

I am so glad the code is working now. Feel free to ask for more help, we are here to help.

0 Kudos
Message 4 of 8
(1,978 Views)

I think in this case, leaving out the wait is better. The loop has only one function, to wait for data from the serial port. If your arduino code is trying to send data faster than 2/second having the wait is going to cause you to get stale data and start filling up the serial port's buffer with data. Let the rate that data is coming in determine the loop rate.

0 Kudos
Message 5 of 8
(1,914 Views)

Hi Kalemax,

 

I would listen to what Steven said. Leave out that wait. 

0 Kudos
Message 6 of 8
(1,909 Views)

Also note that the VISA Read is basically a sleep for the loop while waiting for data to come in.  Your processor will handle other stuff while waiting for the data.

 

So, yes, remove the wait.  Just like with a Producer/Consumer, let the incoming data determine the loop rate of the consumer (the VISA Read loop being the consumer in this case).

 

One final note:  If the device is not constantly sending data, I will use the Bytes At Port to see if a message has at least started.  If there is no data, I have a wait.  If there is data, do the read.


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 7 of 8
(1,832 Views)

Thank you for the response!

 

I take this opportunity to ask you some advice on the project I did.

I share with you the Labview program that reads from Arduino the temperature detected by an NTC and writes to Arduino the duty cycle (produced by a PID conrtrol I made in labview) that will be transmitted on a digitalPin of Arduino on which there is a mosfet (pilot its gate with PWM signal).

 

I know that the labview file is a disaster ... it's the first time I use it.

However, I would kindly ask you to list what the problems are in using such a code.

 

Thank you all for your time and support

0 Kudos
Message 8 of 8
(1,757 Views)