Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
daq-and-datalogging:documents:raspberry-pi-acquisition-with-ul-for-linux [2023/06/14 05:43] – Scandiwebdaq-and-datalogging:documents:raspberry-pi-acquisition-with-ul-for-linux [2023/07/28 01:07] (current) – Arthur Brown
Line 1: Line 1:
-====== TechTip: ======+====== TechTip: Raspberry Pi Data Acquisition Using Universal Library for Linux® ======
  
-===== Utilizing Digital Inputs / Outputs with MCC DAQ =====+**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**\\  **Objective**\\ 
-To show how to write to a single digital I/O bit using an MCC data acquisition device and various software platforms.+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**\\  **Intended Audience**\\ 
-Data acquisition system developers who need to monitor or control digital states, and seek to understand its implementation in various software environments.+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.\\ 
  
-**Overview**\\  +**Equipment**\\  
-Digital signals, by definition, are those which can represent just two states, such as on or off. Examples include a warning lamp being lit or dark, a door being latched or unlatched, and a relay being closed or open. Numerically the two states are represented as 1 and 0, or Boolean (true and false). As in most hardware architectures, such individual bits are concatenated together to form bytes and words for more efficient data transfer. Such is the case for the hardware ICs used in modern DAQ devices. Usually, the input and output capability is provided in groups of 8 bits, and all 8 are read or written to in parallel fashion.+The following equipment is needed to perform the exercises:
  
-In some applications you will want to control or monitor a set of signals exactly at the same time, so be sure to group those signals onto the same port. But for some signals, while you may physically wire them to the same port, you may decide to read or write to them sequentially. In addition to port-wise operations, MCC provides bit-wise operations that automatically mask the remaining bits from the individual bit you want to focus on.+  *Raspberry Pi single-board computer – For this example, Raspberry Pi 3 model b is used, but you can use any Raspberry Pi model 
 +  *microSD 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
  
-A common question is “how fast should I sample my digital inputs?”, and the answer invariably is: frequently enough so you do not miss a change-of-state. Note that digital inputs generally are not self-latching, nor do they automatically detect input changes. You must read (poll) them on a regular basis, and it is up to your software to decide if the current reading represents a change from the prior reading. For outputs, since they are latched, you need not write to the port again unless you require a change of state.+[[https://files.digilent.com/manuals/Linux-hw.pdf | Click here]] for a listing of MCC DAQ devices supported under Linux® and compatible with Raspberry Pi.\\ 
  
-While real-world digital signals are predominantly unidirectional, DAQ devices usually offer bi-directional capability so as to be adaptable to a wider set of applications. Generally, a DAQ device’s digital ports will power up as inputs. You will need to set (i.e. configure) the direction of each port on the DAQ device for the desired direction. Some devices are bit-configurable for further flexibility. The configuration is to be done once for each digital port, at the start of the program.+The image below shows the Raspberry Pi configuration used to perform these exercises.\\ 
  
-For a software-paced digital output operation, independent of the software platform, two steps are required: Set the direction of the port to output, then later write a value to the port/bit. The former is performed just once, while the latter can be repeated as needed throughout the application.+{{https://files.digilent.com/reference-images/TT-10-RaspberryPi.png?545x595}}\\ 
  
-The following information must be specified:+**Install the Raspberry Pi Operating System**\\  
 +You must install the Raspberry Pi operating system onto the Raspberry Pi before it can be used. The Raspberry Pi OS (previously called Raspbian) is the official supported OS for the Raspberry Pi.\\ 
  
-  *Port Number +Use the Raspberry Pi imager to install the Raspberry Pi OS to a microSD card. The SD card must be formatted to remove all previous information.\\  
-  *Port Direction + 
-  *Data value to output+**Watch the Video!** Go to [[ https://www.youtube.com/watch?v=J024soVgEeM | HOW TO INSTALL RASPBIAN OS to your Raspberry Pi with ease]] to see a brief video that shows how to image your microSD card with Raspberry Pi OS.\\  
 + 
 +**Format the microSD card**\\  
 +Perform the following steps to format the microSD card: 
 + 
 +  *Go to www.sdcard.org and click **SD Memory Card Formatter** button. 
 +  *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. 
 +  *Install the SD card into your PC or Mac and run the **SD Card Formatter 5.0.1 Setup.exe** (SD formatter executable). 
 + 
 +**Write the Raspberry Pi image to the microSD card**\\  
 + 
 +  *Insert the microSD card into a computer or SD card reader connected to a computer. 
 +  *Go to https://www.raspberrypi.org/downloads/ and download the latest version of Raspberry Pi Imager specific to your operating system (Windows, macOS or Ubuntu). 
 +  *Connect an SD card reader with the formatted SD card inside. 
 +  *Run the Raspberry Pi Imager exe and select an operating system. 
 +  *Choose the SD card you wish to write your image to. 
 +  *Click 'WRITE' to begin writing data to the SD card. 
 + 
 +For additional information and options go to the Installing operating system images page on the Raspberry Pi website.\\  
 + 
 +**Use the Raspberry Pi**\\  
 + 
 +  *Insert the microSD card into the Raspberry Pi. 
 +  *Open the setup options menu and configure various options such as the language and regional settings to match your location 
 +  *Tap <Finish> and press <Enter> when done setting configuration options. 
 +  *The command prompt displays pi@raspberrypi~$
      
-And the following information is returned:+Congratulations! You have now ready to use the Raspberry Pi!\\ 
  
-  * Error code +**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~$\\ 
  
-The examples below show how to perform a non-continuous scan using the Universal Library™, UL for Android™, NI LabVIEW™, DASYLab®, and DAQami.\\ +**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.\\ 
  
-**Universal Library**\\  +  *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. 
-The following example shows how to first configure, and then control, a digital output using the Universal Library (UL) and Visual Basic:+  *Click Scan to list the available wireless networks. 
 +  *Double click on the service set identifier (SSID) network name to which you want to connect. 
 +  *Verify the Authentication and Encryption fields on the connection window, and enter the password in the PSK (pre-shared key) field. 
 +  *Click Add. 
 +The configuration program automatically connects to the newly configured network. 
 +  *Cycle the device power to reboot the Raspberry Pi and enter the login information above.
  
-PortType = MccDaq.DigitalPortType.AuxPort ‘Specify which digital port\\  +After logging in, the command prompt displays pi@raspberrypi~$.\\ 
-Direction = MccDaq.DigitalPortDirection.DigitalOut ‘Specify the output direction\\  +
-ULStat = DaqBoard.DConfigPort(PortType, Direction) ‘Configure the port\\  +
-BitNum = 0 ‘Specify which bit in the port to control\\  +
-BitValue = 1 ‘Specify the value to write\\  +
-ULStat = DaqBoard.DBitOut(PortType, BitNum, BitValue) ‘Write the value out\\ +
  
-**UL for Android**\\  +**Update the Raspberry Pi Package List**\\  
-The following example shows how to configure and control a digital output using UL for Android and Java:\\ +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
  
-DigitalPortType = AUXPORT; //Specify which digital port\\  +**UL for Linux**\\  
-DigitalDirection = OUTPUT; //Specify the output direction\\  +To build and install the latest version of the library, refer to the instructions on GitHub at: https://github.com/mccdaq/uldaq
-mDioDevice.dConfigPort(DigitalPortType, DigitalDirection); //Configure the port\\  +
-bitNum = 0; //Specify which bit in the port to control\\  +
-bitState = true; Specify the Boolean value to write mDioDevice.dBitOut(DigitalPortType, bitNum, bitState); //Write the value out+
  
-**NI LabVIEW**\\  +**Examples**\\  
-The following example shows how to control a digital output bit using LabVIEW. The wiring diagram below shows the pertinent VIs and settings. Here just the first bit (Do0) of the Auxport on hardware device #0 is configured for output, and then it is tasked with outputting the true/false value the operator enters\\ +MCC example apps are developed on Linux and are available for Linux supported MCC devices in C and Python. The example apps perform all the device functions such as acquire analog, counter, and digital data (as supported), test device functionality, and display device information.
  
-{{https://files.digilent.com/resources/measurement-computing/Reference Images/TT-DIO-ULx-wiring-diagram.png?625x152}}\\ +Refer to the [[https://files.digilent.com/manuals/UL-Linux/c/examples.html | online help for C/C++]] or the [[https://files.digilent.com/manuals/UL-Linux/python/index.html | online help for Python]] for an overview of each test/example app. Select an appropriate test app for your device.\\ 
  
-DASYLab\\  +**Running Examples**\\  
-Non-programmers with digital signals to monitor and control can consider the popular DASYLab package. A Digital Output module is shown below, with its data input wired to the output of a Switch Control module. At run time, the operator can select either on or off, resulting in digital output bit D0 of the DAQ hardware toggling to either a 1 or 0.\\ +Example apps are located in the examples folder. Run the following commands to execute the analog input example:
  
 +C:
 +$./Ain
  
-{{https://files.digilent.com/resources/measurement-computing/Reference Images/TT-DASYLab-DO.png?342x231}}\\ +Python: 
 +$ ./a_in.py 
 +There are example apps for each feature of supported devices, for example:
  
-Double clicking on the Switch module allows you to access a menu where you can specify how often the switch position will be monitored. Below we see that 1 Hz is selected, resulting in digital output bit D0 on the DAQ hardware being updated every second to match the operator’s selection.\\ +^ 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 |
  
-{{https://files.digilent.com/resources/measurement-computing/Reference Images/TT-DASYLab-DO-timebase.png?379x225}}\\ +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.
  
 More Information\\  More Information\\ 
-Please contact Measurement Computing Corporation if you have any questions or if you would like any further information.\\  +Please reach out to our support team on the Digilent Forum if you have any questions: [[https://forum.digilent.com/]]
- +
-Knowledgebase: [[https://kb.mccdaq.com/Default.aspx | kb.mccdaq.com]]\\  +
-Phone: 508-946-5100\\  +
-Fax: 508-946-9500\\ +
      
-Additional TechTips are available on our [[https://www.mccdaq.com/Technical-Articles | Data Acquisition Technical Articles web page.]]+Additional TechTips are available here in Digilent Reference: [[start]]