Using Serial Communications in LabVIEW
LabVIEW offers the ability to communicate with most serial-based instruments and devices, including Arduino and Raspberry Pi.
Serial communication is a data transmission protocol in which information is sent in a series, one bit at a time. It is one of the oldest communication protocols in the computer industry, dating back to the 1960s when RS-232 was created.
For decades, RS-232 was one of the most widely used interfaces in personal computers, allowing the connection of keyboards, mice, and other peripherals to the main CPU. Today, RS-232 has been largely replaced by other faster and more energy-efficient protocols in the PC industry, such as the USB.
Despite this, RS-232 ports are still commonly used in industrial devices, such as laboratory equipment, variable-frequency drives (VFDs), networking equipment, embedded systems, and even PLCs.
Figure 1. Many modern oscilloscopes are equipped with RS-232 ports. Image used courtesy of Siglent
One of the main reasons for the interface’s longevity is its simplicity. Serial communication can be established with as little as two wires, making it suitable for microcontrollers and PCBs where the number of pins available is minimal. Although data transmission speeds are lower than most protocols, it is still an adequate solution for many of the aforementioned devices.
LabVIEW and Serial Communication
LabVIEW is a software platform that helps automate laboratory testing and other industrial processes utilizing Virtual Instruments (VIs), or computer-based tools. Naturally, LabVIEW offers the capability of interfacing with a large number of serial-based hardware instruments. Beyond RS-232, RS-422 and RS-485 standards are also supported.
To achieve this, LabVIEW uses an application programming interface (API), called NI-VISA (National Instruments – Virtual Instrument Software Architecture). NI-VISA is a driver, downloadable from NI, that provides a standard for integrating several different communication protocols, including serial RS-232/RS-485, Ethernet, USB, among others.
Setting Up RS-232 in LabVIEW
To begin the communication setup of a serial-based instrument with LabVIEW, the device must first be connected to the computer where the application is executed. Considering that personal computers equipped with serial ports can be hard to find nowadays, then to achieve this physical connection, USB-to-serial adapters can be used.
Figure 2. USB-to-serial (RS-232) adapters are needed to connect serial devices to personal computers. Image used courtesy of Adafruit
With the device connected and the NI-VISA driver installed, the NI-MAX tool can complete the configuration. Relevant serial protocol parameters, such as baud rate, data bits, parity, and flow control, are set up for the serial port ID where the instrument is connected. It is important to know these values from the instrument itself to successfully establish the communication.
Once the setup is completed, the newly added device becomes a VISA entity that can be added into the block diagram in LabVIEW. From there, functions such as serial port open, close, read, and write can be programmed on the VISA entity, which gets executed on the connected instrument.
Figure 3. Setup of a new RS-232 instrument using the NI-MAX tool. Image used courtesy of National Instruments
RS-485 and Modbus in LabVIEW
Another popular serial communication protocol is RS-485, also known as TIA-485 or EIA-485. This method is used in many industrial automation systems to interconnect robots and motor drives to a central controller.
RS-485 interfaces are preferred in systems with considerable electrical noise and is the underlying physical layer used with other protocols, such as Modbus. For example, Modbus is widely used in SCADA systems (Supervisory Control and Data Acquisition) and many PLC applications with sensors and other field devices.
Figure 4. An example of a SCADA created in LabVIEW. Image used courtesy of National Instruments
LabVIEW offers the Modbus API to facilitate the integration with Modbus systems. The API allows the creation of server/client systems for sending control messages to connected devices. Information requests, or polling, is also available in the I/O configuration. With this API, a fully functional SCADA can be created in the front panel of the application.
LabVIEW Integration with Raspberry Pi and Arduino
Raspberry Pi and Arduino are two of the most popular programmable boards in academia and maker (“do-it-yourself”) electronics projects.
Arduino boards consist of an Atmel 8-bit microcontroller and several other features, such as pins and memory. One of the most recognized models is the Arduino UNO.
On the other hand, Raspberry Pi contains a microprocessor, technically a very compact computer. As such, many of the standard desktop peripherals can be connected to it. Both boards can be integrated into a LabVIEW project.
Arduino in LabVIEW
With the LabVIEW Interface for Arduino Toolkit, programmers can incorporate the Arduino board and create useful graphical user interfaces (GUI) for their application in the front panel of LabVIEW. To do this, the toolkit first uploads a template program into the Arduino board to establish connection and allow commands from LabVIEW.
Since the protocol is serial, the NI-VISA driver is used to set up the communication parameters. The code can then be programmed in the block diagram format of the G language, and a GUI can be developed in the front panel.
Raspberry Pi in LabVIEW
Similarly, to create projects in LabVIEW using a Raspberry Pi board, an additional toolkit is needed. In this case, the Raspberry Pi Compiler for LabVIEW helps develop code in the G language, which can then be deployed and executed from a Raspberry Pi board.
More recently, the LabVIEW LINX add-on was released, which provides a centralized and standardized platform for creating projects in LabVIEW using many different embedded systems, including Arduino and Raspberry Pi. However, LINX is only compatible with LabVIEW 2020 and newer versions.
LabVIEW has the capability to use multiple types of serial communication, which is still often used in industrial equipment. To name a few, there are RS-232, RS-485, Modbus, Arduino, and Raspberry Pi. Do you use these communications for LabVIEW, or do you use another?