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
Table of Contents
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.
- 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”.
- 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.
- 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.
- 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.