Programming with LabVIEW

Online LabVIEW Evaluation: Exercise 1

Tutorial


Online LabVIEW Evaluation: Exercise 1

Goal

This exercise will help you write your first LabVIEW program, which is called a virtual instrument (VI).


Objective

Create a VI that converts temperature values from Fahrenheit to Celsius.

Before You Begin

We recommend you use the following equipment to complete the exercise:

  • A mouse for easy maneuverability
  • Two monitors, one to show the exercise steps and another for LabVIEW

Excercise Instructions

  1. Create a new VI by selecting File > New VI

    This step creates a new VI, which is made of two windows.  The Front Panel serves as the user interface, and the Block Diagram contains the program code in a graphical form.

  2. Building the User Interface
    • Place a Numeric control by right-clicking the Front Panel, navigating to the Numeric palette, and selecting Vertical Pointer Slide.
    • The controls Palette that appears when you right-click includes all the necessary elements to build your user interface. Take some time to explore the different controls and indicators available. 


    • Place the control on the Front Panel
    •  Tip: You can resize controls and indicators; when your curser is on an object, resizing handles appear at the points from which you can resize. Use these handles to resize the control to your liking. 


    • Double click the label "Slide", and type the new label, Temperature (F).

    • Right-click the Slide control and select Properties. In the Scale tab, change the scale range maximum to 200 and click OK.

      Take some time to explore the different properties you can modify.


    • Right-click the Slide control and select Visible Items >> Digital Display.
    • Add an indicator, where the user can see the results or outputs of the program displayed. In this exercise, it will be a Numeric Indicator where the converted temperature in Celsius will be displayed.
    • Right click the front panel, navigate to Numeric and select Tank.
    • Once placed on the Front Panel, right-click and select Change to Indicator,.Then, select Properties. In the Scale tab, change the scale range maximum to 100 and click OK.


    • Place the thermometer on the front panel and resize it to your liking.
    • Change the label to "Temperature (C)."
    • Right-click the temperature indicator and select Visible Items >> Digital Display
  3. Creating the Block Diagram
  4. On the block diagram, you now have two terminals corresponding to the control and indicator we placed in the previous step. We'd like to pass the input from the Temperature (F) control through a quick calculation, converting it to a Celsius, and finally to the Temperature (C) indicator.


    The conversion equation is T(C)=[T(F)-32*[5/9], which means we need a subtract, a multiply and a divide function in our program.


    • Right click the block diagram and navigate to Programming >> Numeric >> Subtract.

      When you right-click the block diagram, the Functions palette appears. Here you will find all the necessary elements and functions to create the logic of your program. Take some time to explore the different functions available.

    • Place the subtract function on the block diagram, in a space between the control and the indicator.
    • Right click the block diagram and navigate to Programming >> Numeric and add the Multiply function.
    • Right click the block diagram and navigate to Programming >> Numeric and add the Divide function.



  5. Wire the code to create data flow
  6. To create the logic, next we need to add our constants and wire the functions together.

    • Hover your cursor over the Temperature (F) control. When the node on the right appears, click it then move your cursor to the top input node on your Subtract function and click it to connect a wire between the control and the function.

    • When you hover your cursor on each function, input and output nodes appear. For example, the Subtract function will take in 2 inputs and output the difference between them.

    • On the lower input node of the Subtract function, right-click and select Create Constant. Double click the constant and type 32.
    • Similarly for the Divide function, create a constant for each of the input nodes, changing the top one to 5 and the bottom one to 9.
    • Connect a wire from the output of Subtract to the top input of Multiply.
    • Connect a wire from the output of Divide to the bottom input of Multiply.
    • Connect a wire from the output of Multiply to the Temperature (C) Indicator.

      We now have a functional program that can take the input temperature you select, convert it to Celsius, and display it on the Temperature (C) indicator. Let's test it out!

    • Move the Temperature (F) slider to 75 (or type out 75 in the digital display), then select the Run button. The program will run, and the Temperature (C) thermometer should now read 23.8889.

  7. Writing the code: Using Loops
  8. As a final step, we'd like to allow the user to continuously change the input and see the converted temperature until they decide to end the program. To do this, we will use a While loop.


    • Right-click on the Block Diagram>>Programming>>Structures>>While Loop.
    • As you place it on the Block Diagram, drag the loop to encapsulate the existing code.
    • On the bottom right corner of the loop, you'll find a Loop Condition terminal, which determines when the loop stops running. In this exercise, we want to give the user control.

    • Right-click on the Block Diagram > Boolean > Stop Button.
    • This step creates a Stop button on the front panel.

      Tip: On the front panel, move and resize the Stop button for better accessibility and a friendlier user interface



Your program is now ready to run.

  • Click the Run button on Front Panel toolbar.
  • Move the Slide control on your Temperature (F) control, and you can see the corresponding temperature in Celsius displayed on the Temperature (C) Indicator
  • After you are done, click the Stop button to end the program.

Where to Go Next

Resources

To continue learning about using LabVIEW, NI provides you with a number of options.

Find more content about the Online LabVIEW Evaluation

Back to Quickstart