05-24-2023 08:27 AM
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!
Solved! Go to Solution.
05-24-2023 09:13 AM
Do not use "Bytes to read", change your code to this below:
05-24-2023 09:31 AM
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).
05-24-2023 10:33 AM - edited 05-24-2023 10:34 AM
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.
05-24-2023 04:58 PM
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.
05-24-2023 05:01 PM
Hi Kalemax,
I would listen to what Steven said. Leave out that wait.
05-25-2023 09:04 AM
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.
05-27-2023 07:10 AM - edited 05-27-2023 07:33 AM
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