LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I tried to mimic code with Daqmx using arduing VIs as shown below. Can you give me a feedback?

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?

 

GRCK5000_1-1683560769238.png

 

0 Kudos
Message 1 of 8
(1,165 Views)
  • Why do you think you need to configure the serial port, read one points, then kill it, every 10ms?!?!?! Only the reading should be inside the loop, right? (same glaring problem with both loops!)
  • It is incorrect to create a 2D array from a 1D array and a scalar turned ito a 1D array of one point, unless you want the second row to be padded with 999 zeroes. do you?
  • Going 2D array -> dynamic data -> waveform data is just plain silly because no timing information is there.
  • It is not clear at all what that FOR loop is supposed to do.

Can you explain what you want to do, not how you want to do it?

Message 2 of 8
(1,143 Views)

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.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 3 of 8
(1,130 Views)

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. 

GRCK5000_0-1683567951527.png

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.

 

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

@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...).

 

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

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.

GRCK5000_0-1683581677172.png

Front panel

GRCK5000_1-1683581727283.png

 

 

 

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

@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.

0 Kudos
Message 7 of 8
(1,038 Views)

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.

Message 8 of 8
(1,034 Views)