Tutorial 2: Programming Arduino with LabVIEW: In our last tutorial we have seen how to get started with LabVIEW . We answered what is LabVIEW? How its program looks like and How to make our first program in LabVIEW? Today’s tutorial is about the interfacing of LabVIEW and Arduino. We will explore about
- What Arduino is?
- Why interfacing of Arduino is necessary with LabVIEW?
- Necessary softwares required for interfacing of LabVIEW and Arduino?
- How to make a program in LabView, upload it to Arduino and control it through user interface?
What Arduino is?
Arduino is open source hardware board with many open source libraries to interface it’s on board microcontroller with many other external components like LED , motors , LCD , keypad , Bluetooth module , GSM module and many other things one want to interface with Arduino board. Arduino is basically make from a microcontroller but Arduino have all external socket to connect with other devices and it also have built in programmer which is used to program Arduino from computer. So Arduino is a complete board which includes all things to connect with external peripheral and easy to program through computer. There are many Arduino borads are available. But in this article I will give you brief review of Arduino UNO R3 which is very popular board among engineering students.
Arduino is the one of the most excellent electronic platform of the 21st century; it has accompanied the entire micro controller system into a small and handy device. It is an open source hardware and anyone can used it due to its friendly and easiness and can be used to create complex project by simple programming algorithms. It is not only to use design and develop but also can test the prototyped and hardware infinite times. The hardware consist of different microcontroller depending on the model that you are using with other electronic components which can be programmed using its own software the Arduino IDE to do almost any task starting from a simple LED glowing to building an Mars Rover and Drone Systems. The human friendly nature of the Arduino language makes it easier for everyone who wants to build different prototypes and hardware for its own interest as well as for some industrial purposes. Additionally, it possesses a simplified version of C++ which makes it easier to build programs at your own.
Arduino is intended for the people who want to play, run and build the complex hardware’s without knowing very much of the programming skills and algorithmic knowledge. It’s the best open source platform currently available in the market and has created another revolution and usage after its huge demand in the public. Since it is open source hardware; so most of the programs and softwares are available on the internet. The development cost of Arduino it extremely small as compared with the other tech giant’s microcontrollers.
Its software files include the basic programs for a beginner in its source code libraries. A user can use them to make its project versatile and can further edit the program for improving its capabilities and it also possess strong online helping community platforms.
Following are the main features of Arduino UNO which we will use in our tutorials:
- 14 digital IO (6 can be PWM outputs)
- 32KB program memory
- 6 Analog Inputs (10 bit resolution)
- Interfacing port
Fig. 1: Arduino UNO Board
Why interfacing of Arduino is necessary with LabVIEW?
Ardunio is open source hardware board and it is very easy to perform complicated tasks with it. It not only has many built in features but also supports external devices. But it requires writing different lines of code which could be cumbersome. Here comes in the LabVIEW to rescue you. LabView uses graphical language and do not require writing lines of code. Instead we use graphical diagram to perform particular task. You can have a look at tutorial 1 for more details.
Interfacing of LabVIEW and Arduino combines both the simplicity of Aduino hardware board and the graphical language of LabVIEW. Now we do not need to write lines of code and also we do not need the other complex hardware boards.
Necessary softwares required for interfacing of LabVIEW and Arduino?
Here is the list of software you are required to install for interfacing of Arduino and LabVIEW. All software are free and easily available.
- Arduino IDE
- Visual Package Manger (You might already have it if you installed LabVIEW. If not download.)
- LabVIEW Interface for Arduino(Present in Visual Package Manger. Download and install it)
- NI-VISA Package
After installation test your installation using sample program at the “finish” dialogue box.
How to make a program Arduino with LabVIEW
In our program we will control an LED on real time hardware using a Push Button in LabVIEW.
- Start the LabVIEW.
- Creat Blank VI as in Tutorial 1.
- Go to “Block Diagram” Panel
- Right Click on white space. Go to “Arduino” and select “init”.
- Bring Cursor to anywhere in “Block Diagram” panel and place the “Init”.
- First input is “VISA resource”. It is the serial port you are using for interfacing of Adruino. You can find it in “device manager” of your computer under “ports (COM & LPT)….” Make sure Arduino board is connected with computer otherwise it won’t be shown. In my case it is COM4.
- Bring cursor on first input of “Init” until it shows “VISA resource”. Right click on it. Go to “create” and select “constant”. As it will be a constant value of Port which will be always used for serial communication.
- Click on arrow it will show available option. In my case its “COM4”. Select appropriate one after checking from device manger as mentioned above otherwise it won’t work.
- Second input is “Baud Rate”. Create it as constant as done for “VISA resource”. Right click on “Baud Rate” then “create” and then “constant”.
- Third input is “Board Type”, fourth is “Bytes per packet” and fifth is “Connection type” make them also constant.
- Click on white space on “Block Diagram” and follow “Arduino → Low Level → and select Set Digital Pin”
- Place “Set Digital Pin” on “Block Diagram” and join “Arduino resource” of both blocks. Create “digital I/O pin” as constant. And write 13 in it. It will be pin we will control. Make second input “Pin Mode” as constant and select output from drop down. It means pin will work as output pin. Join “error in” with “error out” of other block. If any error occurs in previous block, it will travel to next block. We will elaborate its purpose at end of article.
- This completes what we do in setup loop of Arduino program.
- Click on white space on “Block Diagram” and follow “Arduino → Low Level → and select Digital Write”. Place “Digital Writ ” on “Block Diagram”.
- Now next as we do in program; we place DigitalWrite function in void loop, we will do same here.
- Click on white space on “Block Diagram” and follow “Structure → select While loop”.
- Draw a rectangle on “Block Diagram” and click on red color round icon “loop condition”Create a constant by right clicking on it. I will show a “STOP” icon on diagram.
- Bring “Arduino Resources, Error Out and Pin 13” on rectangle.
- Connect “Resources with Resource”, “Error with Error” and “Digital IO with Pin13”.
- For creating “value” input go to Front Panel. Right click “silver → Boolean → Push Button” and Place it in Front Panel. It will also be shown in “Block Diagram” automatically.
- Bring the Boolean in while loop and find “Boolean to (0,1)” as follows.
- Place “Boolean to (0, 1)” in “Block Diagram” and connect as shown.
- Find “Close Block” as Follows.
- Connect Close Block as Follows.
- Now Start Ardunio IDE.
- Click “File” then “Open” and Follow as shown. Go through all these folders from “Computer” onward and open LIFA_BASE Arduino file.
- Upload the program opened using Arrow button on top of Arduino IDE.
- Once uploading done close the Arduino IDE. It’s very important to close it because both LabVIEW and Arduino are using COM4. If not closed LabVIEW will not be able to communicate and it will crash.
- Now go to Front Panel in LabVIEW and run the program.
- Once both the Tx and Rx lights are ON; on Arduino board press Boolean button on Front Panel. You will observe LED on board connected with pin 13 is ON when we press push button on LabVIEW once. Pressing Again send 0 so LED will be OFF.
In previous article of Getting Started with LabVIEW , we have seen about LabVIEW and how it can be graphically programmed and executed in computer (software level). Now in this article we learn about How to Interface LabVIEW with Arduino Board.
To interface LabVIEW with Arduino, you require the following software’s and hardware’s,
- LabVIEW (software)
- NI VISA (software)
- VI packet manager (software)
- Arduino IDE (software)
- LINX, (this will be available inside VI package manager, open VI package manager and search for it, double click on it. You will reach to an installation window. Click install button visible to you in that window.)
- LabVIEW Interface for Arduino, this will be available inside VI package manager, open VI package manager and search for it, double click on it. You will reach to an installation window. Click install button visible to you in that window, as shown below
Why we interface Arduino with LabVIEW?
As already told in previous article , LabVIEW is a graphical programming language. Arduino programme is made up of lines of codes but when we interface LabVIEW with Arduino, lines of codes are reduced into a pictorial program, which is easy to understand and execution time is reduced into half.
LED Blink with Arduino & LabVIEW
- Launch the LabVIEW.
- To launch LabVIEW refer previous article .
- Now start graphical coding.
- In Block diagram window, right click select Makerhub >> LINX >> Open, drag & drop the Open box. Then create a control by right clicking the first wire tip and selecting Create >> Control. Thus created a Serial port.
- In Block diagram window, right click and select Makerhub >> LINX >> Close. Drag & drop Close.
- In Block diagram window, right click and select Makerhub >> LINX >> Digital >>Write. Drag & drop Write. Then create a controls on second and third tip of wires by right clicking each individually and selecting Create >> Control. Thus created a D0 channel and Output Value.
- In Block diagram window, right click and select Structures >> While loop. Drag the While loop across the Digital write. Then create a Shift register by right clicking on the While loop.
- In Block diagram window, right click and select Makerhub >> LINX >> Utilities >> Loop rate. Drag & drop it inside the While loop.
- In Block diagram window, right click select Boolean >> or. Drag & drop or inside the While loop.
- In Block diagram window, right click and select Timing >> Wait(ms). Drag & drop Wait(ms) into the While loop and create a constant for it by right clicking on the wire tip which is left most to the Wait(ms) and select Create >> Constant.
- In Front panel window, right click and select Boolean >> Stop button. Now stop button appears in the Block diagram window. Drag & drop it inside the While loop.
- Now by connecting all these created blocks using wiring connections, you can build the Graphical LED blink program to interface with your Arduino hardware.
Connect the LabVIEW code with Arduino
- After building the graphical code, select Tools >> Makerhub >> LINX >> LINX Firmware wizard.
- Now LINX Firmware wizard window open’s, in that select Device Family as Arduino; Device type as Arduino Uno ; Firmware Upload Method as Serial/USB. Then click Next.
- Then connect the Arduino board to your PC using Arduino USB cable.
- Now in Next window select the Arduino port by clicking to the drop down list. Select COM4. Then click Next twice.
- Then click Finish button.
- Now you have setup the serial port and interfaced Arduino board with LabVIEW.
Run the Program
- Now select the Continuously Run Icon, then in the front panel window select the port and enter the digital pin.
- Then by switching the Output Value (which acts as an On & Off switch), you can see the in-built LED of the Arduino board blinking till the Output Value is turned Off .
Complete process is also explained in the video below.
- arduino uno
- LED blinking
JLCPCB Prototype: Only $2 for 10 pcs PCBs, 48 Hours Quick Turn
JLCPCB, with 300,000+ Customers Worldwide, 8,000+ PCB Orders Per Day.
Quote and Order boards in minutes on https://jlcpcb.com/quote
Log in or register to post Comment
TI Training Videos
Active Forum Topics
- why should //uint8_t, //uint16_t macro actually to be used !!
saj Replies: 2
- is the same effect in updation of Timer 0 resister
saj Replies: 3
- Question about relays
kangyunmei Replies: 1
Baiju Replies: 3
- Request To Make A Project On Obstacle Avoidance Drone
Habib Uddin Replies: 1
- EV Videos
- Flow Meter