11-29-2025 04:18 AM
Hello, I am currently working on a project with an analog sensor and a stepper motor. I want the sensor to collect data when the motor turns to angles of specific increments.
Currently I have labview tell the arduino what angle increment the stepper should move in through the serial monitor. (Ex. I send "5", and the motor will move to 5, 10, 15, 20... degrees). When it reaches that angle, I have the arduino print on the serial monitor what angle it is currently at which Labview should read. I also have arduino write "M" on the serial monitor if the motor is still moving so that labview knows to not take any data from the sensor. I currently don't have the sensor on me so I have a random number generator instead.
Labview is able to communicate with the arduino and tell it what increment the stepper motor should move in. However it doesn't seem to be reading what the arduino writes back at all. I'm sure this is a trivial problem but I am still having a hard time with this even after reading the other threads. Any help would be graciously appreciated!
Solved! Go to Solution.
11-29-2025 01:10 PM
DO NOT USE THE BYTES AT PORT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (still not enough emphasis)
You are dealing with an ASCII protocol, so let the VISA Read do all of the hard work for you. Just tell the VISA Read to read more bytes than you ever expect in a message and it will read the entire line for you. After that, it is a matter of you making a proper message on the Arduino side and properly parsing it on the LabVIEW side. I would recommend taking all of your data from a single loop in the Arduino and formatting that into a single line, maybe using a comma as a delimiter.
11-29-2025 01:26 PM
Thank you so much for replying!
I tried testing Labview with the bytes set to 100 and changed the arduino end so that it only sends a line on the serial monitor when the motor reaches the new angle. The buffer still doesn't read anything and doesn't seem to be recieving any bytes at all when I checked with the probe. Is there something with reading the serial monitor in a while loop after writing that Labview doesn't like?
11-29-2025 04:35 PM
I don't really know how I solved it but everything works now!
- I moved the code in the void loop to setup
- I changed the byte to 100
The code definetly could be cleaner but if it works it works.
11-30-2025 12:40 PM - edited 11-30-2025 12:49 PM
@crossrulz ha scritto:
DO NOT USE THE BYTES AT PORT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (still not enough emphasis)
Let me pick-up on this.
I banged my head on this long ago and, back then, not even NI support gave me good answers.
Granted that it is of course a better idea to let VISA vi's do the 'hard work', and only for the sake of my understanding, why does "bytes at serial port' work so badly? I could never understand what conditions make it give out inaccurate results. It is simply erratic.
Given that VISA vi's work, there must be an internal "low level" mechanism that actually works. Why can't we, "common mortals", use it?
Or is it just a brute force "keep reading each byte from UART as fast as possible and process as soon as terminator is received, 'N' bytes are received or timeout reached"?