0% found this document useful (0 votes)
26 views

LabVIEW LINX and Arduino

Uploaded by

fhamdi
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

LabVIEW LINX and Arduino

Uploaded by

fhamdi
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 92

https://www.halvorsen.

blog

LabVIEW LINX
and Arduino
LabVIEW + LabVIEW LINX Toolkit + Arduino

Hans-Petter Halvorsen
Contents
• This Tutorial shows how we can use Arduino in
combination with the LabVIEW Programming environment
• “LabVIEW LINX Toolkit” is an add-on for LabVIEW which
makes it possible to program the Arduino device using
LabVIEW
• In that way we can create Data Logging Applications, etc.
without the need of an expensive DAQ device
• If you don’t have “LabVIEW Professional” Software, you
may use the “LabVIEW Community Edition” (free for non-
commercial use). You then get a very low-cost
DAQ/Datalogging System!
Table of Contents
• Introduction to LabVIEW LINX
• DAQ System
• Input/Output Channels
– Digital I/O
• Digital Out/Write
• Digital In/Read
– Analog I/O
• Analog Out/Write -> PWM (Pulse Width Modulation)
• Analog In/Read
• Sensors
– TMP36 Temperature Sensor
– Thermistor Temperature Sensor
LabVIEW + LabVIEW LINX Toolkit
PC
Arduino UNO
LabVIEW Sensors
+
LabVIEW LINX Toolkit
U
S
B TMP36
Temperature
c Sensor
a
b
Hardware
• Arduino
• Breadboard
• Wires (Jumper Wires)
• Resistors (𝑅 = 270Ω, 𝑅 =
10𝑘Ω)
• LED, Push Button
• TMP36 Temperature Sensor
Arduino UNO
• Arduino is a Microcontroller
• Arduino is an open-source platform
with Input/Output Pins (Digital
In/Out, Analog In and PWM)
• Price about $20
• Arduino Starter Kit ~$40-80
with Cables, Wires, Resistors, Sensors, etc.
Arduino I/O Channels
Digital Inputs and Digital Outputs
You can choose from the
code if they are to be
inputs or outputs

Those marked with ~ can also


be used as "Analog
Outputs", so-called PWM
outputs

Analog Inputs
LabVIEW
• LabVIEW is Graphical Software
• LabVIEW has powerful features for
simulation, control and DAQ
applications
Basic LabVIEW Example:
LabVIEW LINX Toolkit
• The LabVIEW LINX Toolkit adds
support for Arduino, Raspberry Pi,
and BeagleBone embedded
platforms
• We will use Arduino Uno in this
Tutorial
Installing LabVIEW LINX Toolkit
Use VI Package Manger

Note: Do not install this package if you are running LabVIEW 2020 Community Edition or later,
as the Community Edition already includes the LabVIEW LINX Toolkit
LabVIEW LINX
LINX Firmware Wizard
LabVIEW Palette
https://www.halvorsen.blog

DAQ System

Hans-Petter Halvorsen Table of Contents


DAQ System
DAQ – Data Acquisition
Input/Output Signals
Analog Signals
Software
Analog IO
Digital Signals Application

USB, etc. Hardware Driver

Sensors Digital IO
(Analog/Digital
Interface) Data Acquisition PC
Hardware
We will use an Arduino Uno as the DAQ Hardware
I/O Module
Analog Signals

0 − 5𝑉 Analog Input (AI)


Analog Sensors Analog Output (AO)
Analog IO

I/O Module

Digital IO Digital Signals


True
Digital Input (DI)
False
Digital Output (DO)
Sensors with Digital Interface (e.g., SPI, I2C)
https://www.halvorsen.blog

LabVIEW LINX
Arduino DAQ System
Hans-Petter Halvorsen Table of Contents
https://www.halvorsen.blog

Input/Output
Channels
Hans-Petter Halvorsen Table of Contents
Arduino I/O Channels
Digital Inputs and Digital Outputs
You can choose from the
code if they are to be
inputs or outputs

Those marked with ~ can also


be used as "Analog
Outputs", so-called PWM
outputs

Analog Inputs
Input/Output Channels
• Digital
–Digital Out
–Digital In
• Analog
–Analog Out
–Analog In
https://www.halvorsen.blog

Digital I/O

Hans-Petter Halvorsen Table of Contents


LabVIEW Palette – Digital I/O
Digital I/O
Digital Inputs and Digital Outputs
You can choose from the
code if they are to be
inputs or outputs

Those marked with ~ can also


be used as "Analog
Outputs", so-called PWM
outputs
https://www.halvorsen.blog

Digital Out (DO)

Hans-Petter Halvorsen Table of Contents


Digital Out (DO)
• We will use the Digital Out pins to
turn on/off a LED
Breadboard Wiring
Make sure not to short-circuit
the components that you
wire on the breadboard

The Breadboard is used to connect components and electrical circuits


LED Wiring

LED

𝑅 = 270Ω
LabVIEW Example
Multiple Digital Out Channels
https://www.halvorsen.blog

Digital In (DI)

Hans-Petter Halvorsen Table of Contents


LabVIEW - Digital In
We can test the Digital In (Read) by wiring to 5V (True/High) or GND (False/Low)

False/Low True/High
LabVIEW - Digital In
LabVIEW Digital Write - Read
We can test the Digital In (Read) by wiring a Digital
Out (Read) Channel to the Digital In (Read) Channel
LabVIEW Digital Write - Read
Push Button/Switch
• Pushbuttons or switches connect two
points in a circuit when you press them.
• You can use it to turn on a Light when
holding down the button, etc.
Light
+ Switch (On/Off)

Power Supply

-
Wiring (Pull-up Resistor)
Another Digital Channel Using external Pull-up Resistor
can of course be used

𝑅 = 10𝑘Ω
Pull-down/Pull-up Resistor
Why do we need a pull-up or pull-down resistor in the
circuit?
• If you disconnect the digital I/O pin from everything, it
will behave in an irregular way.
• This is because the input is "floating" - that is, it will
randomly return either HIGH or LOW.
• That's why you need a pull-up or pull-down resistor in
the circuit.
Pull-up Resistor
+5V • When the pushbutton is open
(unpressed) there is a connection
Resistor between 5V and the DI pin.
DI • This means the default state is
True
Switch
(High).
• When the button is closed
GND
(pressed), the state goes to False
Pull-up Resistor
True/High False/Low
+5V +5V

Resistor Resistor

DI DI

Switch We Push the Button Switch


Open
Closed

GND GND
Push Button (Pull-up Resistor)
Button is NOT Pushed => True/High

Button is Pushed => False/Low


Adding a “NOT” block
Button is NOT Pushed => False/Low

Button is Pushed => True/High


Pull-down Resistor
We could also have wired according to a “Pull-down“ Resistor
False/Low True/
High +5V
+5V
Switch Switch
Open
Closed
DI DI

We Push the Button


Resistor Resistor

GND GND
Wiring (Pull-down Resistor)
Another Digital Channel Using external Pull-down Resistor
can of course be used

𝑅 = 10𝑘Ω
Push Button (Pull-down Resistor)
Button is NOT Pushed => False/Low

Button is Pushed => True/High


https://www.halvorsen.blog

Analog I/O

Hans-Petter Halvorsen Table of Contents


Analog I/O
Those marked with ~ can also
be used as "Analog
Outputs", so-called PWM
outputs
LabVIEW Palette – Analog I/O
https://www.halvorsen.blog

Analog Out (AO)

Hans-Petter Halvorsen Table of Contents


Analog Out
• Arduino UNO has no real Analog Out
• We need to use Pulse Width Modulation
(PWM)

Not Working!
PWM as “Analog Out”
The Arduino UNO has no
real Analog Out pins,
but we can use a PWM
pin.

PWM can be used to


control brightness of a
LED, control the speed of
a Fan, control a DC Motor,
etc.
PWM
PWM is a digital (i.e., square wave) signal that oscillates according to a given frequency and
duty cycle.
The frequency (expressed in Hz) describes how often the output pulse repeats.
The period is the time each cycle takes and is the inverse of frequency.
The duty cycle (expressed as a percentage) describes the width of the pulse
within that
frequency window.

You can adjust the duty cycle


to increase or decrease the
average "on" time of the
signal. The following diagram
shows pulse trains at 0%,
25%, and 100% duty:
PWM
The Digital Pins marked with ~
can be used as "Analog
Outputs", so-called PWM
outputs
Control Brightness of a LED
• We've seen how to turn an LED on and off, but how do
we control its brightness levels?
• An LED's brightness is determined by controlling the
amount of current flowing through it, but that requires a
lot more hardware components.
• A simple trick we can do is to flash the LED faster than
the eye can see!
• By controlling the amount of time the LED is on versus
off, we can change its perceived brightness.
• This is known as Pulse Width Modulation (PWM).
Control Brightness of a LED
Below we see how we can use PWM to control the brightness of a LED

https://www.electronicwings.com/raspberry-pi/raspberry-pi-pwm-generation-using-python-and-c
Wiring
LED

𝑅 = 270Ω
PWM Example
We will see the brightness of the LED
will increase.
Or you can use a Multimeter and see
the (average) voltage will increase
PWM Example
PWM Example
20% → 1V 1V

0-100% → 0-5V
https://www.halvorsen.blog

Analog In (AI)

Hans-Petter Halvorsen Table of Contents


Analog Input
Analog In
Analog In
https://www.halvorsen.blog

LabVIEW LINX
Arduino
Temperature Sensors
Hans-Petter Halvorsen Table of Contents
https://www.halvorsen.blog

Sensor
s
Hans-Petter Halvorsen Table of Contents
Sensors
We will use 2 different types of Temperature
Sensors:
• TMP36 Temperature Sensor
• Thermistor Temperature Sensor
Sensors

You can use these, or you


can also easily make
Some Examples of your own VIs for
premade Sensor VIs interfacing Sensors from
scratch
https://www.halvorsen.blog

TMP36
Temperature
Sensor
Hans-Petter Halvorsen Table of Contents
Hardware
• Arduino
• Breadboard
• TMP36 Temperature Sensor
• Wires (Jumper Wires)
TMP36 Temperature Sensor
• A Temperature sensor like TM36 use
a solid-state technique to determine
the temperature.
• They use the fact as temperature
increases, the voltage across a diode
increases at a known rate.
• It costs only about $1

https://learn.adafruit.com/tmp36-temperature-sensor
TMP36

TMP is a small, low-cost temperature sensor and cost about $1 (you can buy it “everywhere”)
Wiring
LabVIEW
LabVIEW LINX has a built-in SubVI for TMP3x Sensors
LabVIEW
Do it from
Scratch
• LabVIEW LINX has a built-in SubVI for
TMP3x Sensors (TMP3x.vi)
• Let's see how we can do it from
“Scratch”
• We use the Datasheet and the
ordinary “Analog Read.vi”
Output Voltage vs. Temperature
Datasheet
Linear Scaling
Convert form Voltage (V) to degrees Celsius
From the Datasheet we have:

(𝑥1 , 𝑦1 ) = (0.75𝑉,
25°𝐶) (𝑥2, 𝑦2) = (1𝑉,
50°𝐶)

There is a linear relationship between


Voltage and degrees Celsius:
This gives: 𝑦 = 𝑎𝑥 + 𝑏
We can find a and b using the following
50 − 25
𝑦 − 25 = 1 − 0.75(𝑥 − 0.75) known formula:

Then we get the following formula: 𝑦2 − 𝑦1


𝑦 − 𝑦1 = (𝑥 − 𝑥1)
𝑦 = 100𝑥 − 50 𝑥 2 − 𝑥1
LabVIEW Example

𝑦 = 100𝑥 − 50
https://www.halvorsen.blog

Thermistor
Temperature Sensor
Hans-Petter Halvorsen Table of Contents
Thermistor
A thermistor is an electronic component that changes
resistance to temperature - so-called Resistance
Temperature Detectors (RTD). It is often used as a
temperature sensor.
Our Thermistor is a so-called NTC (Negative Temperature Coefficient).
In a NTC Thermistor, resistance decreases as the temperature rises.
There is a non-linear relationship between resistance and excitement. To find the
temperature we can use the following equation (Steinhart-Hart equation):
[Wikipedia]
where 𝐴, 𝐵, 𝐶 are constants given
1
𝑇 = 𝐴 + 𝐵 ln(𝑅) + 𝐶 ln(𝑅) 7 below
𝐴 = 0.001129148, 𝐵 = 0.000234125 𝑎𝑛𝑑 𝐶 = 8.76741𝐸 −
Hardware
• Arduino
• Breadboard
• Thermistor 10K (Temperature Sensor)
• Wires (Jumper Wires)
• Resistor 10 kΩ
Wiring
Thermistor

𝑅 = 10 𝑘Ω
Voltage Divider
The wiring is called a “Voltage divider”:
+5V

10𝑘 Thermistor

Analog In (AI)

𝑅 = 10𝑘Ω

GND
[https://en.wikipedia.org/wiki/Voltage_divider]
General Voltage Divider
We want to find 𝑉𝑜𝑢𝑡

𝑅1 Formula:
+

𝑅&
𝑉𝑜 𝑢 = 𝑉$𝑛
𝑉&𝑛
+

𝑅1 +
-
𝑅2 𝑉𝑜𝑢𝑡
-
𝑡
𝑅&
https://learn.sparkfun.com/tutorials/voltage-dividers/all
Voltage Divider for our System
Voltage Divider Equation:
+ 𝑅 ( = 10𝑘Ω
𝑅𝑡
𝑉𝑜𝑢 = 𝑉<𝑛 5𝑉 𝑉&𝑛 +
𝑡 𝑅> + - 𝑅𝑡 𝑉𝑜 𝑢 𝑡
-
We want to find 𝑅𝑡 : 𝑅𝑡
𝑅𝑡 - 10k Thermistor. This varies with
𝑅𝑡 = 𝑉 𝑜u𝑡 𝑅 $ temperature. From Datasheet we
𝑉 i 𝑛 $ 𝑉 𝑜 u𝑡 know that 𝑅𝑡 = 10𝑘Ω @25℃
Steps:
1. We wire the circuit on the Breadboard and connect it to the DAQ device
2. We measure 𝑉𝑜𝑢𝑡 using the DAQ device
3. We calculate 𝑅𝑡 using the Voltage Divider equation
4. Finally, we use Steinhart-Hart equation for finding the Temperature
Steinhart-Hart Equation
To find the Temperature we can use Steinhart-Hart Equation:
1
𝑇𝐾 = 𝐴 + 𝐵 ln(𝑅) + 𝐶 ln(𝑅)
*

This gives:
1
𝑇𝐾 = 7
𝐴 + 𝐵 ln 𝑅 + 𝐶 ln 𝑅
𝐴 = 0.001129148
Where the Temperature 𝑇𝐾 is in Kelvin
𝐵 = 0.000234125
𝐴, 𝐵 𝑎𝑛𝑑 𝐶 are constants 𝐶 = 0.0000000876741
The Temperature in degrees Celsius will then be:

𝑇𝐶 = 𝑇𝐾 − 273.15
Pseudo Code
1. Get 𝑉𝑜𝑢𝑡 from the DAQ device (Arduino UNO)

2. Calculate 𝑅𝑡 = 𝑉 𝑜u𝑡 𝑅 $
𝑉 i𝑛 – 𝑉 𝑜 u𝑡

R
3. Calculate 𝑇𝐾 = 3
𝐴T𝐵 𝑙𝑛 𝑅 𝑡 T𝐶 𝑙𝑛 𝑅 𝑡

4. Calculate 𝑇𝐶 = 𝑇𝐾 − 273.15

5. Present 𝑇𝐶 in the User Interface


Pseudo Code
float Vin = 5;
float Ro=10000;
float Rt =
(Vout*Ro)/(Vin-
Vout);

//Steinhart constants
float A = 0.001129148;
float B =
0.000234125;
float C =
0.0000000876741;

//Steinhart-Hart
Equation
LabVIEW
LabVIEW - Steinhart-Hart Equation
Alternative 1: Formula Node

Something may be easier to do in a


text-based programming language
LabVIEW - Steinhart-Hart Equation
Alternative 2: Pure LabVIEW Code
Summary
• This Tutorial has shown how we can use Arduino in
combination with the LabVIEW Programming environment
• “LabVIEW LINX Toolkit” is an add-on for LabVIEW which
makes it possible to program the Arduino device using
LabVIEW
• In that way we can create Data Logging Applications, etc.
without the need of an expensive DAQ device
• If you in addition use the “LabVIEW Community Edition”
(free for non-commercial use) you get a very low-cost
DAQ/Datalogging System!
• You can also easily add features for logging data to Files or a
Database System like SQL Server, or an OPC Server
Hans-Petter Halvorsen
University of South-Eastern Norway
www.usn.no

E-mail: [email protected]
Web: https://www.halvorsen.blog

You might also like