Display Integer Using a 7-Segment LED, NI myDAQ, and LabVIEW
This document explains using a low-cost 7-Segment LED to output a numeric integer with your National Instruments myDAQ in LabVIEW. The digital output will be generated on the myDAQ's digital port (8 digital lines) using the DAQ Assistant that is installed into LabVIEW with the NI DAQmx driver.
Table of Contents
- What You Need:
- Wiring Instructions:
- LabVIEW User Interface:
- Coding Strategy:
- How It Works:
- Tips and Tricks
- Related Links
Use a 7-Segment LED (Light Emitting Diode) to output a numeric integer using a digital port output on your myDAQ device.
A 7-Segment LED is an extenuation of a basic LED that requires 8 digital lines (1 digital port) to control, 7 segments and 1 decimal point. 7-Segment LEDs are used in microwaves, alarm clocks, and many other numeric indicating applications. It is important to know that a 7-Segment LED behaves exactly the same as a basic LED, which is a diode that only allows current to flow in one direction and we will need to limit the current by connecting a resistor in series.
Figure 1: 7-Segment LED and 330Ω Resistor
What You Need:
- NI myDAQ
- 7-Segment LED
- 330Ω 1/6th Watt Resistor
The LED is wired in series with a 330Ω resistor. Assuming the LED has negligible resistance, the total resistance of the circuit is 330Ω. According to Ohm’s Law, the current drive with a 5VDC power supply from the digital line would result in 5V÷330Ω= 15.15mA. As stated in the specification sheet for the LED that is referenced at the bottom of the document, the Led can handle a current up to 20mA, and is recommended to be used with 16 to 18mA; so at 15.15mA we will be safe. The LED requires a positive input on the longer lead side and a negative input on the shorter side, as seen in Figure 1 above. We will supply power to this circuit using Digital Line 0 of the myDAQ, and ground the circuit to Digital Ground of the myDAQ.
Figure 2: Wiring Diagram
LabVIEW User Interface:
The user interface we created has the Boolean controls on top of the 7-Segment LED image for ease of use. The Boolean controls will light-up when pressed, and this will indicate a 5V signal is being applied across the LED and resistor.
Figure 3: LabVIEW Front Panel
In LabVIEW we need to create a front panel Boolean array control to output a 5V digital signal on Port0 to our basic 5mm LED. This Boolean array is input into our DAQ Assistant which will output the corresponding values to the NI myDAQ digital port. After configuring our DAQ Assistant to output Inverse Boolean logic, a True corresponds to a 5V signal, and a False corresponds to a 0V signal. Therefore, a True will turn on the LED segment.
Figure 4: Coding Block Diagram
The LabVIEW diagram looks very similar to the coding block diagram, except the 7- Segment LED is not included.
Figure 5: LabVIEW 2009 Block Diagram
(The attached LabVIEW code snippet can be dragged-and-dropped to a LabVIEW block diagram, use attached PNG file. After locating the PNG file, just drag the file icon onto a blank block diagram, as if you were dragging the file onto your desktop.)
How It Works:
Inside the while loop on the left are 8 Boolean controls, each used to send a True or False to the corresponding LED segment. Each control is then input into the build array function. This is because the DAQ Assistant is setup to output to a Digital port, which consists of 8 Lines; each Boolean control will output to a Line of the Port. Notice that the controls are not in alphabetic order form top to bottom; this is because the controls are arranged on the block diagram exactly as they are in the Wring Diagram above, Figure 2. The Build Array VI can be thought of as the Digital Port0 on the NI myDAQ, consisting of 8 digital Line outputs.
On the right is the DAQ Assistant. It’s configured to output a single value to each Line (0 through 7) on the myDAQ Digital Port0 each time it executes in the form of a Port Array. Before sending the data to the DAQ Assistant, we first have to convert the Boolean Array to a Number, and then build the number into a 1 element array. This is because the DAQ Assistant is configured to receive this data type. All of the code inside the While Loop continues to run until the Stop button is pressed on the front panel. The Wait VI (bottom center) delays execution of the while loop to every 100ms. Therefore the output rate is 10 samples per second, or 10 Hz.
In this VI the DAQ Assistant is configured for on-demand output on the digital channel. The following steps walk through the configuration of the DAQ Assistant from scratch:
- Be sure your myDAQ is plugged in
- Press Ctrl-Space to bring up the Quick Drop Window (takes a full minute to load on the first use)
- Search for DAQ Assistant and double click on it when it appears in the list
- Drop it on the Block diagram (white window)
- When the Create a New Express Task configuration pane appears, select
- Generate Signals
- Digital Output
- Line Output
- Dev 1 (NI myDAQ) *Note: If you have other NI hardware installed, the myDAQ will not be Dev1.
- Leave Timing Settings to
- 1 Sample (On Demand)
- Select Invert Line (This will send a 0V on True and a 5V signal on False, as aforementioned)
- Press OK
Figure 6: DAQ Assistance Resistance Configuration
*Note that sample time is set by the Wait VI and is set to sample 10 times per second (every 100ms) in this VI
Tips and Tricks
- Use this document in conjunction with the Measure Temperature using 10kΩ Thermistor, NI myDAQ, and LabVIEW document to display a number that corresponds to a temperature.
- Expand your application by integrating a case structure that will output the proper Boolean array to the DAQ Assistant which will output the integer on the 7-segment LED. You can add a case to the case structure for each number by right clicking on the case structure wall and adding a case, and then add a numeric control to select the case.
Reader Comments | Submit a comment »