Getting Started with Data Acquisition

You want to get your first data with LabVIEW or an NI data acquisition (DAQ) device.  You have the device and want to know what to do next to get data.   You’ve come to the right place.

Where you're at:

Don't fret if you have a device that isn't supported by NI's DAQmx driver.  While that driver supports a large family of general-purpose devices, it doesn't support everything.  Check your device's manual to see what driver supports it.

Keep in mind this guide is for simple data collection as a first experience gathering data with these tools.  There are lots of potential use cases we use these tools for, from a large tester to an advanced control system, from a single thermocouple to thousands of channels.  We can't cover all that in one blog - but we will cover how to get started.

I'm going to cover an analog input voltage case, but this same flow applies for most kinds of measurements.

MAX Setup

First, connect your device to your computer (odds are it's a USB device).  Then launch NI Measurement and Automation Explorer, or MAX for short.  Once MAX is open, you'll want to

1 - Make sure your DAQ card is detected, then configure its alias

2 - Test out an acquisition in a test panel

There's lots going on here and we won't take the time to learn about acquisition modes now, so just try the “One Sample On Demand mode”, after selecting your channels.  This will acquire up to about 300 samples per second.  I say 300 very loosely, because there's a lot of potential factors influencing that number - but what I mean is it will update fast enough for you to see your signal change with your eyes and see variations on the time scale of you touching a voltage source.  It probably won't show you a 10 kHz sine wave cleanly - at least not yet.

If you see a signal that responds to stimulus, IT WORKS.  We can fine tune all sorts of parameters either here or in LabVIEW.  So why spend any more time here if we can spend that time in LabVIEW and be able to use that effort in whatever automated scenario we want?  Stop the task and close the test panel before moving on.  (Failure to release it will give us errors when we try the next step.)

LabVIEW Examples

Fire up LabVIEW.  Open up the Example Finder (Menu >> Help >> Find Examples) or

Let's start with these examples - but first one warning about examples.  They are files on disk and if you modify and save them, you're stuck with your modifications until you reinstall LabVIEW... or get creative and copy them from another computer.  So don't save yet!

Once you’ve opened the Example Finder, go to Hardware Input and Output >> DAQmx >> Analog Input



NI Example Finder's section of DAQmx examples

Let’s zero in on these Voltage examples to start.

Analog Input Voltage examples

1 - Start with “Voltage – SW Timed”

Software timing is where the computer uses its clock to time and initiate the process of acquiring every sample, every time.  It is quick and easy to get going and is supported on every device.  But, it lacks many of the capabilities of other acquisition types.  This should run like the Test Panel.  Feel free to fine tune things like acquisition range here, but don't spend too much on sample rate yet if you're aiming for higher speeds. 

Our first LabVIEW DAQ example

If you’re measuring a different type of signal such as current or thermocouple directly, take a peek at the related example.  You’ll notice with DAQmx that the configuration and the execution are separate – it may only take a small change in configuration to turn code from a voltage task into a current task.

2 - Next try “Voltage - Continuous” or “Voltage - Finite”

These will use hardware timing - or a clock onboard the DAQ device to time the acquisition.  With the hardware clock timing samples and putting them into buffers, the card can clock samples many times faster (assuming it has this capability - many devices have a limited number of timing engines). 

Select between the two based on your needs.  Finite Input fetches a known number of samples all at once then returns the data to you.  Continuous Input gathers samples continuously, returning them to you a chunk at a time while in a loop.  The neat thing about hardware timing is that the samples are acquired at a consistent rate – there isn’t an interruption each time you grab your chunk of data.

Now is when we can crank the sample rate up into the tens of thousands of samples per second.   Dial in any triggering or other tweaks you want to get your acquisition working well.  For continuous acquisitions, tune your chunk size.  About ten reads a second is a good starting rule of thumb.

Next steps

Don't use the DAQ Assistant

Originally made for folks getting started, the DAQ Assistant provides a menu interface similar to MAX’s test panel to help set up your task.  It is a super easy way to get started and plenty of guides point to it.  But the way it gives you the data isn't very compatible with most of the analysis or logging functions - at least not without finding the right converter functions and guessing their configuration correctly with little feedback. If you don’t know where it is, that’s ok – I won’t show you.  The DAQ Assistant uses a different paradigm with LabVIEW code that tends to lead newcomers in the wrong direction.

For a less frustrating experience overall, I recommend you keep working with the DAQ examples rather than getting too distracted with the DAQ Assistant.  In days since the DAQ Assistant was made, the DAQ examples have improved fantastically.  Working with them gives a much smoother transition to more advanced functionality as you want to expand your code's capabilities.    If you want an easy-to-use GUI to tweak your task rapidly and iterate quickly, go use the Test Panels in MAX.  Once you’ve figured out what works, come back to LabVIEW and start with code from the examples to make things work consistently every time.

Copy code from the examples

Copy code from the DAQ examples and begin adapting them in your own VI.   Check out the other examples that perform functions you would like - say logging to file or displaying a graph with analysis results on the screen.  Grab code from several to serve as a springboard your code.  Just remember to not save the examples!  On the other hand, save your code often!

Run it often and try it as you go. 

It's a lot easier to develop code incrementally and test it incrementally than it is to build a masterpiece only to find it takes tons of work or was built on an untested assumption about how something works.

Parting words

Looking for something other than voltage?  How about Thermocouple?  Bridge measurement?  Frequency domain data?  Is your use case different in another way?  That's fairly normal - such use cases vary widely across industries and applications.

Many folks that just picked up a low-cost data acquisition card without using one before often use it for a bit and find that it's not what they really need.  Check our common DAQ pitfalls before too long to make sure you're on the right path. 

Do you have an unanswered question?  Let us know.  We've successfully handled many difficult control and acquisition problems.  We can do design consulting to get you pointed in the right direction or offer turn-key test or automation systems.

Good luck and have fun!

Andrew Heim

Staff Systems Engineer

Although Andrew wrote his first programs in GW Basic in the early 90s, he took until LabVIEW 2009 to write his first VI.  It was atrocious, but he swears he has improved!

Before joining Endigit, Andrew worked at National Instruments for 7 years.  He most recently spent 5 years as a Systems Engineer, working with hardware-in-the-loop, DAQ, control, and real-time systems for some of NI’s largest customers.  Previous to that, he worked for NI as an Applications Engineer in the Engineering Leadership Program (ELP).  Before that, he was a LabVIEW Ambassador and an ELP intern.

Andrew has a bachelor’s in Mechanical Engineering from Brigham Young University.  He speaks fluent Portuguese, from spending two years doing missionary work in Brazil.

Andrew enjoys spending time with his wife and son, and spending time outdoor as long as the weather is warm.  He has pretty much always liked all things science and technology (and most things Star Wars), and has a recent interest in ham radio.

Add new comment