« Close

Datasheets and User Guides

App Notes

Software & Driver

 

T7, Raspberry Pi 3, Cloud9 (App Note)

Raspberry Pi 3, LCD Screen, and LabJack T7
Intro
This is a simple application note documenting how to get started using a Raspberry Pi 3 single board computer to control a LabJack T7/T7-Pro multifunction data acquisition and control device. One of the best development environments that we have seen for developing applications on a single board computer is to use the Cloud9 IDE. This development environment idea comes from the use of a BeagleBone Black.

If this long single-page tutorial seems daunting, take a look at the this tutorial published through Versal, an online classroom/learning tool, the class title is Getting Started LabJack T7, Raspberry Pi, Cloud9.

Prior Knowledge
  1. A Raspberry Pi 3 that has Raspbian installed. The Pi Foundation has a guide titled Installing Raspbian with Noobs that is easy to follow.
  2. Basic command line/Linux terminal skills:
  3. Basic computer skills (connecting keyboard, mouse, turning on Raspberry Pi)

Recommended Hardware
  1. LabJack T7
  2. Raspberry Pi 3
  3. Raspberry Pi LCD Display
Raspberry Pi 3, LCD Screen, and LabJack T7
An Amazon shopping list containing these parts and a few other useful cables: Raspberry Pi 3 & LabJack T7 DevKit.

Goals
  1. Update Raspberry Pi
  2. Install NodeJS
  3. Install Cloud9 IDE
  4. Install LabJack LJM Driver
  5. Install and Run LJM Python Examples

Initial Suggestions
When you start a new "Terminal" the default starting directory is "/home/pi". In this directory there are a few already existing files and folders such as "Desktop", "Downloads", "Documents", etc. This guide recommends you to create a folder called "git" in this directory via the command: "mkdir git". Things that you need to download via wget should go in the "Downloads" directory, and things that are cloned via git should go in the "git" directory. This is just a directory structure suggestion, it is not required.

You should connect your computer, raspberry pi, and potentially your T7 to the same network. It is always preferable to connect devices to the internet via an ethernet connection, however a WiFi connection will usually work just fine.

Update Raspberry Pi
It is always good to keep your system up to date. This can sometimes break things, so only do this if you aren't on a mission critical system.
$ sudo apt-get update && sudo apt-get upgrade

Install NodeJS
The Cloud9 IDE requires that Node.js be installed on your system. One source (#1) recommended Node.js v0.10.28, however Node.js has been releasing native ARMv7 builds for node starting in version ~4 so this guide recommends v4 or higher. The latest versions of Node.js can be found on their current downloads page. The following instructions are from source #3.
$ tar -xvf node-v6.6.0-linux-armv7l.tar.gz
$ cd node-v6.6.0-linux-armv7l
$ sudo cp -R * /usr/local/
$ export NODE_PATH="/usr/local/lib/node_modules"

You can check to make sure you completed this step by typing the commands:
$ node -v
v6.6.0
$ printenv NODE_PATH
/usr/local/lib/node_modules

Install the latest Cloud9 SDK
Clone the official GitHub Repo for the Cloud9 SDK: https://github.com/c9/core and follow the suggested method of installing:
$ git clone git://github.com/c9/core.git c9sdk
$ cd c9sdk
$ scripts/install-sdk.sh
After several minutes (time is dependent on several factors) you should see a screen emit an "All OK" message. Both the download ("git clone") and install ("scripts/install-sdk.sh") steps may take a long time to run. As of 9/19/2016, the install step looked like it had frozen after outputting something like ~"prebuilt binaries not found...", the install step is actually downloading and installing stuff. When the installation finishes, you may also see a message with instructions on how to start a Cloud9 IDE instance.
$ node server.js -p 8080 -a :

To initialize a Cloud9 IDE instance with remote-connections enabled:
$ node server.js -w /home/pi -l 0.0.0.0 -p 8080 -a :

Test Cloud9 SDK
Start the Cloud9 IDE and write down the IP address/URL that it is listening at, ex: "http://192.168.1.102:8080". On a computer connected to the same network, use Google Chrome or another web-browser to navigate to the appropriate URL. The first time you navigate to the URL the page will take a long time to load because the Cloud9 IDE has to initialize the development environment. Subsequent starts will happen faster.

(Optional) Make a Cloud9 IDE local-app
Google Chrome has a very convenient feature that lets you save a webpage as a local application and run it in "desktop" mode. While you are on the Cloud9 IDE web page, go to "Settings->More tools->Add to desktop....". Re-name the page and make sure the "Open as window" checkbox is selected. A new icon should get generated on your desktop and when you open the shortcut it will show up as an new application without any of the Google Chrome browser features. You can also use applications like NW.js and GitHub's Electron to do this and avoid using Google Chrome.

(Optional) Auto-Start Cloud9 IDE
It may make sense for you to enable the Cloud9 IDE to start when the Raspberry Pi gets turned on. The article titled "Using forever (NodeJS) with Cloud9 IDE" (Source 4) provides some information about how to do this. (see below)
sudo npm install -g forever

Create a file /forever/development.json as documented by the forever GitHub repository. An example file looks like the following:
{
// Comments are supported
"uid": "app",
"append": true,
"watch": true,
"script": "server.js",
"sourceDir": "/home/pi/c9sdk",
"args": ["-w","/home/pi", "-l", "0.0.0.0", "-p", "8080", "-a", ":"]
}

Execute the forever start command:
sudo forever start ./forever/development.json

Testing:
sudo shutdown -r now

Run the command:
forever -m 5 ./c9sdk/server.js -w /home/pi -l 0.0.0.0 -p 8080 -a :


Edit the computer's "crontab" file.
follow the instructions on the Stack Overflow page describing how to automatically-start-forever-node-on-system-reboot.
crontab -u $USER -e
(or crontab -u pi -e)

Edit the file so that the last line of text is:
@reboot /usr/local/bin/forever start -c /usr/local/bin/node /home/pi//c9sdk/server.js -w /home/pi -l 0.0.0.0 -p 8080 -m 5 -a :

Exit and save the file. Type the shut-down command to see if the process was successfully added!


Tutorial Check-Point
The Cloud9 IDE provides you with remote terminal access to the Raspberry Pi, so the rest of this tutorial can be completed using the Cloud9 terminal. Simply navigate to the URL in a web browser, or use the local-app that was created.

Install the latest LJM Library
Navigate to the LJM Downloads page to download and install the latest armhf Linux driver for the Raspberry Pi.
$ tar -xvf LabJackM-1.1200-Raspbian-Linux-armhf-beta.tar.gz
$ cd LabJackM-1.1200-Raspbian-Linux-armhf-beta.tar.gz
$ sudo ./LabJackM.run

Build the LJM Examples
Included in the .tar.gz file are a large number of C examples for communicating with and controlling a LabJack device. We have created a few scripts that make them easy to build and then executed for testing purposes. From within the LabJackM-x directory, navigate to the /LabJackM directory and read the "README" file. At around line 83 there are instructions for compiling the example programs. The Raspberry Pi (Raspbian) should already have a version of Python installed. If you are unsure you can type "python --version" to get the installed version of Python.
$ cd examples
$ ./make_all.sh
** For this tutorial, run the command "./make_all.sh" instead of "./make.sh"

Connect a T7 and Run the "list_all" example
After building the LJM examples, connect a T7 to your Raspberry Pi via USB and navigate to the "utilities" directory and run the "list_all" example to scan for LabJack devices.
$ cd utilities
$ ./list_all

After running the output text of the "./list_all" program should indicate that you have connected one device via USB to the Raspberry Pi. These last two steps indicate that the LJM Library has been properly installed and you can now use other LabJack examples on your Pi.

Downloading and running Python Examples
The latest version of the LabJack LJM Python examples can be found on the Python LJM Examples page. They can be downloaded by running the command:

After downloading, you can extract the .zip file using the "unzip" command (Source 6):
$ unzip Python_LJM_2015_12_03_0.zip

After un-zipping, you should navigate into the created "Python_LJM" folder using the Cloud9 IDE to open the README.TXT file where you will find instructions for how to install the Python library (~line 23). This is a common process among many Python libraries that are not hosted by Python package managers such as pip.
$ sudo python setup.py install

You can then verify that the Python examples have been properly installed by following lines 39-41 of the readme file:
$ python
>>> import labjack.ljm
>>> help(labjack.ljm.ljm)

After verifying that the examples have been installed properly, you should navigate into the Examples/List_All directory and run the list_all.py example file which should list the LabJack devices currently connected to your Raspberry Pi:
$ python list_all.py

Alternate instructions for the U3/U6/UE9
Instead of following instructions relating to the LJM driver, follow the in-depth Linux Build instructions for the UD driver. There are also some instructions on the exodriver installer page. When trying to install the libusb-1.0 library from source and the "./configure" command is failing, it may be required to install the libudev-dev package "sudo apt-get install libudev-dev". The last three steps in the in depth build instructions section show how to get started using the python library for the U3/U6/UE9 devices. For more details, go to the LabJackPython examples page.

Sources
  1. Medium, 9/19/2016: Using Cloud9 3.0 IDE on Raspberry Pi
  2. Stack Overflow, 9/19/2016: How to install cloud9 IDE on Ubuntu Server
  3. Wia, 9/19/2016: Installing Node.js on a Raspberry Pi 3
  4. Medium, 9/19/2016: Using forever (NodeJS) with Cloud9 IDE
  5. Raspberry Pi, 9/21/2016: Installing Raspbian with Noobs
  6. Stack Exchange, 9/21/2016: How to unzip a zip file from the Terminal?
  7. Stack Overflow, 9/21/2016: Automatically start forever node on system restart