Standalone Data Logging System with LabJackT4 and Raspberry Pi (App Note) | LabJack
 

Free Shipping for U.S. Orders $150+   |   5-year Warranty   |   Try Our Devices & Support for 60 Days, Risk Free  |   51 of 54 Products In-Stock Now

Standalone Data Logging System with LabJackT4 and Raspberry Pi (App Note)

This is a simple application note explaining how to start logging data from a Labjack T4 onto a Raspberry Pi. We often have customers ask us how to perform simple standalone data logging and while you can do this using the Lua scripting features of the T-Series devices(T8, T7, T4); LabJack devices are the most powerful and deliver the best user experience when connected to a computer. Typically a customer interested in standalone data logging wants to reduce their cost, footprint but maintain reliability. This option does not add much to your costs but will greatly improve your reliability and simplify logging data without the risk of batteries going dead or a remote node losing its connection. To keep things as simple and straightforward as possible, this data logging system will be using Python.


Prior Knowledge

  1. A Raspberry Pi 3 or newer 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 T4 or LabJack T7

  2. Raspberry Pi 3 or newer 

  3. Display for Raspberry Pi 

  4. Keyboard and mouse to connect to Raspberry Pi

  5. An analog sensor of your choosing

 

Goals

  1. Measure and record data using a Raspberry Pi and a LabJack device

  2. Create a virtual environment

  3. Install LabJack LJM Driver

  4. Install and Run LJM Python Examples

  5. Read voltage from Analog input

  6. Log readings to separate file

 

Update Raspberry Pi (suggested but not required) 

It is always good to keep your system up to date. Updating your system ensures that you are using the newest version of Raspberry Pi’s software and avoids any compatibility issues when running programs on the Raspberry Pi. Updating 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

 

Create Virtual Environment

Make and activate a virtual environment by entering the commands below into your command terminal.  If you are unfamiliar with virtual environments, check out Python Virtual Environment for more information. 

$ python3 -m venv myenv    #make a venv

$ source myenv/bin/activate    # activate the venv

 

Install the latest LJM Library

First, we recommend checking which architecture your device uses. Most older Raspberry Pis use the 32-bit ARM architecture (ARMv7) but newer Raspberry Pis also support 64-bit ARM (sometimes called ARMv8 or Aarch64). You can easily check your computer architecture with the following command:

$ uname -m

 

This should output something like ARMv7, ARMv8, or Aarch64. From there, navigate to the LJM Downloads page to download and install the appropriate ARM Linux driver. Expand "Details" toward the right of the installer download link for installation instructions.

 

Before following the installation instructions on the LJM Downloads page, use the command:

$ wget https://labjack.com/sites/default/files/software/LabJackM-1.1804-Raspbian-Linux-armhf-release.tar.gz

 

The file used in these directions is the most updated version as of 5/31/2022. Make sure to check LJM Downloads for the newest version of the LJM Library. 

 

Install labjack-ljm Python package

To run LJM using Python, both the LJM library and the labjack-ljm Python package must be installed. To install the labjack-ljm Python package, enter the commands below into your terminal. 

$ pip install labjack-ljm

$ pip install labjack 

 

You may get a “ModuleNotFound: No module named ‘labjack’”  error when running a python script.  To fix this, use the sudo command for both pip install commands. 

$ sudo pip install labjack-ljm

$ sudo pip install labjack-ljm

 

For more details and troubleshooting tips, check out Python for LJM.

 

Running Examples

With the LJM library installed and a virtual environment created, you should be ready to run some examples. See our LJM Examples List for examples and setup instructions in numerous common programming languages. If you are new to programming, we recommend starting with a scripting language such as Python.

To Run Python for LJM 

$ wget https://labjack.com/sites/default/files/software/Python_LJM_2020_11_20.zip

$ unzip Python_LJM_2020_11_20.zip

$ cd Python_LJM_2020_11_20

$ python setup.py install

 

The file used in these directions is the most updated version as of 5/31/2022. Make sure to check LJM Examples List for the newest version of Python for LJM. 

Standalone Data Logging

Your Raspberry Pi is now ready to begin logging data. There are many different ways you could record data however, one of the simplest ways is to write analog input data to a .csv file. This .csv file can then be accessed in the Raspberry Pi’s file directory and/or an external USB flash drive. An example python script for this is provided at the bottom of this app note. 

 

Going Deeper: JEDI One by Machinechat

If you would like to go further than just logging data and want to monitor in real time, JEDI One is a perfect tool that is affordable and easy to run on a Raspberry Pi. JEDI One by Machinechat offers powerful yet lightweight software (less than 30MB) that can be used with LabJack UD and T-Series hardware.  Pairing a Labjack with the JEDI One software from Machinechat, you can create rules, alerts and actions, email and text notifications, beautiful dashboards, and network monitoring, among other things. Best of all, this can all be set up in about 15 minutes. 

If you are interested in using JEDI One with your Labjack device, check out Supercharging your LabJack for instructions and more. 

 

Sources

  1. Raspberry Pi, 6/6/2022: Installing Raspbian with Noobs

  2. Raspberry Pi, 6/6/2022: Raspbian

  3. Machinechat, 6/6/2022: JEDI One by Machinechat

  4. Machinechat, 6/6/2022: Supercharging your LabJack

  5. GeeksforGeeks, 6/14/2022: Python Virtual Environment