Hands-On Lab Analog Sensors, Signal and Data Output: 1 Aims of This Exercise
Hands-On Lab Analog Sensors, Signal and Data Output: 1 Aims of This Exercise
Hands-On Lab
Analog Sensors, Signal and Data Output
1 Aims of this exercise
• To improve your understanding of how to read and write analog signals using DAQ hardware and LabVIEW
software
• To improve your knowledge of sensors and the basic concept of calibration
• To develop practical data acquisition skills using a myRIO and a breadboard
4 Background
A basic but fundamental part of experimentation is the ability to store signals and save them to disk. This can be
done in two ways: by using either a digital or analog signal. In this lab we will use analog devices and the analog-
to-digital converter built into the myRIO device and export those values.
This task is highly representative of the tasks you will be asked to do in your group project later in the semester
so understanding this lab is very important. This task is also highly representative of challenges faced in industrial
experimentation, active control and feedback, robotics, process control and automated manufacturing (plus many
more).
1
MACE6X021 – Experimental Methods
a) b)
Figure 5.1 – a) NI myRIO Expansion Port (MXP) Protoboard Accessory and b) myRIO ports
Just for clarification, when using breadboards, they are linked vertically as shown in Figure 5.2.
1. Plug the 3-pin potentiometer into the breadboard, as illustrated in Figure 5.3
2. Connect the A-pin of the potentiometer to the AI-GND pin on the breadboard with a connector wire
3. Connect the B-pin of the potentiometer to the 5V using the breadboard with a connector wire
4. Connect the C-pin pf the potentiometer to AI-0 using the breadboard with a connector wire.
Your circuit should look like the schematic shown below in Figure 5.4.
2
MACE6X021 – Experimental Methods
Once this has been completed, ask a demonstrator to inspect your circuit.
5.2 Software
Once the hardware set-up has been completed, plug the myRIO into the PC via the USB cable and open LabVIEW
2019 and complete the following:
1. Ensure that the myRIO environment is selected before you open LabVIEW
4. Use the default personality for the myRIO. Now open the Main.vi file from the project view (Figure 5.5).
Open up the Block Diagram page and you will find a basic LabVIEW. In order to get started, delete the contents
of the main loop. Your VI should look as shown in Figure 5.6. Now follow the instructions below.
1. Press Ctrl+H to open context help. Press Ctrl+T to tile the Block Diagram and Front Panel across the screen
3
MACE6X021 – Experimental Methods
2. Right click on the Block Diagram and click the pin icon in the top left of the functions palette to keep it
open throughout this exercise
3. Create a stop button by right clicking the input of the condition terminal on the block diagram and select
create control. This controls when the loop stops. If the condition terminal receives a value of true the
loop will stop executing.
4. Insert a basic Wait function in the timing loop with a 5ms delay to control the execution speed. Create a
numeric constant with the value of 5 and wire it to the wait function.
5. Right-click on the Block Diagram and insert an Analog input (1 sample) from the myRIO menu on the
functions palette into the loop
6. Configure the high-level VI by double left clicking on it. Configure it to record the voltage from channel
AI0 and name the channel Potentiometer
7. Wire the error cluster through the VI to the output of the loop. It is important to make sure the error
cluster is wired because it helps debugging and also ensures the order of execution is easily controllable
8. On the front panel create a Waveform Chart. On the Block Diagram wire it to the analog input signal
9. Ensure that auto scale are enabled for both the x and y axes on the Waveform Chart by right clicking each
axis and ensuring AutoScale X/Y is ticked
11. Run the VI by clicking the arrow in the top left corner
12. Turn the potentiometer and see the output on the screen
As you turn the potentiometer you should see the voltage reading on the chart change. Ask a demonstrator for
assistance if you need it.
Figure 5.7 – Waveform chart showing potentiometer output vs. sample number
Figure 5.8 – Waveform chart showing angle in degrees vs. sample number
1. Insert a FAT32 format USB pen drive into the port on the myRIO
2. On the Block Diagram, wire the angular output value to the edge of the loop
3. Right-click on the loop tunnel and select indexing as the tunnel mode
5
MACE6X021 – Experimental Methods
4. On the Block Diagram, outside the loop, place a Write Delimited Spreadsheet VI from the File I/O menu
6. Wire the error cluster through this VI using the error in and error out terminals
8. Right-click on “delimiter” terminal on the Write Delimited Spreadsheet VI and select create constant, then
input a comma ,
11. On the Front Panel, in the control for the file path1, type “/u/data.csv”
12. Run the VI and turn the potentiometer a few times before pressing stop
13. Save the VI you will need it for the next part of the lab
The data should now be saved in an easily readable format on the pen drive and can be read into other software
such as Excel or Matlab. In order to read the data off the USB drive you must plug it into the PC directly.
1
The address of a pen drive to a myRIO is /u/ . This should always be used when connecting to external memory
6
MACE6X021 – Experimental Methods
6 Extra challenge 1
Can you create a time array using the Wait value and the loop counter ( ) and then save this in another column
in the spreadsheet output? You will need to build a two-dimensional array from the two one-dimensional ones
using the Build Array function from the Array palette
7 Extra challenge 2
The acquisition rate used during this lab was set by using a wait function; however, there are more accurate ways
to set acquisition rate, such as using a timed loop. A timed loop will execute at the specified rate (or as fast as it
can) and operates in the same manner as a while loop. The timed loop has the added advantage that it can tell
you when the loop has not executed on time and this can be displayed on the Front Panel using a Boolean
indicator. Give it a try and see what the fastest consistent loop you can set is by monitoring the finished late signal,
as shown in Figure 7.1.
7
MACE6X021 – Experimental Methods
8 Conclusion
Congratulations! You have now used DAQ hardware to save an analog signal to disk. Make sure you save the
project that you have completed here as they could be very useful in future projects…
Tell the demonstrators if you have completed the project here as there are extension activities to do if you have
the time.
9 Notes
_______________________________________________________________________________________
___________________________________________________________________________________________
___________________________________________________________________________________________
___________________________________________________________________________________________
___________________________________________________________________________________________
___________________________________________________________________________________________
___________________________________________________________________________________________
________________________________________________________________________________________
8
MACE6X021 – Experimental Methods
________________________________________________________________________________________
___________________________________________________________________________________________
________________________________________________________________________________________
________________________________________________________________________________________
________________________________________________________________________________________