MAKE-ing with LabVIEW - Part Three

MAKE-ing with LabVIEW & Raspberry Pi: Part 3 – Raspberry Pi Setup

In Part 3 of this series on using the Raspberry Pi with LabVIEW I will be configuring a Pi 3 B and installing the LINX Toolkit on it. I will also cover some handy hints & tips when setting up the Raspberry Pi.

Introduction

This guide is based on the official set up guide from the Raspberry Pi foundation – found here.

We’ll be setting up the Pi with the latest Raspbian OS package downloaded from the official Pi website and then installing the LabVIEW Run-time.

The Raspberry Pi website offers Raspbian and NOOBS – NOOBS is an easy way to download and try out different OSes for it but it takes up more space on your SD card and may prevent things like configuring it to run headlessly (without a display). I also expect that only Raspbian is supported by the LINX Toolkit.

Prerequisites:

For the initial setup, you’re going to need the following:

Equipment required to configure a Raspberry Pi.
Time to gather your tools to harvest the Raspberry Pi!
  • Raspberry Pi: The LINX Toolkit officially supports the Pi 2/3 but I will provide an update or a separate post on other targets such as the new Pi 4 and the Pi Zero W.
  • Power Supply: For the Pi 2/3 you need a MicroUSB with an output of at least 2.5A and 3.0A USB-C for the Pi 4.
  • >=8GB microSD card: You can use a blank/formatted card or you can buy microSD cards with NOOBS (the Raspberry Pi OS launcher) preinstalled. The SD card will be the disk drive of your Raspberry Pi so will contain the OS and all of your programs/files – it’s worth getting a decent Class 10 SD card or above.
  • SD Card Reader: You’ll need to format & install the OS image using another computer with an SD card reader. You might also need a microSD to SD adapter.
  • Screen and Keyboard/Mouse: Recommended for the initial setup but read the hints & tips at the bottom of the post to learn how you can set up the Raspberry Pi without these and use SSH and/or VNC to access the Pi remotely.
  • Ethernet Cable / WiFi Credentials: To install the LINX Toolkit / LabVIEW Runtime to the Raspberry Pi it will need to be connected to the internet (to download the LabVIEW Runtime) and be on the same network as your LabVIEW 2019 installation (to configure/setup the Raspberry Pi and to deploy code to it).

Of course, you’ll also need your laptop/PC with LabVIEW 2019 and the LINX Toolkit installed – as discussed in Part 2.

How to: Set up a Raspberry Pi for LabVIEW

  1. Download the Raspbian OS

    Go to the download page for the Raspbian OS and download the latest Desktop edition (at the time of writing that is Raspbian Buster). There are three editions of the OS available:
    Desktop: The main OS installation that includes a GUI desktop. The GUI can be turned off to improve performance later.
    Desktop and recommended software: As per the ‘Desktop’ download but includes additional preinstalled applications (e.g. for education/programming purposes) – find out more about what’s included here.
    Lite: This is a minimal OS installation without any desktop functionality – you have to use the command-line interface. You can install the desktop support later if you want.Raspbian Download Options

  2. Install the OS to the microSD card

    The easiest way to prepare the SD card for your Raspberry Pi is to use balenaEtcher – a multi-platform GUI tool that can format and install the Raspbian OS image to the SD card. Alternatively you can use Win32DiskImager. Note that this will format/wipe the SD card.
    – Download and install balenaEtcher from here. It will automatically open.
    – Select the Raspbian OS image file you downloaded in the previous step (you don’t need to extract the .zip file).
    – Select the correct drive for your SD card.
    – Click ‘Flash!’ to begin. The process will take around 5-10 minutes.
    The instructions for writing the image to the SD card can also be found here.Install OS image using balenaEtcher

  3. Connect your Raspberry Pi

    Now you have your SD card prepared, you can install it and connect everything up.
    – Install your SD card to the underside of the Raspberry Pi
    – Connect your mouse/keyboard to the USB ports
    – Connect your display(s) to the HDMI port(s)
    – (Optional) Connect an ethernet cable from your Raspberry Pi to your network / router

  4. Turn on the Raspberry Pi

    Connect the power supply to the Raspberry Pi. You should see a red LED on the Raspberry Pi board and after a few moments you should see raspberries on the display and the Raspberry Pi will boot to the desktop.

  5. Configure the OS

    When it has finished booting, a wizard will appear to allow you configure the basic settings on the Raspberry Pi like the language, timezone and WiFi settings (if present).
    – Firstly, enter your country, language and timezone.
    – On the second screen you can enter a new password for the ‘pi’ user account and make a note of it – you’ll need it.
    – Thirdly, if your Pi has onboard WiFi (e.g. a Pi 3, 4 or Zero W) then you can connect to it now
    – Lastly you can check for updates to the OS and applications. The wizard will then prompt you to reboot the Pi if required.
    Raspberry Pi Setup Wizard

  6. Hooray!

    If you made it this far – congratulations, you now have fully functioning Raspberry Pi computer!

    If you ran into any issues – check out the official troubleshooting guide or the Raspberry Pi help forums.

  7. Enable SSH

    SSH allows you to remotely access a command-line prompt on the Raspberry Pi. This allows you to enter linux commands to access/control the Raspberry Pi. It’s also required by the LINX Toolkit to install the LabVIEW run-time and deploy projects to the Pi.

    In newer versions of Raspbian it is disabled by default (to protect against hackers).

    Open the Raspberry Pi Configuration utility from the ‘Preferences’ menu, open the ‘Interfaces’ tab, click ‘Enable’ next to SSH and then click OK.

  8. (Optional) Enable GPIO Hardware Peripherals (SPI/I2C/Serial)

    The GPIO pins on the Raspberry Pi support a number of protocols/interfaces but they need to be enabled so they can be used from the LINX Toolkit. You can enable these peripherals from the Raspberry Pi Configuration screen as shown above.

    If enabling the Serial Port interface, make sure that Serial Console is disabled so that the port is accessible in LabVIEW.

    At the time of writing, the LINX Toolkit supports I2C on pins 3&5, Serial on pins 8&10 and SPI on pins 19,21&23. See the pinout here for more information.

    Note: All of the GPIO pins are 3.3V – directly connecting any signal >3.3V will likely damage the GPIO functionality of the Raspberry Pi.

  9. Install the LINX Toolkit / LabVIEW Run-time (Method 1: Wizard)

    Note: The first beta version of the LINX Toolkit had a number of bugs that mean the installation fails – either apply the fixes at the bottom of the post first and come back here or try the Manual method below.

    Update 10/10/2019: NI have updated the LINX Toolkit to Beta 2 which fixes using the Wizard to deploy the LabVIEW Run-time to the Raspberry Pi and adds official support for the Raspberry Pi 4. I have updated the article reflect this.

    – Open the Target Configuration Wizard from ‘Tools -> MakerHub -> LINX -> LINX Target Configuration…”

    – Enter the hostname/IP, username and password for the Raspberry Pi and click ‘Connect’

    – Click the ‘Install Software’ button and then click ‘Install’ – this will perform the required configuration on the Raspberry Pi and install the LabVIEW run-time. This will take a few minutes.


    After the installation is complete, the ‘Installed Version’ should show something like 19.X.X (for me at the time of writing it is 19.0.1-2).

  10. Install the LINX Toolkit / LabVIEW Run-time (Method 2: Manual)

    The manual installation method is to use a terminal or SSH session on the Raspberry Pi and run the following commands:
    echo "deb [trusted=yes] http://feeds.labviewmakerhub.com/debian/ binary/" | sudo tee -a /etc/apt/sources.list
    sudo apt-get update
    sudo apt-get install lvrt19-schroot -y


    The first line you only need to run once to set up the LINX Toolkit repository on the Raspberry Pi. The 2nd and 3rd lines retrieve the latest package versions from the repository and then install the ‘lvrt19-schroot’ package which has the LabVIEW Run-time.

  11. Run the Example Project

    If everything has gone smoothly so far you should now have the LabVIEW Run-Time installed on your Raspberry Pi.

    You can test it out by pressing the ‘Launch Example’ button from the Wizard which will generate a example project and configure the IP address of your Pi for you.

    If the ‘Launch Example’ button doesn’t work, you can copy the template project from C:\Program Files (x86)\National Instruments\LabVIEW 2019\vi.lib\MakerHub\LINX\Private\Templates\Raspberry Pi 2 B to another folder, open the project and change the IP address to match your Pi and then run it. To do this, right click on the Raspberry Pi target in the project and go to ‘Properties’, then update the IP Address field and click OK.

    You can then ‘Run’ the VI, the code will be deployed to the Raspberry Pi and if you have an LED to hand you should be able to toggle it by connecting it to the correct GPIO pin.

  12. Congratulations!

    That’s it! You’ve now configured a new/blank Raspberry Pi with the latest Raspbian OS image, configured it for remote access, installed the LINX LabVIEW Run-time and run the sample/template project.

Hints & Tips

Remote Access – VNC

Once you have done the initial setup of the Pi and it is connected to your network, you might not want to keep a display/mouse/keyboard attached to it. The solution is to enable VNC – it’s the Raspberry Pi equivalent to remote desktop and allows you to view and control the Raspberry Pi remotely.

The first step is to enable the VNC server on the Raspberry Pi using the configuration tool (or via sudo raspi-config). You will then need to install the VNC Viewer which you can download from here.

Once installed, you can enter the hostname/IP address of your Raspberry Pi and then connect using the same username/password as SSH.

Accessing the Raspberry Pi via VNC

Headless Raspberry Pi (no display)

If you don’t have a mouse/keyboard/screen available for the initial setup, you can still setup and configure your Pi over the network.

You can do this by modifying the contents of the ‘boot’ partition of the SD Card on your computer after you have written the Raspbian OS image to it.

WiFi

If you need to use the Pi over WiFi, you can confgure the WiFi credentials by creating a file called wpa_supplicant.conf in the ‘boot’ partition of the SD card. Its contents will then be copied over to the Raspberry Pi when it boots up.

The file needs to look like this:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=«your_ISO-3166-1_two-letter_country_code»

network={
    ssid="«your_SSID»"
    psk="«your_PSK»"
    key_mgmt=WPA-PSK
}

You will need to fill in the country code, SSID and pre-shared key. Ensure that the file has Linux line endings (LF or ‘\n’ instead of CRLF ‘\r\n’).

SSH

Create/copy a file called ‘ssh.txt’ (case-sensitive) onto the ‘boot’ partition of the SSD card. The contents of the file doesn’t matter.

Enabling SSH on the Raspberry Pi via the SD Card
Enabling SSH via the SD card boot partition

Other Configuration Options

After setting up the WiFi and enabling SSH, you should be able to boot up and then SSH into the Pi. You can try connecting to the default hostname ‘raspberrypi’ or check your router/network settings to find its IP address.

Once you have connected via SSH, you can run sudo raspi-config to access a terminal-based configuration editor which allows you to change all of the settings of the Pi as per the initial setup etc.

Raspberry Pi terminal configuration utility.
Raspberry Pi Configuration from the terminal (looks pretty oldschool!)

Controlling the LabVIEW Run-time

The LabVIEW Run-time runs as a service on the Pi, to start/stop/restart it you can use the following terminal commands:

sudo systemctl [stop|start|restart] labview.service

This can be useful in case you want to ‘reboot’ LabVIEW without restarting the Pi. Note that this will abort any currently running LabVIEW VIs that are running on the target.

Fixing the LINX Toolkit Beta

Update 10/10/2019: The LINX Toolkit has now been updated to Beta 2 on the NI Software Technology Preview – the fixes below are no longer necessary to install the LabVIEW Run-time to the Raspberry Pi. This update potentially breaks the ability to create Real-Time Applications (rtexe) in LabVIEW 2019 – performing a repair on LabVIEW Real-Time from NI Package Manager fixed this for me.

At the time of writing the LINX Toolkit Beta is just a copy of the 2014 version of the Toolkit. It has not been updated or fixed to work with LabVIEW 2019 and newer Pi Targets.

Fortunately I have been able to resolve most of the issues to get the Wizard working to install the Toolkit and launch the examples. This requires changes to some of the VIs to update it for the new LabVIEW Run-time for the Pi.

Most of the VIs are located in C:\Program Files (x86)\National Instruments\LabVIEW 2019\vi.lib\MakerHub\LINX\

Remove LabVIEW 2014 Prompt

Open LMH-Linx.lvlib:System Check.vi and change the string in the case structure from “2014” to “2019”. This will remove the dialog that appears when opening the dialog that you’re using the wrong version of LabVIEW.

Remove LabVIEW 2014 check from LINX Toolkit
Remove LabVIEW 2014 prompt from LINX Toolkit in System Check.vi

Update for 2019 LabVIEW Run-time

Open LMH-LINX.lvlib:Install LV Support.vi and change the package name to ‘lvrt19-schroot’:

Updates to the Install LV Support VI.
Update the ‘Install LV Support’ VI

Open LMH-LINX.lvlib:Add MakerHub Feed.vi and modify as follows:

Updates to the Add MakerHub Feed VI.
Update the ‘Add MakerHub Feed’ VI

Open LMH-LINX.lvlib:Check Target LV Package Version.vi and change the package name to ‘lvrt19-schroot’:

Modifications to the Check Target LV p
Package Version VI.
Update the ‘Check Target LV Package Version’ VI

Note: It will still show the latest version as the LV2014 version but it doesn’t affect the installation

Add Raspberry Pi 3 (& 4?) Support

The library detects the target type according to the CPU name retrieved from the cat /proc/cpuinfo command. This is different for the Raspberry Pi 3 (and also the Pi 4 and maybe the Pi Zero etc.).

To add support in the Wizard for new targets we need to do the following:

  1. Determine the CPU type on the Raspberry Pi by running cat /proc/cpuinfo in a terminal or via SSH. At the end of the output it will show a line saying something like Hardware: BCM2835. This is the CPU type used by the LINX Toolkit wizard.
  2. Open LMH-LINX.lvlib:Get Device Type.vi and add a new entry for the Raspberry Pi you are using (e.g. 3/4):
  3. To fix the ‘Launch Example’ button in the Wizard, we also need to modify it to use the Raspberry Pi 2 B example files. Open LMH-LINX.lvlib:Script Example Project.vi and modify as follows:

If you want to look into the LINX Target Configuration VI, you can open it from the Tools menu and then press ‘Ctrl+.’ to abort the VI. You can then look through its block diagram. Be aware that any changes you make might be overwritten by a new version of the Toolkit. Feel free to leave a comment if you’ve made any other useful changes!

Conclusion

This has been quite a long post, but we’ve now covered everything required to setup a Pi for use with LabVIEW. I’ve also provided fixes for the current Beta version of the LINX Toolkit so you can use the Wizard to install the LabVIEW Run-time and provided some hints & tips for remotely accessing the Raspberry Pi and for setting up the Pi without a mouse/keyboard/screen attached.

In the next post, I’ll go into some details about some of the on-board communications methods on the Raspberry Pi. I will cover network communications and serial ports. Tune in next time!

4 replies
  1. toshas
    toshas says:

    Hi!

    Many thanks for such detailed guide!
    Do you have any ideas what is wrong with WebServices ?
    Previously it worked fine (with 2014 LINX) but now (with beta) deployment error is exist during webserver start:

    Initializing…
    Calculating dependencies…
    Checking items for conflicts. This operation could take a while…
    Preparing items for download. This operation could take a while…
    Deploying Raspberry Pi 2 B(successfully deployed target settings)
    Deploying WebServer
    Failed to start the debug web server on the target. Check the target properties and ensure the configured port is not in use and that the Web Services Runtime component is installed.
    Deployment completed with errors

    Looks like something was changed in WebServices deployment too.

    Thanks!

    Reply
    • Sam
      Sam says:

      To be completely honest, I don’t think I ever tried LabVIEW Web Services on the Raspberry Pi. I suggest you provide feedback on the Software Technology Preview forums and see what they say.

      Reply
  2. Alan Thao
    Alan Thao says:

    Hi Sam,

    I read everything you posted on this subject and tried your tutorials and love what you are doing, which help people like myself; a hobbyist without the money, but love labview and RPI. Please keep the world posted as thousands of us are waiting for Labview to make this happen. Since I’m only using the 30 day version and unable to get an beta toolkit since I do not have a license, is there any way I can get it please? Thanks in advance.

    Reply
    • Sam
      Sam says:

      Thanks for the kind words – I should be publishing the next post in the next few days so keep a look out for that 🙂

      You should be able to extend your LabVIEW evaluation/trial to 90 days. I have been told you should be able to sign up to the LINX Toolkit Beta without entering a license/serial number on the registration page – the LabVIEW Community Edition beta is not live in the Software Technology Preview yet though so you’d need to work with the evaluation version of LabVIEW.

      Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.