TechTip: Raspberry Pi Data Acquisition using Universal Library for Linux

Introduction
The Raspberry Pi® is a single-board computer that runs the Linux® kernel-based operating system and provides easy connections to peripheral devices, including a monitor, mouse, keyboard, and MCC data acquisition devices. With a cost of less than $40, the Raspberry Pi provides a cost-effective way to perform data acquisition. You can acquire data from most Measurement Computing USB DAQ devices using the Raspberry Pi and UL for Linux.

Objective
Acquire data from an MCC DAQ device using a test application installed on a Raspberry Pi computer.
This document provides information about how to perform the following tasks:

  • Format an SD card
  • Install an operating system onto the Raspberry Pi
  • Configure Raspberry Pi options
  • Install Universal Library for Linux drivers and build the library
  • Run an MCC Linux test app

Intended Audience
This document is intended for application developers familiar with MCC DAQ devices who are interested in acquiring data on a Linux platform using a Raspberry Pi.

Equipment
The following equipment is needed to perform the exercises:

  • Raspberry Pi single-board computer – For this example, Raspberry Pi 3 model b is used, but you can use any Raspberry Pi model
  • SD card (8 GB or higher)
  • PC or Mac® with internet access
  • Ethernet® cable or wireless adapter (The Pi model used here has built in WiFi)
  • Monitor or television + HDMI cable
  • Power supply
  • Mouse or trackball
  • Keyboard
  • MCC DAQ device – I'm using a USB-1808X to perform data acquisition tasks

Click here for a listing of MCC DAQ devices supported under Linux® and compatible with Raspberry Pi.

The image below shows the Raspberry Pi configuration used to perform these exercises.

Raspberry Pi

Using an SD to Install the Operating System
You must install an operating system onto the Raspberry Pi before it can be used. This example uses Raspbian, which is a free operating system based on Debian, optimized for the Raspberry Pi hardware. NOOBS (New Out Of the Box Software) is an operating system install manager for the Raspberry Pi, and is used to install Raspbian in this example.

You use an SD card to transfer NOOBS onto the Raspberry Pi. The SD card must be formatted to remove all previous information. The following procedures show you how to perform these steps.

Watch the Video! Go to http://www.raspberrypi.org/help/noobs-setup/ to see a video showing how to format the SD card, download NOOBS, and install the Raspbian OS onto the Raspberry Pi.

Format the SD card
Perform the following steps to format the SD card:

  1. Go to www.sdcard.org and click SD Memory Card Formatter button.
  2. Scroll to the page bottom and select the SD formatter for Windows or Mac, follow the on-screen prompts, and then save the download on the computer.
  3. Install the SD card into your PC or Mac and run the SD_CardFormatter0500SetupEN.exe (SD formatter executable).

Install the Operating System onto the Raspberry Pi
Perform the following steps to download NOOBS and install the OS onto the Raspberry Pi:

  1. Go to www.raspberrypi.org and click Downloads.
    Under the NOOBS section click Download Zip and save the file to your PC or Mac.
  2. Expand the zip file and copy all files to the SD Card.
  3. Remove the SD card from your PC or Mac, and install it into the Raspberry Pi.
  4. Connect the monitor, keyboard, mouse, and power.
    Connecting power will boot the Raspberry Pi.
    The Raspberry Pi Logo displays, followed by a NOOBS dialog box which shows a list of operating systems to install.
  5. Check the Raspbian checkbox and click Install, then select Yes on the Confirm dialog box to install Raspbian.
    A dialog box notifies you when installation is complete.
  6. Click OK; the Raspberry Pi starts loading Raspbian.
    If this is the first time booting Raspbian, a Setup Options menu appears. Use the keyboard arrow keys to navigate the menu.
  7. Set the configuration options, such as the language and regional settings to match your location.
  8. Tap <Finish> and press <Enter> when done setting configuration options.
    The command prompt displays pi@raspberrypi~$

Congratulations! You have now installed the Raspberry Pi operating system.

Logging In
Each time you boot up the Raspberry Pi you are prompted for the following login information:
   raspberrypi login: pi
   password: raspberry
The command prompt displays pi@raspberrypi~$

Verify Internet Access
Before downloading UL for Linux, verify that the Raspberry Pi can access the internet. You can connect an Ethernet cable or connect a USB WiFi adapter to connect with a wireless network. This example uses the Pi’s built in WiFi adapter.

  1. Double-click the WiFi Config icon on the desktop to start the wireless configuration program. The Adapter: field lists the name of the USB wireless adapter (for example wlan0); the Network: field is empty.
  2. Click Scan to list the available wireless networks.
  3. Double click on the service set identifier (SSID) network name to which you want to connect.
  4. Verify the Authentication and Encryption fields on the connection window, and enter the password in the PSK (pre-shared key) field.
  5. Click Add.
    The configuration program automatically connects to the newly configured network.
  6. Cycle the device power to reboot the Raspberry Pi and enter the login information above.

After logging in, the command prompt displays pi@raspberrypi~$.

Update the Raspberry Pi Package List
To ensure that you have the latest Raspberry Pi software versions for each package installed, enter the following code from the terminal window to update the Raspberry Pi package list.
      $ sudo apt-get update

To use the UL for Linux, you need to install the following prerequisites:

  1. C, C++ compilers and Make tool
  2. Development package for libusb

To install them, enter the following commands from the terminal window:
      $ sudo apt-get install gcc g++ make
      $ sudo apt-get install libusb-1.0-0-dev

Download the UL for Linux for C
The MCC Linux drivers are currently available for USB MCC devices (with more to come). They are stored on GitHub at: https://github.com/mccdaq/uldaq

  1. To download the UL for Linux, enter the following in the terminal window:
    $ wget https://github.com/mccdaq/uldaq/releases/download/v1.0.0/libuldaq-1.0.0.tar.bz2

  2. Extract the tar file
    $ tar -xvjf libuldaq-1.0.0.tar.bz2

  3. Run the following commands to build and install the library
    $ cd libuldaq-1.0.0
    $ ./configure && make
    $ sudo make install


  4. The C examples are located in the examples folder and ready to run
    $ cd examples
    $ ./Ain

Python Interface for UL for Linux
If you would like to use the UL for Linux with Python, you still need to follow the steps above, and then proceed here with pip:
      $ sudo pip install uldaq

Open the Raspberry Pi’s browser and navigate to:  pypi.org/project/uldaq

Under Navigation click the Download files link

Click the uldaq-1.0.0.tar.gz link to download the file.

A dialog box appears, select Save file and click OK.  The file is now downloaded.

  1. Copy the file from the Downloads folder to the folder where you installed libuldaq-1.0.0:
    Make a directory:
    $ mkdir python

    Change to the directory:
    $ cd python

    Copy the file from downloads:
    $ cp ~/Downloads/uldaq-1.0.0.tar.gz ~/libuldaq-1.0.0

  2. Extract the tar file:
    $ tar -xvf uldaq-1.0.0.tar.gz

  3. The Python examples are in the examples folder:
    $ cd uldaq-1.0.0/examples
    $ ./a_in.py

MCC Test Apps and Source
MCC test apps are developed on Linux and are available for Linux supported MCC devices in C and Python. The test apps perform all the device functions such as acquire analog, counter, and digital data (as supported), test device functionality, and display device information.

Refer to https://github.com/mccdaq/uldaq, click on the link for ULHELP and select Index.html for the names of each test/example app. Pick an appropriate test app for your device.

Example: Running an example app with an MCC USB DAQ Device and Raspberry Pi
Change to the libuldaq directory to run an example app and enter the following commands at the pi@raspberrypi~$ command prompt. For example, if you have an USB-1808X, you can run an analog input example:

  1. In C:
    $ cd libuldaq-1.0.0/examples
    $./Ain


  2. In Python:
    $cd libuldaq-1.0.0/python/uldaq-1.0.0/examples
    $ ./a_in.py

There are example apps for each feature of supported devices, for example:

Function C Examples Python Examples
Analog In Ain
AInScan
AInScanWithEvents
AInScanWithQueue
AInScanWithTrigger
a_in
a_in_scan
a_in_scan_with_events
a_in_scan_with_queue
a_in_scan_with_trigger
Analog Out AOut
AOutScan
a_out
a_out_scan
Digital IO Din
DBitIn
DInScan
DInScanWithTrigger
DOut
DBitOut
DOutScan
d_in
d_bit_in
d_in_scan
d_in_scan_with_trigger
d_out
d_bit_out
d_out_scan
Counter In CIn
CInScan
CInScanWithEncoder
c_in
c_in_scan
c_in_scan_with_encoder
Timer Out TmrPulseOut tmr_pulse_out

 

Each example performs a specific function of a supported device and is well commented for your review. Additional prompts appear if more information is needed, such as a channel number or frequency value. The examples run and the results displayed on the monitor.

更多信息
任何关于Raspberry Pi的数据采集问题,请联系Measurement Computing Corporation:

更多Raspberry Pi相关信息,请参考www.raspberrypi.org.

Measurement Computing Corporation 和 Measurement Computing logo是属于Measurement Computing公司的商标或注册商标
Raspberry Pi是属于Raspberry Pi基金会的商标
Linux®是Linus Torvalds在美国和其他国家的注册商标
其他商标全部属于其持有者

其他技术文章请浏览我们的数据采集技术文章页面