05-08-2023 10:54 AM - edited 05-08-2023 10:55 AM
Note: Arduino VIs does not have a VI that corresponds to "Daqmx timing" and "Daqmx start". I think Daqmx start does not matter really much with arduino. For Daqmx timing, I made it up by using the for loop code.
What do you think? Is it good or bad?
How would you modify arduino code so that it corresponds to the code for NI6009?
05-08-2023 11:33 AM - edited 05-08-2023 11:55 AM
Can you explain what you want to do, not how you want to do it?
05-08-2023 11:55 AM
I'm guessing you put the loops around BOTH code examples. While putting a loop around the code makes it work until you tell it not to - as intended - you need to watch what goes inside the loop and what stays outside. Generally speaking anything that opens or initializes instruments stays outside, as does anything that closes or resets instruments. The idea is "Open a reference once, use it until you're done, then close it," and "You only need to initialize once." Now this is generalized information, but it does work in the vast majority of cases.
05-08-2023 01:07 PM - edited 05-08-2023 01:12 PM
Thanks Mr. Altenback and @Billko, Based on the feedback received, this is how I modified the code.
@Mr. Altenback, I used for loop because I want to plot a 1000 sample all the time.
Does this look okay?
My goal is to have arduino do what NI 6009 can do so that when someone looks at the data collected of both microcontrollers, they wouldn't distinguish between arduino and NI 6009.
05-08-2023 03:41 PM
@GRCK5000 wrote:
Does this look okay?
If you want to look at the last 1000 samples, use a chart with a 1000 point chart history (Is that what you have? Sorry, can only look at the image). No shift registers and array gymnastics needed. Your array operations make no sense at all! You start with an empty array, add one element creating a 1D array with 1 element, then you delete 1000 elements, thus starting again with an empty array at the next iteration. Thinks about it!!!!
In the upper loop, all the timing configuration and setup also belongs before the loop. It never changes! Only the read operation belongs inside the loop.
You cannot directly compare the two traces because one contains 1000 samples per second and one 100 samples per second (Assuming the arduino communication can keep up...).
05-08-2023 04:35 PM - edited 05-08-2023 04:37 PM
Hi Mr. Altenbach
Thanks for the feedback.
I changed the x-axis scale of my waveform graph from 0 to 1000.
Also, one more thing on my arduino code, I am using "array subset" function. I know it looks similar to the "delete from array" function. sorry for the confusion. I should've attached a VI. I feel like I'm getting there to where I want to be. So this below is how I updated the code based on your feedback. I also attached a VI. I will test the arduino code and see if I get the same results as NI 6009.
Front panel
05-08-2023 06:14 PM
@GRCK5000 wrote:Also, one more thing on my arduino code, I am using "array subset" function.
Sorry, my browser zoom is a 80% and I don't currently have access to LabVIEW, so things don't look quite sharp.
It still makes no sense! Imagine you have 1000 points already and append one more point, then take the subset of size 1000. Now the element you just appended will immediately get deleted again!!!! Right? Right! At this point, the graph will show 1001 points and the last one will get replaced with every iteration while the first 1000 will never change again. As I said, Use a chart! No history code needed.
I don't understand why you think that changing the x-axis scale to 0...1000 would help solve your problem. Can you explain the reasoning behind it?
I am not sure why you think both loops should show the same result. Now the lower loop has absolutely no timing and the loop rate only depends on the unpredictable time it takes reading the data via serial.
05-08-2023 06:19 PM
If you really just want to view 1000 points, then use a Chart instead of a Graph and set it to display 1000 points. Then just feed it one sample at a time.
If you need to do something with the data (like I usually do) then a Chart will make it a little annoying to get that array of 1000 points, so doing what you're doing is fine with a small exception. When you use Array Subset, you take the first 1000 points out of the array. As you build the array, you're adding them to the end, so you'll always end up with the same 1000 points.
Either do an Array Length - 1000 as your Start index, or switch to Delete from Array and leave "Index" unwired. It'll automagically delete the last 1000 points and return the "deleted data" in "deleted portion". That will retain your final 1000 points instead of always giving you the same set of 1000 points.