Skip to content

A Python GUI app for logging and displaying analog voltage data with the NI DAQmx API

Notifications You must be signed in to change notification settings

sldgr/daqmx-python-UI-example

Repository files navigation

DAQmx with Kivy

Analog Input - Continuous Voltage

Display and Logging

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Contributing
  5. Contact

About The Project

This is a Python take on the LabVIEW built-in example VI called Voltage - Continuous Input. Like the G-code equivalent, this code features the ability to configure, start and stop a DAQmx single-channel analog input voltage task with real or simulated NI (National Instruments) hardware. Other features worth mentioning include:

  1. Use of Kivy, a cross-platform NUI development framework for python allowing easy separation of a UI layout and business logic
  2. Real-time, (60+ FPS) graph display with home, zoom, and pan using matplotlib and numpy
  3. Automatic logging of acquired data to a .csv file
  4. Use of the python multiprocessing package to separate the Kivy App process from the DAQmx Stream Reader process

Built With

ACKNOWLEDGEMENTS

(back to top)

Getting Started

Get a local copy up and running by following these steps.

Prerequisites

What you need before proceeding with the installation:

  • Windows 10

  • Python 3.9 (3.10 or later not supported)

    https://www.python.org/downloads/
  • Pip

    py -m pip install --upgrade pip
    py -m pip --version
  • Virtualenv

    py -m pip install --user virtualenv
  • NI DAQmx Full Driver (Latest Version) <- Needed for NI MAX

    https://www.ni.com/en-us/support/downloads/drivers/download.ni-daqmx.html#428058

Installation

  1. Clone the repo (or simply download as zip and then unzip):

    git clone https://github.com/sldgr/daqmx-python-UI-example
  2. Update pip and other installation dependencies:

    py -m pip install --upgrade pip setuptools virtualenv
  3. Navigate to your repo:

    cd <repo>
  4. Create a virtual environment:

    py -m venv env
  5. Activate the virtual environment:

    .\env\Scripts\activate
  6. Install necessary packages from requirements.txt:

    py -m pip install -r requirements.txt
  7. (Optional for simulated hardware):

    1. Open NI MAX (Measurement & Automation Explorer)
    2. Right-click > 'My System > Devices and Interfaces' and select 'Create New...'
    3. Select 'Simulated NI-DAQmx Device or Modular Instrument'
    4. Select 'Finish'
    5. Select any device that supports analog input. (e.g. PXIe-6368)
    6. Select a desired PXI chassis and slot # (or use defaults)
    7. Verify the simulated device is working by right-clicking and selecting ' Test Panel...' and then hitting 'Start' when it opens. Verify you see a signal.

(back to top)

Usage

To run, simply use the following command in the top-level of the repository with the virtual environment (env) running:

.\python daqmx_with_kivy.py

From here, you can hit 'Start Acquisition' immediately if you are using device name PXI1Slot2. If you are using a real device or a device, a device with different name in NI MAX, or simply want to change the settings feel free to do by hitting 'Enter' on your keyboard after you type in each field. If there is an issue, the error will be displayed in the error box in the bottom right-hand corner.

After starting, a single channel, continuous analog input voltage task will begin. If using a simulated device with the default settings, this task will acquire a -5V to 5V sine wave with noise at 1000 Hz. The graph will update in real-time (up to 60 FPS) point-by-point. The UI will run in one process and the DAQmx acquisition will run in other process. The DAQmx task will read the number of samples requested (default 100) per read and will write the samples to a .csv file.

To stop the task, simply hit 'Stop Acquisition' or close the window. A .csv file will eventually appear after being written and closed by the DAQmx process.

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

Contact

Cole Harding - [email protected]

Project Link: https://github.com/sldgr/daqmx-python-UI-example

(back to top)

About

A Python GUI app for logging and displaying analog voltage data with the NI DAQmx API

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages