To download NI software, including the products shown below, visit ni.com/downloads.
You depend on measurements to make key decisions and discoveries. NI offers a wide range of data acquisition products, including the low-cost DAQ family for basic applications such as simple data logging, portable measurements, and academic lab experiments. Choose the right high-quality hardware based on the requirements for your application and budget.
Take advantage of free NI resources to help you get to your measurement faster. In this tutorial, modify one of the hundreds of measurement-specific examples included with your device to learn how to build a basic application that emits an audio frequency when you press a button. NI low-cost DAQ products feature a variety of devices ideal for this type of basic application. For this tutorial, we work with the NI USB-6003 because it features hardware-timed audio output, which prevents distortion in the audio frequency. However, you can apply this code to any NI DAQ device that has digital input and hardware-timed analog output capabilities.
These devices come with software support for ANSI C, Visual C++, C# .NET, Visual Basic .NET, NI LabVIEW, NI LabWindows™/CVI, and NI Measurement Studio as well as configuration software. We demonstrate the task using LabVIEW, but you can complete this same task in other application development environments or programming languages. To see tutorials for other programming languages such as ANSI C or C# .NET, select from the tutorials linked at the bottom of the page.
First, make sure you have installed the supporting NI-DAQmx driver software version. If you are using a USB DAQ device, a green or blue LED light should turn on when the device is recognized by your host PC. Open Measurement & Automation Explorer and confirm that the device appears under Devices and Interfaces. Select the Self-Test button and confirm that the device passes.
The push button should have two terminals. Connect one of the terminals to P2.0 and connect the second terminal to 5 V.
This tutorial uses a speaker plugged into a two conductor (mono) phone jack. Two wires were soldered to the two terminals and one connected to ground, another to AO0, according to the diagram on the phone jack. Follow the diagram on your phone jack to connect the terminals to the analog output channel and ground.
For our application, we want to emit an audio frequency on command. To do this, we set up a program that creates and configures a physical digital input and analog output channel, waits for a digital trigger to occur, and then writes a frequency to the speaker. When we are done emitting the frequency, we want to be able to stop the program, clear the tasks, and release the resources. The basic flow of the program is in the following diagram.
Instead of building this entire application, we’re going to use one of the example programs included with your DAQ device. You can find the location of these example programs for your specific OS by visiting ni.com/info and typing in daqmxexp. We are going to modify a LabVIEW voltage output example called Voltage – Continuous Output.vi, which demonstrates how to continuously regenerate analog output data that is configured by the user. This example also incorporates digital triggering, so we do not have to add this to our code.
Copy the example program from its original location into your personal folder, so that modifications to your program do not overwrite the original example.
The first thing that you should notice in your program is the comments that designate sections of the code. In this example, there are five sections in the code: Channel Settings, Timing Settings, Trigger Settings, Waveform Settings, and Output. Documenting your code as you make changes is a best practice that allows your code to be read and understood.
Follow these steps to modify the example or open the finished program attached to this tutorial.
To run the program, select the run arrow. Compress the push button and hear an audio tone emitted from your speakers. Select Stop on the UI to stop the program.
The mark LabWindows is used under a license from Microsoft Corporation. Windows is a registered trademark of Microsoft Corporation in the United States and other countries.
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.