From the book, O’Reilly’s Distributed Network Data by Bradford and Allan, see the XBee blog for more details, the final chapter deals with using an Arduino with LabView. However the final example, which graphs Arduino sensor data within LabVIEW, uses an example .vi file called Basic Serial Write and Read. However, this example file no longer exists in LabVIEW 2013, and instead a more complex example Continuous Serial Write and Read is provided. This makes learning the graphical programming style somewhat more difficult. However, the original Basic Serial Write and Read .vi file may be found on the NI web site, on the example page, Serial Communication – Basic Serial Write and Read.
NOTE: The image above differs slightly, with an included delay, from the image at the top of the page, which is from Instrument Control in LabVIEW Tutorial.
The modification required, for the book example, to continuously read from the Arduino:
- The Instr block : VISA Bytes at Serial Port (Instrument I/O>VISA>VISA Advanced>Bus/Interface Specific>Serial>Bytes at Port)
Owning Palette: Serial VIs and Functions
Requires: Base Package
Returns the number of bytes in the input buffer of the specified serial port.
The Number of Bytes at Serial Port property specifies the number of bytes currently available at the serial port used by this session.
Visa Bytes at Serial Port is a Property Node with a VISA class of Instr.
- The Waveform Graph is a control that needs to be added to the Front Panel, not the BlockDiagram, else you will never find it:
Now we can modify…
Source: Page 148
- The “Add new data to the array” block
appears to be a “Insert into Array” in LabVIEW 2013, see How to store values in array inside loop? Leave the index disconnected (see how to append array elements without overwriting?). However, it is more correctly a “Build Array” element, and it constructed thusly:
- Drag on a Build Array element, which is a single line;
- Right click on the input and select Concatenate inputs, and finally;
- Right click again on the input and select Add input.
The three stages are shown here:
This was a helpful link in discovering this: Add an element(cluster) to an array of cluster.
- Matching the type, for the connection of the Array initialiser, through the Shift Register and out to the Waveform Graph is somewhat fussy.
- bytes to read needs to change to bytes read and right click and change the type to Indicator, rather than an Constant – this will remove the tunnel direction issue
- The array constant requires a numeric constant to be placed within it
- The output tunnel of the inner loop will be outlined in blue, rather than solid blue. This is because the False case is not connected. With the inner loop set to false (the contents of the inner loop will disappear – no need to panic), just connect the input and output tunnels together. NOTE: Do not use the Set to Default suggestion of the output tunnel of the inner loop.
Now the diagram should be complete. However, upon running you may receive the following error:
Error -1073807202 occurred at Property Node (arg 1) in VISA Configure Serial Port (Instr).vi->Arduino_serial_write_and_read.vi
LabVIEW: (Hex 0xBFFF009E) VISA or a code library required by VISA could not be located or loaded. This is usually due to a required driver not being installed on the system.
The solution, from A code library required by VISA could not be located or loaded, suggests that VISA may not be installed. Sure enough, upon opening NI MAX, nothing was listed under Devices and Interfaces.
VISA is the Virtual Instrument Software Architecture, and can be downloaded from the VISA downloads (you are required to create a login). Download and run NIVISA1501full_downloader.exe – this will run a downloader application to download 636MB of NI-VISA (NIVISA1501full.exe). Running this .exe will then cause an unzipping and then the dreadful NI installer will open for yet another tedious and monotonous install process to ensue (seriously… what freakin’ moron, or committee thereof, designed and developed this application’s architecture?!? It takes longer than Windows, to install fully).
This should fix the errors and the .vi file will run correctly:
If you can’t be bothered to effect all of the changes yourself, then you can download the updated .vi file here, which I have had to text encode and rename, Arduino_serial_write_and_read.vi.txt
NOTE: To use this file, after downloading, remove the .pdf file extension, which was used only to allow WordPress to update the file. Then you must undo the text encoding, with the command:
certutil -decode Arduino_serial_write_and_read.vi.txtArduino_serial_write_and_read.vi
This Upgrade and Compatibility Issues page could be useful for differences between olders and newer versions of LabVIEW.