You are on page 1of 57

1/30/2017 myRIO | Tufts Maker Network

AUTHOR
Jason Linker

myRIO
This handbook will get you up to speed on the basics of the National Instruments myRIO, including initial
setup, hardware, software, and configuration.

Setting up your myRIO


myRIO Hardware
The kit should include the following:

NI myRIO
myRIO power cord
myRIO USB cord
Various power adapters (for international use)
Mini System Port (MSP) Screw-Terminal
Connector

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 1/57
1/30/2017 myRIO | Tufts Maker Network

myRIO Expansion Port (MXP) wirewrap


This image shows the hardware attachment points on the
breakout myRIO.

On the myRIO there is:

WiFi on/off switch


Button
4 programable LEDS
3 status LEDs (power, status, and WiFi)
Audio in/out connectors
Mini System Port (MSP)
myRIO Expansion Port (MXP)

myRIO Software
First you need to create an account here (you must your your university account to get a student license).

To work with myRIO you will need the latest myRIO Software Bundle

The myRIO Toolkit is compatible with 32-bit WINDOWS LabVIEW only. Therefore, you must have 32-bit
Windows LabVIEW installed even if you use a 64-bit operating system.

The myRIO Software Bundle includes:

LabVIEW
LabVIEW RIO (Reconfigurable I/O)
LabVIEW RT (Real Time)
LabVIEW FPGA (Field Programmable Gate Array)
NI RIO Drivers
Various other optional LabVIEW and RIO drivers depending on intended use

If your computer does not have a built in .iso reader (a virtual CD drive) you can find one online. I used
Virtual Clonedrive and it worked fine.

National Instruments will ask you to activate your license. The evaluation copy will work for about 30
days, but student licenses are rather inexpensive and last for six months from the purchase date.

There will mostly likely be a lot of updates and patches for the software. If you run into updating issues,
some updates are dependent on others and need to be installed separately.

Plugging in the myRIO for the first time

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 2/57
1/30/2017 myRIO | Tufts Maker Network

0:00 / 7:37

The first time you plug in the myRIO via USB a USB Monitor Window will
appear. Launch the getting started wizard. The wizard will update and install
the newest software onto your myRIO. (The myRIO runs its own Linux based
LabVIEW and other software.) When it restarts the device and the menu
reappears click "do nothing" a few times. Eventually you will be able to test
the on-board LEDs button and accelerometer.

The USB monitor will appear


every time a myRIO is
plugged in.

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 3/57
1/30/2017 myRIO | Tufts Maker Network

Use this window to test the myRIO's onboard devices. There is an accelerometer, button, and 4 LEDs.

Configuring myRIO

0:00 / 6:39

Every time you plug in the myRIO the USB Monitor will appear. If you click on the "Configure NI myRIO"
tab you will be brought to a locally hosted site. (You may need to install Microsoft Silverlight and restart
your web browser). Here you can see and adjust a lot of the settings for your myRIO.

For now, all you need to know is the name and current IP address (most likely your USB port's IP
address) for your myRIO. For more details on configuring the myRIO see below.

The settings include:

System Configuration (Change the name of the myRIO, adjust the startup settings, and see what is
connected to the myRIO)
File Browser (Load/unload files from the myRIO)
https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 4/57
1/30/2017 myRIO | Tufts Maker Network

Security (Edit permissions on you myRIO)


Network Settings (View the MAC address and connect the myRIO to a wireless network. Once
connected to a wireless network the myRIO will be given an IP address. This may change periodically
and can also be viewed in the system configurations page. The myRIO can even create its own local
network. More information can be found in this video.
Software Management (See what software is currently installed and running on myRIO)
Date and Time Adjustment
Web Services (manage the myRIO's publishing to and reading from the web)
Web Servers (control HTTP and SSL connections)
Installed Configuration Tools (Adjust the configuration page)

Project 1: LED Level

The following guide will help you create an LED level using an accelerometer. The myRIO has an onboard
accelerometer, 4 built in LEDs, and a button which will be used in this guide to create a level along the Y-
axis. The LEDs should indicate how far from level the device is and in which direction a user should rotate
it to make it level. (Assume the X and Z axis are stable). How can you best use the 4 onboard LEDs to
accomplish this?

If you have never used LabVIEW please refer to the Introduction to LabVIEW section.

Your first VI from scratch and targeting your myRIO

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 5/57
1/30/2017 myRIO | Tufts Maker Network

0:00 / 3:13

1. In LabVIEW create a new blank project.

2. Right click on Project (the top line) -> New -> Targets and Devices -> New Target or device -> myRIO-
1900. Then choose your myRIO.

3. Right click on myRIO in the project -> properties -> add IP address (enter the current connection IP
address (USB or WiFi IP address))

4. Last, create a new VI on the real time processor (this will use the default FPGA identity). Right click on
RT Target -> New -> VI

In the bottom left corner of the VI it should say the project name and your myRIO. If it does not, right click
the bottom left and select your myRIO.

A video of this process (done with compact RIO) can be found in the sidebar.

Live Accelerometer Data


To determine whether the myRIO is level we will use the built in accelerometer. It has predetermined X,
Y, and Z axis. For more information on the accelerometer refer here. However, for the scope of this
project we can use an express VI from the standard myRIO toolkit.

To graph in real time with LabVIEW use a waveform chart.

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 6/57
1/30/2017 myRIO | Tufts Maker Network

0:00 / 3:17

(HINT to display multiple plots on one set of axis use a cluster. Each element inside the cluster will graph
as its own line.)

0:00 / 3:26

Activity: Live Accelerometer Data


partial-solution-accel.vi

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 7/57
1/30/2017 myRIO | Tufts Maker Network

Use the myRIO accelerometer express VI and a loop to plot live data (every 10
ms) for all 3 axis on a graph. Use a stop button as a control to exit the loop
and end the program. This is a plot of the
accelerometer data from the
To continually take in accelerometer data we need to repeat the same code myRIO.
over and over again. For this repetition use a while loop.

If you are struggling download partial-solution.vi and it will walk you though the gathering data process.

Solution
The while loop will run until the stop button is
pressed. The loop will wait 10ms between each
cycle. During each cycle the accelerometer will
read a value for each axis and then graph all three
on one plot.

Here you can see the accelerometer data flowing into the
waveform chart. Also the loop will exit when the stop
button is pressed.

This solution to graphing the data uses express VIs.

This solution uses myRIO channels. This is slightly more


complicated and hidden behind every express VI.

Controlling Onboard LEDs


https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 8/57
1/30/2017 myRIO | Tufts Maker Network

The myRIO has 4 built in LEDs and a button. For this project the express VIs will be sufficient but more
LED information is located here and more information on buttons is located here.

Activity: Controlling Onboard LEDs


Use the myRIO LED and button express VIs to turn
on LED0 when the button is pressed. Also include a
virtual LED indicator on the front panel.

More information on indicators below.

If the button is pressed the green LED will light up.

0:00 / 4:25

Solution
The output of the button is a boolean and so is the input of the LED control. The pacing of the loop will
determine how fast the response time is.

LED-on-off1.vi
LED-on-off2.vi

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 9/57
1/30/2017 myRIO | Tufts Maker Network

Here you can see the boolean values flowing through the VI. Notice how highlight execution slows down the
program. The loop will exit when the stop button reads true.

This solution uses express VIs. It is simple and straightforward.

This solution uses myRIO channels. This is slightly more complicated and hidden
behind every express VI.

Is the myRIO Level?


When the myRIO is stationary on a flat surface the values for each axis remain constant.

Activity: All Level?


Use the accelerometer values to light up an onboard LED and a virtual LED indicator when the myRIO is
level and stationary. The is-level-components.vi has all the needed blocks to complete this activity.

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 10/57
1/30/2017 myRIO | Tufts Maker Network

However, the VI is not assembled. Drag the blocks into their correct locations and wire them up to create
a runnable VI.

partial-solution-all-level.vi

(HINT case structures cannot take double


precision floating point numbers (orange wires in
LabVIEW), it will convert them to integers so
multiply the values by a constant before defining
cases. Also, don't forget about the default case!)

The partial-solution.vi is a partially assembled


solution to this activity.

The graph will plot live data. If the x, y, and z axis are all
"level" then the virtual LED will light up.

Solution
Each of the axis' data is fed into a case structure to determine if that axis is level. If all are level, the LED
will turn on. The axis' data is multiplied by a scalar constant because case structures will not take
decimals. The default cases are when the myRIO is level.

is-level1.vi
is-level2.vi

This shows LabVIEW deciding between case structures.

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 11/57
1/30/2017 myRIO | Tufts Maker Network

This solution uses express VIs and case structures.

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 12/57
1/30/2017 myRIO | Tufts Maker Network

This solution uses myRIO channels. The channels are hidden behind express VIs but the overall structure of the
solution is the same as solution 1.

Progressive Level
Now we should be able to put all of this together to accomplish the original goal.

Activity: Progressive Level


Use the 4 built in LEDs and the accelerometer to create a level along the Y-axis. The LEDs should indicate
how far from level the device is and in which direction a user should rotate it to make it level. (Assume
the X and Z axis are stable). How can you best use the 4 onboard LEDs to accomplish this?

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 13/57
1/30/2017 myRIO | Tufts Maker Network

The graph will plot live data. It will also mimic the LEDs on the myRIO to show how level the
device is.

Solution
These are two solutions to this activity. The first evaluates the axis data and enters the respective case
structure. Each case has a specific LED configuration.

progressive-level1.vi
progressive-level2.vi

This shows LabVIEW deciding between case structures.

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 14/57
1/30/2017 myRIO | Tufts Maker Network

This shows the different cases in the case structure. As the myRio is less level, more LEDs turn
on. This method is rather inefficient as it requires an express VI in each case.

This shows the different cases in the case structure. As the myRio is less level, more LEDs turn on. This solution uses
math to simplify the LED selection.

The second method has a case for positive and a case for negative. It then does division to determine
which lights should turn on.

Going further
Visit Dr. E's Challenges to upload your own level solutions, and see how others approached this project.

Here are some other cool project ideas that use the same basic principles as the level you've completed.

What happens when you bump the myRIO on a table? How can you display that?
Can you use the button to "zero" the level (turn whatever the current position is to "level")?
What angle is the myRIO at?

Project 2: Binary Counter


https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 15/57
1/30/2017 myRIO | Tufts Maker Network

This project details how to build a binary counter. When counting in binary there are only two values:
TRUE (1) and FALSE (0). Using a combination of these values and some clever logic we can create any
number. We will create a series of places, each holding its own value (bit). The first will represent 2^0
(convenient because computer science almost always starts counting at 0), the second will be 2^1, then
2^2, etc. This will give us the series 1 2 4 8 etc. This means that we could count up to 15 with a 4 bit
system if we add up all of the represented values.

Using this method we can create counters and clocks.

Make a countdown timer


In previous projects, you have used a wait to pace your loop. This means that the code within the loop
will run and then it will wait before looping again. That means if you include a 10ms wait, the loop is
actually running slightly slower. When we need precise timing in LabVIEW we use a single cycle timed
loop. This type of loop can be configured to run at a precise rate. If you set the dt of the timed loop to
10ms, the loop will run exactly every 10ms.

Activity: Make a countdown timer


Use a single cycle timed loop to create a countdown clock. Display the remaining time with a dial.
Include a user input for the time and the onboard button as a start button. When the timer reaches 0
seconds, have an LED on the myRIO and the front panel turn on.

In order to remember a value from the last loop iteration, LabVIEW uses shift registers. This will allow you
to keep track of values from the last loop iteration so you can keep track of the current time remaining.

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 16/57
1/30/2017 myRIO | Tufts Maker Network

0:00 / 3:00

If you need help, the partial-solution.vi file is missing some parts of the complete solution. It contains all
the needed structures, controls, and indicators; but none of the operations and logic.

counter-partial-solution.vi

This is the user interface for the count down timer. A dial displays the time remaining
and and LED displays if time has run out.

Solution

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 17/57
1/30/2017 myRIO | Tufts Maker Network

The user control can be trigger via either a switch statement or a case structure. The gauge is simply an
indicator and the loop subtracts one from the remaining time with every cycle. When the remaining time
is 0 an LED turns on and the program exits the loop.

countdown-timer1.vi
countdown-timer2.vi

This solution uses a switch statement instead of a case structure to determine whether or not to enter the
countdown loop. The button will only affect the program if it is not counting down.

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 18/57
1/30/2017 myRIO | Tufts Maker Network

This solution uses a case structure instead of a switch statement to determine whether or not to enter the
countdown loop. The false case contains a false constant to wire to the stop condition.

Make a binary counter


In the last example we counted down. In this activity we will count up using the binary addition method.

Activity: Make a binary counter


Count up from 0 and display the current count (in seconds) with virtual and onboard LEDs. Use the
binary counting system to represent the current time. (1 2 4 8). The lights should change at precisely 1
second. Include a virtual and onboard reset button to restart the counting at 0 and a stop button to
peacefully end your program (your program should always have one of these).

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 19/57
1/30/2017 myRIO | Tufts Maker Network

These LEDs mimic the the myRIO's LEDs.


They're labeled with their values to make
reading the counter easier. The maximum
value if 15 with 4 LEDs.

Use this if you need help creating the binary counter.

There are two easier ways to approach this problem and many other more complicated solutions.

The modulus operation (Quotient & Remainder operator in LabVIEW).


Integer division (this can be created using the regular divide function and a round to -infinity
function).
https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 20/57
1/30/2017 myRIO | Tufts Maker Network

Other more complicated solutions include but are not limited to bit-shifting and boolean operations.

Solution
Every second, the count increases. It checks if it is divisible by 8, if it is it subtracts 8; and so on with 4, 2,
and 1. This is possible to do with either integer division or a modulus operator.

The reseting can either be done with a loop (exit the count-up loop and restart) or a switch statement
(the current time switches to 0)

binary-counter-countup-clock1.vi
binary-counter-countup-clock2.vi

The quotient and remainder tool works like a modulus function. A series of cases structures determine which LEDs to
light up.

There is no integer division function in LabVIEW. You can create integer division by dividing and rounding down
[toward -infinity]. A series of cases structures determine which LEDs to light up.

Going Further
https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 21/57
1/30/2017 myRIO | Tufts Maker Network

Visit Dr. E's Challenges to upload your own binary counter solutions, and see how others approached this
project.

Here are some other cool project ideas that use the same basic principles as the binary counter.

Make an LED Binary clock using a breakout board and LEDs.


Display each counted number on a pixel display.

Project 3: Smart Night Light

In this project you will build a smart night light. The darker in the room it gets, the brighter the light will
get.

This will be the first project using the myRIO expansion ports.

For this project you will need:

Some type of expansion system (detailed below)


An LED (you can choose the color and size)
A resistor (Anything from 1ohm to 100kohm will suffice, I used a 10kohm resistor)
A photoresistor
Jumper wires

myRIO Expansion Options


There are 2 types of ports on the myRIO. The Mini System Port (MSP) is located on the right under the
LEDs. The myRIO Expansion Ports (MXP) are located on the left side. The MXP port can be used with
female header wires or certain expansion boards custom made for myRIO. The MSP port can take any
wire (male jumper wires work very well) or other specialized breakout boards. Digilent makes a lot of
specialized boards for myRIO.

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 22/57
1/30/2017 myRIO | Tufts Maker Network

[L to R] the Mini System Port and breadboard, the myRIO expansion port and wirewrap, and the digilent myProto
accessory board.

In the picture (L to R), there is an MSP port and protoboard (breadboard), an MXP wirewrap (comes with
myRIO), and a Digilent myProto accessory board. Any of these will work and you will find some of these
options better for certain projects than others.

The MXP options are great for specialized tasks with custom boards or applications needing a lot of pins,
you will mostly likely also need to pair it with a protoboard. The MSP myProto is great because it
converts all the screw connections into "breadboard pins" and has kill switches for 5V and +/-15V. Any
protoboard will also work with the MSP port, you just have screw in the wires yourself.

For convenience and ease of use I will use various Digilent boards throughout this tutorials.

Basic LED Controls


One of the most basic circuits you can make
contains an LED. In order to not blow out the LED
we can use a resistor to limit the amount of
current the LED gets.

The myRIO can send and receive two types of


signals, analog and digital. An analog input will
read in the voltage. An analog output will output a
periodic wave at a given maximum voltage and
frequency. A digital output will be either 0 (FALSE)
or 3V (TRUE). A digital read works similarly; if the
input is greater than 3V the input will read true,
otherwise it will read false. You can find the digital
and analog read/write commands in the myRIO This depicts the flow of electricity in the circuit for this
activity.

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 23/57
1/30/2017 myRIO | Tufts Maker Network

section of the toolkit on the block diagram. Be careful about which pins you select to read and write to.

Activity: LED on with 5V


The LED needs some type of power to turn on and
light up. Connect the long end of the LED (anode)
to +5V. Then connect the cathode of the LED (the
short end) to the resistor and that resistor to
ground (GND). It should light up. This 5V port will
always output 5V whenever the myRIO is on.

This will light up via a constant 5V signal.

Activity: LED on with Digital Signal


Write a VI that turns on the external LED when the
onboard button is pressed. Output TRUE to a
digital pin when the button is pressed and false
otherwise. Wire your LED-resistor circuit to that
pin and ground. Notice how the LED is not as
bright when powered with a digital signal?
(remember it is only 3V)

This is the schematic for the wiring of the digital solution.

Solution
The button outputs a boolean and the digital write takes a boolean so they can be simply wired together.

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 24/57
1/30/2017 myRIO | Tufts Maker Network

This will light up via an digital signal, but


remember it is either true [3V] or false [0V].

Activity: LED on with Analog Signal


Write a VI that turns on the external LED when the
onboard button is pressed. Send 5V to an analog
pin when the button is pressed and 0V when not
pressed.

Now use a front panel control to change the


voltage. Notice how the LED turns off before the
voltage decreases to 0? This is called a forward
bias. Also, keep in mind that the signal is actually a
wave. The LED is only actually on when the value
of the wave is above that bias number, which is
why it is still dimmer. This can cause problems in
more complicated circuits, but we will discuss that This is the schematic for the wiring of the analog solution.
soon.

Solution
The button outputs a boolean value but the analog write takes a double precision number. To convert
this, use a switch statement. When true...When false...

This will light up via an analog signal, but remember it is a


wave.

Dimming LEDs on the Real Time Processor


As you have seen from the basic LEDs section, you can change the brightness of an LED by changing the
current through it. With this method the only way to adjust the brightness would be to change the

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 25/57
1/30/2017 myRIO | Tufts Maker Network

resistor in the circuit, or use a potentiometer (variable resistor).

If you want to control the brightness precisely using the myRIO or a computer you will have to use a
technique called pulse width modulation (PWM). PWM is essentially a digital output. By oscillating
between true and false the output looks like a "square wave". By changing the percent of time high and
low you can create different brightnesses. This is called the duty cycle, and it generally will vary as a
decimal between 0 and 1 or as a percentage between 0 and 100. The higher the duty cycle the longer the
light is on in each given HIGH-LOW cycle. Be sure you use a high enough frequency so you don't end up
with a strobe light!

Activity: Real Time Dimming


Located in the myRIO toolkit, use the PWM expressVI to create a VI where you
can control the brightness of an LED.

This is a basic schematic to


see the effect of PWM on
DIO3 on an LED.

This shows the flow of


electricity.

Solution
There is a convenient ExpressVI for PWM. Simply specify the pin and control the frequency and duty
cycle.

real-time-dimming-pwmrt1.vi
real-time-dimming-pwmrt2.vi

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 26/57
1/30/2017 myRIO | Tufts Maker Network

This uses an express VI and the default FPGA to create a PWM signal on DIO3.

This is the basics of a PWM signal. it is all located on the real time processor and the default FPGA personality.

Dimming LEDs on the FPGA


Now you will create your own PWM signal on the FPGA. The major benefit to the FPGA is that it runs
extremely fast. If you are not currently working in a myRIO FPGA project right click on the myRIO and
select new Targets ad Devices. Select the myRIO chassis and because the FPGA is integrated it will be
inputed into the project. Now right click on the FPGA target and create a new VI. The FPGA also has I/O
but it works a little different.

00:27 / 11:39

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 27/57
1/30/2017 myRIO | Tufts Maker Network

(NOTE: If using a standard non-student/non-educational license you get 1 year of free cloud compile.)

(NOTE: If local compile is not working or it says "cannot find host" then you need to download Vivado
Tools.)

Activity: FPGA Dimming


Use a digital I/O write to control an LED with PWM. A control should allow
you to change the brightness. A flat sequence will help execute things in
order. It will not proceed to the next element until the previous is complete.
This way you can wait between digital writes. The pictured examples wait for
a value in use.

This activity can be done using two controls (a high count and low count) or
This is a basic schematic to
one control and a local variable. If you chose the second method you may see the effect of PWM on
also need to establish a total count or a maximum count. A PWM signal can DIO3 on an LED.

also be generated using a loop counter and threshold.

This shows the flow of


electricity.

Solution
The flat sequence method is more straightforward. Make the pin true, wait, make it false and then wait
again. Each time can be decided independently or one can be a function of the other.

The counter method uses a threshold. The counter will increase linearly until the max value, then drop to
0. If we set a threshold somewhere along that linear path we can control how long it is true vs false. Be
careful with you comparison logic if using this method.

fpga-dimming-pwmfpga1.vi
fpga-dimming-pwmfpga2.vi

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 28/57
1/30/2017 myRIO | Tufts Maker Network

This uses a flat sequence and wait commands to create a pwm signal on DIO3.

This uses a counter. If counts from 0 to the maximum specified value. If the "count
on" is less than the "current count" the LED will be off until the "current count"
passes the "count on".

Measuring Ambient Light


In order to make a nightlight, the myRIO has to
know when to illuminate the light. This can be

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 29/57
1/30/2017 myRIO | Tufts Maker Network

done with a photoresistor. The brighter it is in the


room, the less resistance it will have. If hooked up
in series with an LED you will notice the LED gets
darker as the room gets darker (cover the
photoresistor to simulate turning off the lights. But
how do we measure how dark it is in the room?
When placed in series, the photoresistor and the
LED form a voltage divider circuit and we can
measure the voltage in the middle.
This has a variable distance related to the brightness on
the sensor.

Activity: Measuring Ambient Light


Make a simple VI to graph the input voltage in between the photoresistor and the LED.

NOTE: If using the MSP port you have an AI0+ and an AI0-. You will measure in one (for measuring positive
or negative signals) and you must ground the other. If you are using the MXP port there are only AI0-AI3
so this is not an issue.

This is a graph of the voltage controlled by the photoresistor.

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 30/57
1/30/2017 myRIO | Tufts Maker Network

This schematic uses a voltage divider a measures the voltage between the photoresistor and the LED.

This schematic shows the circuit used to measure


ambient light. The LED should dim as it gets darker.

Solution
The VI here is very straightforward, just analog read into a graph.

measuring-light-photoresistor.vi

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 31/57
1/30/2017 myRIO | Tufts Maker Network

This is a simple VI for graphing the


analog input in between the
photoresistor and the LED.

The Smart Nightlight

The analog input signal is a somewhat arbitrary value, so if it is easier you can multiply the analog signal
by 1.221 to convert it into volts. Below you will make the night light on the real time processor and the
FPGA.

This schematic uses a voltage divider a measures the voltage between the photoresistor and a constant resistor. It
has an LED connected to DIO3 which will output a PWM signal.

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 32/57
1/30/2017 myRIO | Tufts Maker Network

This schematic uses a voltage divider a measures the voltage between


the photoresistor and a constant resistor. It has an LED connected to
DIO3 which will output a PWM signal.

Activity: Making The Smart Nightlight - Real Time Processor


In order to make a smart nightlight we need to
inversely control the PWM signal by the amount of
light. That is the darker the room, the brighter the
light and vice versa. How can you convert the
input into a duty cycle for the PWM signal?

Make a graph of the raw data vs. the PWM signal so


that the inverse relationship is visible. Make a
control for the PWM frequency. Notice how the
light starts to flash if the frequency drops too low? How can you invert the analog input into a PWM duty
cycle?

SPACES HANDBOOKS EQUIPMENT MAKERS GROUPS PROJECT S ABOUT

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 33/57
1/30/2017 myRIO | Tufts Maker Network

This is the graph of PWM signal vs analog input. Notice the


inverse relationship.

Solution
Once the basic architecture for the night light is complete, the math should not be too difficult or
complex. Using the maximum and minimum values from the analog input convert accordingly to a value
between 0 and 1. A linear function works well for this.

night-light-realtime-main_rt.vi

This is the completed block diagram for the night light.

Activity: Making The Smart Nightlight - FPGA


The FPGA is extremely fast and can run while the
real time processor is doing other applications.
This allows for parallel processing. It is hard to
SPACES HANDBOOKS EQUIPMENT MAKERS GROUPS PROJECT S ABOUT
analyze data on the FPGA but it is great for data
acquisition.

FPGAs can only carry certain data types like


integers, fixed-point, and single precision
numbers. How can you use the PWM from the previous activity to
create the nightlight?
Use the same circuit as the real time night light but
transfer all the processing to the FPGA. This will require the use of FPGA I/O nodes and one of the two

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 34/57
1/30/2017 myRIO | Tufts Maker Network

types of FPGA PWM signals you generated earlier. You should also make a real time VI that calls the FPGA
program so you do not need to recompile as often.

Solution
Depending on which way you prefer to code a PWM signal on the FPGA there are at least two options
here.

If you chose the sequence option you can filter the data to be within a certain range and then subtract
that lower bound. This will give data between 0 and the upper bound minus the lower bound. This can
then be used to generate a PWM.

If you are using the loop counter to generate the PWM filter the data the same way and then compare it
to the current loop counter. Be careful with your logic.

night-light-fpga-main_fpga1.vi
night-light-fpga-main_fpga2.vi

This uses the flat sequence to create a PWM signal. The high and low values can be calibrated according to the light
in the room. The input data is filtered to make sure it will not cause an error from being above or below the
SPACES HANDBOOKS EQUIPMENT MAKERS
calibrated values. GROUPS PROJECT S ABOUT

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 35/57
1/30/2017 myRIO | Tufts Maker Network

This uses the counter method to create a PWM signal. The high and low values can be calibrated according to
the light in the room. The data is filtered to make sure it will not cause a math error.

Going Further
Visit Dr. E's Challenges to upload your own smart night solutions, and see how others approached this
project.

Here are some other cool project ideas that use the same basic principles as the smart nightlight.

Analyzing data from different types resistor inputs (pressure, temperature, color, etc)
Changing colors of an RGB LED as input values change.

Project 4: Digital Dice

SPACES HANDBOOKS EQUIPMENT MAKERS GROUPS PROJECT S ABOUT

In this project you will create digital dice using a basic LED pixel matrix. When shaken the myRIO will
choose a random number, show a "thinking pattern", then display it like the face of a die on the LED
display.
https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 36/57
1/30/2017 myRIO | Tufts Maker Network

For this project we will need 9 digital outputs so you should use the MXP port. You can either use this
schematic and female header wires or the MXP wirewrap that comes with the myRIO or various other
expansion boards.

For this project you will need:

An MXP expansion system


9 LEDs (you can choose the color and size)
Jumper wires

In this project we will use SubVIs to simplify the block diagram.

Creating the Pixel Matrix


For the digital dice we will use 9 LEDs set up in a square. Remember that LEDs are forward biased and
will only work in one direction.

SPACES HANDBOOKS EQUIPMENT MAKERS GROUPS PROJECT S ABOUT

Use this to create your own pixel matrix.

Activity: Wiring the pixel matrix

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 37/57
1/30/2017 myRIO | Tufts Maker Network

Wire all the the cathodes (short end) to the same ground on your board. Then connect this to ground.
Each LED will connect to its own digital pin.

Use this to help wire the circuit if you are not using an MXP breakout board.

SPACES HANDBOOKS EQUIPMENT MAKERS GROUPS PROJECT S ABOUT

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 38/57
1/30/2017 myRIO | Tufts Maker Network

NOTE: Replace the red wires with LEDs. Use this to create your own pixel matrix.

How to Trigger the Dice


To be as realistic as possible, the die should change every time you throw it. However, we can't throw a
myRIO and LEDs around, so what if we shake the device?

How can you tell when the device was shaken? Lets start with some basic accelerometer tests.

Activity: Triggering
Plot the accelerometer data as well as the sum of
each data stream. What happens when you shake
or bump the myRIO? How is it different from slowly
rotating the device?

Use this information to write a VI that lights up a


virtual LED and stops the program if the device is
shaken or bumped. Call this vi trigger.vi.
SPACES HANDBOOKS EQUIPMENT MAKERS GROUPS PROJECT S ABOUT

A graph of the accelerometer [total, x, y, and z] when the


device is shaken and bumped. How can you use this to
trigger an event or exit a loop?

Solution
A threshold of a combined 2G's of shaking/bumping the myRIO will trigger an action. Whenever the
combined accelerations are over that threshold the loop will end.

digital-dice-trigger-solution.vi

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 39/57
1/30/2017 myRIO | Tufts Maker Network

The background code for triggering the dice to generate a


new number. I used a threshold of 2G's for the
shaking/bumping.

Creating a Pattern with the LEDs


After you shake your myRIO to trigger a new dice number you should show a "thinking" display. This
display can be a sequence of commands. For this you should use either a flat sequence or a stacked
sequence. A LabVIEW sequence will dictate the order of execution when there is no dataflow. A flat
sequence is great for small sequence, but you should use a stacked sequence for anything long because
they take up less space.

Activity: Thinking patterns


Use a sequence to create a "thinking pattern" VI. It
can last for as long or short as you would like, I
made mine about one second. Be creative and
have fun with it. You can also include loops. Make
sure the VI is under the myRIO target in the project
and call it thinking.vi. This pattern will run while the myRIO is thinking. Be
SPACES HANDBOOKS EQUIPMENT creative and come
MAKERS up with your
GROUPS own cool pattern.
PROJECT S ABOUT
Do not put the entire thing in a loop, unless the
loop will automatically terminate after the pattern has been played (via a boolean or loop count etc).

Making the Dice


Now that you have a trigger.vi and a thinking.vi, lets make a dice.vi. We need
to select a random number between 1 and 6 and then display it like a classic
die. In the numeric palette there is a random number generator. This will
output a decimal between 0 and 1.
https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 40/57
1/30/2017 myRIO | Tufts Maker Network

NOTE - If you want a non-looping program to run continuously you can use
These are the 6 faces of a
the run continuously button located next to the run button (two curved
standard die that can be
arrows in a circle). recreated with LEDs.

Activity: Making Faces


Use the random number generator and a case structure to show (light up LEDs) the numbers 1-6. Even
though only 6 cases are possible, there still must be a default case in the case structure (choose
whichever you want). Name this VI dice.vi. (HINT-keep in mind that the random number generator will
output a decimal between 0 and 1.)

Solution
A random number generator in LabVIEw will generate a decimal between 0 an 1, which is then scaled and
rounded to 1 to 6. This value is used in a case structure because every number has a distinct LED pattern.

digital-dice-faces-solution.vi

This generates a number between 1 and 6 and displays


the appropriate dice face.
SPACES HANDBOOKS EQUIPMENT MAKERS GROUPS PROJECT S ABOUT

Putting It All Together


Now we will put the previous 3 VIs together. The reason you made them all as separate VIs with the same
target is so that you can use them as subVIs. SubVIs will make your main program a lot cleaner. In the top
right corner of each front panel there is a grid and an icon. You can use the grid to create inputs and
outputs from your subVI. If you double click the icon you can create a custom icon for your subVI.

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 41/57
1/30/2017 myRIO | Tufts Maker Network

Activity: Making Faces


Use a flat sequence to first initialize all the LEDs to
off. Then enter a main loop with a stop button.
Inside this loop, use the 3 subVIs you created. To
add a subVI to your code, simply drag the file
name from the project tree into the VI. To view or
edit the code of the subVI, just double click the
icon. Since in this case none of the VIs have inputs
or outputs you will need a sequence to dictate the
order in which they execute?

Use these to create inputs and outputs and give the subVI
a custom icon.

Solution
In all of the examples all the LEDs are turned off, then it waits, then it thinks, then it displays, and so on.
SPACES HANDBOOKS EQUIPMENT MAKERS GROUPS PROJECT S ABOUT
The solution with the custom SubVIs is much cleaner and easier to follow. One of the examples uses a
flat sequence, the other uses boolean controls and indicators (data flow) to control the order of
execution.

digital-dice-main_messy.vi
digital-dice-main_middle.vi
digital-dice-main_simple.vi

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 42/57
1/30/2017 myRIO | Tufts Maker Network

Without subVIs this code looks confusing, messy, and hard to follow.

SubVIs make this main program very simple and clear.

SPACES HANDBOOKS EQUIPMENT MAKERS GROUPS PROJECT S ABOUT

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 43/57
1/30/2017 myRIO | Tufts Maker Network

A boolean control and indicator for each subVI force the order
of execution similar to a sequence.

Going Further
Visit Dr. E's Challenges to upload your own digital dice solutions, and see how others approached this
project.

Here are some other cool project ideas that use the same basic principles as the digital dice.

Make a visual countdown clock (draw each number in LEDs)


Vary the image or flashing rate based on a variable resistor (light, temperature, pressure)
Control which LED is on with the accelerometer

You can use a row/column method to create displays with more LEDs than ports. For examples and
information on this click here.

Project 5: Audio Loop Station

In this handbook, you will use the audio in and audio out ports to create a loop station. You can record a
sample of sound and then layer more sound on top of it.

For this project you will need:

A microphone (standard stereo 2 band only)


Headphones or speaker

SPACES HANDBOOKS EQUIPMENT MAKERS GROUPS PROJECT S ABOUT

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 44/57
1/30/2017 myRIO | Tufts Maker Network

Any standard stereo microphone should work, I used both a Chuenyun CY-502 from the myRIO starter kit
and a Rode VideoMic Pro.

The Basics of Sound


The microphone used in this tutorial has 3
sections: left audio, right audio, and ground. The
standard stereo audio jack functions as an analog
input or output. An electric microphone uses a
permanently-charged parallel plate capacitor to
create a varying voltage as sound hits it. The
battery powered microphone uses an impedance Waves travel through air as standing waves. Then, the
converter to do the same thing. moving air vibrates your eardrum and you brain interprets
it as sound.

Audio waves are almost never a single amplitude or


frequency. When we speak, the sound is composed of
thousands of different frequencies and amplitudes.

SPACES HANDBOOKS EQUIPMENT MAKERS GROUPS PROJECT S ABOUT

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 45/57
1/30/2017 myRIO | Tufts Maker Network

Microphones are capable of picking up sounds of all different frequencies, but humans are only capable
of hearing within a certain range.

Viewing Audio Waves


Keep in mind that the microphone is outputting a
voltage into the audio jack. This allows LabVIEW
and the myRIO to interpret and record it. To record
audio, we simply have to store all of the data
points.

Sound travels in standing waves.

Activity: Audio Input


Create a VI that view the audio wave on a chart
when a button is pressed. It should include a stop
button. Keep in mind that the analog channels
take arrays and not values. Use the index array
function to convert from a 1 by 1 array to a double
precision number.

The rate at which you choose to collect data will


affect the visible waveform. Use a control or You can see the duration and intensity of the sounds.
change the constant and see what happens.

Right click inside the chart and extend the chart length history to 4096 to remember more data points.
Also, turning off autoscale on the Y axis and choosing the upper and lower bounds may help to visualize
the sound waves.

Solution
Use a timed loop to take
SPACES in samples. This
HANDBOOKS will allow for a MAKERS
EQUIPMENT controllable constant
GROUPS rate. PROJECT
To trigger the
S timed
ABOUT

loop use either an event structure or a while loop with a case structure.

audio-loop-viewer.vi

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 46/57
1/30/2017 myRIO | Tufts Maker Network

This is the block diagram for viewing audio waves. I found 100usec to be a good sampling rate.

Storing Data
To store data for this activity we can use an array.

The easiest way to fill an array is with a loop. When you create an indicator outside of the loop and
connect it to the data (indexed analog in) a small square will appear at the loop border. With this tunnel,
you can output the last value (solid box) or all of the values (bracketed box).

SPACES HANDBOOKS EQUIPMENT MAKERS GROUPS PROJECT S ABOUT

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 47/57
1/30/2017 myRIO | Tufts Maker Network

Activity: Playing Recorded Sounds


Modify your original audio wave viewing VI to
output all of the collected data from the loop to an
array. It is now effectively a recording VI because
you have a record of all the data. Right click on an
indicator in the block diagram to hide it from the
front panel.

Now make a similar loop that will output that


array of data to the audio out port. Create a start
and stop button for that as well. Make sure to
record and play the data at the same speed
otherwise the data will not sound the same. Use
the build array function to convert from a double
precision value to a 1 by 1 array.
Notice the exact same wave played back at the same
This is possible without any sequencing because of speed.
data flow. The player can not play until the data
array is created when the recording loop is finished.

Solution
The use of an auto-indexing loop tunnel allows arrays to be created and indexed easily. There are also
data type conversions to work between arrays and double precision numbers.

Event structures
SPACES canHANDBOOKS
also be used. EQUIPMENT MAKERS GROUPS PROJECT S ABOUT

audio-loop-play-playback.vi

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 48/57
1/30/2017 myRIO | Tufts Maker Network

This is the recording loop. It uses an autoindexing tunnel.

This is the playback loop. It uses an auto indexing tunnel.

Combining Audio
To combine audio data we can add the data
arrays. However, a sum operation of the two
arrays will not work. Instead each element needs
to be summed with its corresponding element
from the other array.
SPACES HANDBOOKS EQUIPMENT MAKERS GROUPS PROJECT S ABOUT

When adding waves of different frequency and amplitude


there can be constructive and destructive interference.

Activity: Combining Two Tracks


https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 49/57
1/30/2017 myRIO | Tufts Maker Network

Activity: Combining Two Tracks


Record 2 different signals into 2 different arrays.
Then combine the signals and output the results.
When you listen to the combination you should be
able to hear both sounds at the same time. Also
notice that the noise volume has increased.

The graphs are no longer necessary, but they give a visual


interpretation of the incoming and outgoing data.

Solution
A stacked sequence allowed me to force the order of execution. This way, I am only dealing with full
arrays of data. A sequence would not be needed if both arrays were initialized before the recording was
done. A simple for loop with auto-indexing tunnels sums the elements of the array and outputs the
results as one array.

audio-loop-two-waves-combining.vi

SPACES HANDBOOKS EQUIPMENT MAKERS GROUPS PROJECT S ABOUT

This records the first sample and stores it in array1.

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 50/57
1/30/2017 myRIO | Tufts Maker Network

This records the second sample and stores it in array2.

This sums each element of the two samples and stores them in another array.

SPACES HANDBOOKS EQUIPMENT MAKERS GROUPS PROJECT S ABOUT

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 51/57
1/30/2017 myRIO | Tufts Maker Network

This plays the combined array data array.

Infinite Looping and Clearing


A loop station should be able to record more than
just two sounds. This means that after each
recording, the new data should be added to the
playing data array and it should wait for the next
record command.

Local variables will be very important in this


section, as the below video describes:

This is the final front panel control interface for the loop
terminal.

SPACES HANDBOOKS EQUIPMENT MAKERS GROUPS PROJECT S ABOUT

0:00 / 5:37

Activity: Reseting the Loop Station


To make things more consistent and to avoid
possible memory issues, reconfigure your record

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 52/57
1/30/2017 myRIO | Tufts Maker Network

and play loops to run for a controlled amount of


time (maybe the user can specify how long).

In parallel with the other loops, add a clear array


"function". When a button is pressed all of the
data in the array is set to 0. Based on the user
input for sample time, the program should know
how many array elements there are.

To use information like frequency and period of a


timed loop use the property node that
automatically populates inside the loop on the The user will specify the time to record. The stop
recording and stop playing buttons are no longer needed.
left. To control them, use the terminals on the There is also now a clear array button to delete all sounds
outside of the loop. in the array.

Solution
Now that the user is specifying the time to record, some simple calculations provide the program with
how many array elements are needed. This is used when recording, playing, and clearing.

SPACES
The stop HANDBOOKS
button has been replaced with aEQUIPMENT
loop counter. Also, MAKERS
notice the numGROUPS PROJECT
elements indicator S
which states how
ABOUT
many elements there are in the array.

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 53/57
1/30/2017 myRIO | Tufts Maker Network

This loop uses the number of elements to clear the entire array
whenever the button is pressed.

The stop button has been replaced with a loop counter. Also, notice the num elements indicator which states how
many elements there are in the array. Also, the signal has been multiplied by 5 to increase volume and plays out
both audio channels.

Activity: Infinite Looping and Adding of Samples


Now that you can clear the array at any time, add
functionality so you can add to the array at any
time. The any time part should not be difficult, but
how do you add it to the current array?

Also playback the current audio when recording so


the user can hear what they are looping over.

SPACES HANDBOOKS EQUIPMENT MAKERS GROUPS PROJECT S ABOUT

This shows recording multiple sounds. It also has


playback as it records.

Solution
https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 54/57
1/30/2017 myRIO | Tufts Maker Network

Another for loop with auto-indexing tunnels allows for adding of recorded data to previous data. The
programs goes through the old array then creates a new array called the same thing, essentially
overwriting the old array. A flat sequence is used to ensure the correct order of execution. The entire
thing has been surrounded by another while loop to allow for as many sounds as the user wants.

Also, the player will run simultaneously with the recorder so the user can hear what they are recording
over.

audio-loop-infinite-autoloop.vi

The for loop will overwrite the old array with the sum of the old array and the new array.

SPACES HANDBOOKS EQUIPMENT MAKERS GROUPS PROJECT S ABOUT

The new audio player will run while the record loop runs so the user can hear what they are recording over.

Going Further
https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 55/57
1/30/2017 myRIO | Tufts Maker Network

Visit Dr. E's Challenges to upload your own audio loop solutions, and see how
others approached this project.

Here are some other cool project ideas that use the same basic principles as
the audio loop station.

How can you distort the sounds?


Use a fast fourier transform to view the frequencies
Can you filter out the background noise?
Use a variable resistor to control the volume of output audio
You can use a fast fourier
transform [FFT] to filter out
waves of certain frequencies.

Project 6: myRIO WebSocket

This webpage is able to connect to a networked myRIO via a WebSocket. Commands and information
can be transmitted
SPACES back and forth, allowing
HANDBOOKS interaction with
EQUIPMENT a myRIO remotely
MAKERS GROUPSoverPROJECT
a wireless S ABOUT

connection.

What Are WebSockets?


To communicate with networks and devices
computers use ports. The port we will use for
WebSocket communication is number 6123 using
a Transmission Control Port (TCP for short). A

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 56/57
1/30/2017 myRIO | Tufts Maker Network

protocol is a system of rules that two or more


things use to communicate. Normally, you will
need to program both sides of the connection, but
we have already done the web-based portion for
you.

The myRIO and this website will communicate over a TCP


WebSocket.

Getting WebSockets for your myRIO


There are a few simple steps for getting TCP
WebSockets to work with your myRIO.

1. Download and install the latest version of


WebSockets for LabVIEW.
2. When targeting a myRIO, you should see the
WebSockets SubVIs under the Data &
Communication functions palette.
3. Download the VIs attached to the right. (You
need the API from step 1 for these to work)
4. Configure your myRIO to work on a wireless
network (any wireless network except the
locally hosted myRIO web server) and figure out
the myRIO's IP address.
Once downloaded the WebSockets API can be found
These WebSockets will be able to send strings and
under the Data & Communication functions palette.
JSON files back and forth.

websocket.zip

Web LED Control


For each top level VI (the main controller) you want to connect with a WebSocket you will have to set up
the connection
SPACESand end the connection.
HANDBOOKS The set of VIs downloaded
EQUIPMENT MAKERS from here will take
GROUPS care of that
PROJECT S for
ABOUT

you. There is also a special read and write VI that has been created to make the WebSocket interface
more intuitive. Normally if you wire a read then a write the program will wait for a read before it writes.
However, this VIs will check for a read and a write at the same time to allow for constant reading or
writing without relying on a predetermined order.

https://maker.tufts.edu/handbooks/myrio#project­3­smart­night­light 57/57

You might also like