In this post, I will try to describe an approach of LabVIEW/Arduino communication using Modbus protocol. The motivation is to read temperatures from multiple Ds18b20 temperature sensors, however be able to modify easily the code to control relays, read analog inputs etc. I like Ds18b20 sensors from several reason: sufficient accuracy and time constant for many applications, Onewire bus (for one Pt100 or thermocouple is needed a dedicated channel or multiplexer) and good price.
- Labview Modbus Serial Example Reference
- Labview Modbus Rtu Example
- Labview Modbus Serial Example Java
- Labview Modbus Serial Example Key
- Labview Modbus Serial Example Pdf
The easiest approach from the point of view of Arduino programming is usage of Serial monitor and read the data with LabVIEW VI Visa node, since Arduino/Ds18b20 measurement is well documented. A tutorial on the topic of LabVIEW/Arduino data transfer through serial is published on Instructables [1]. I experiences some issues with reading data from serial monitor, LabVIEW sometimes read a blank row and I had to add some buffer and data filter and the VI started to expand to a messy mixture of nodes.
Labview Modbus Serial Example Reference
Second approach can be based on LabVIEW plugin LINX [2]. With LINX you can very simply read or write values on digital or analog pins. LINX add-on allows you also to include Arduino libraries using Custom commands, but I found this approach quit complicated even though reading data from Ds18b20 was discussed in this post [3], where is also example of the LabVIEW VI.
- For example, a register name defined as 2 in a MODBUS configuration device translates to register address 1 in the Holding Registers table of the LabVIEW MODBUS library, as shown below. MODBUS Device Holding Register Name = 2 LabVIEW Holding Register Address = 1 Quantity represents how many discrete inputs to read from the slave.
- RS485 is a serial transmission standard, a little bit like RS232, but using other electric signals. An important advantage of RS485 is that you can put several RS485 devices on the same bus. Therefore, you don't have to multiply RS485 interfaces on the host to question several devices.
Labview Modbus Rtu Example
The original Modbus Protocol specification, published in 1979, describes Serial Communications where data is transmitted one bit at a time. A later update to the standard, called Modbus TCP, describes how to use Modbus in TCP/IP networks. The rest of this article describes the Modbus protocol is more detail: Modbus Data Types.
After some experiments with mentioned approaches, I have started to test the communication via serial protocol called Modbus. Modbus is a serial communications protocol originally published by Modicon in 1979 for use with its programmable logic controllers (PLCs). The data can be transferred through serial lines RS-485, RS-232-C, RS-422, etc with Modbus RTU or via ethernet using Modbus TCP, but there are several other versions. On Arduino, the USB port can be used for data transfer with Modbus RTU. Modbus devices can be master or slave and on one line can be up to 32 slaves. The data stream is controlled by master device, but the information can be transferred both ways: from slave to master or from master to slave.
There can be found several Modbus libraries for Arduino and I selected this one [4]. After installling the library to Arduino IDE, the library can be imported to a new sketch by following code
I will demonstrate the use of modbus library for reading temperature from 3 Ds18b20 sensors. I have them connected to pin 4. To be able to read the data from the sensors, two another libraries is necesseary to import
Full code
Labview Modbus Serial Example Java
Labview Modbus Serial Example Key
LabVIEW side:
Labview Modbus Serial Example Pdf
I am using Modbus API library [5], possible to install via VI Package Manager. Reading data from Arduino through USB is then pretty simple, only two blocks are necessary: Create Serial Master and Read Holding Registers. Full LabVIEW code is in following image.
References
Note: Since free WordPress.com version does not allow you to install plugins, I used online code highlitghter hilite.me.