Analog Input - Continuous Voltage
Display and Logging
Table of Contents
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:
- Use of Kivy, a cross-platform NUI development framework for python allowing easy separation of a UI layout and business logic
- Real-time, (60+ FPS) graph display with home, zoom, and pan using matplotlib and numpy
- Automatic logging of acquired data to a .csv file
- Use of the python multiprocessing package to separate the Kivy App process from the DAQmx Stream Reader process
- mp_007's kivy_matplotlib_widget - Used in the UI with code taken from real-time plotting examples
- pbellino's daq_nidaqmx_example - Inspiration and borrowed file writer
Get a local copy up and running by following these steps.
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
-
Clone the repo (or simply download as zip and then unzip):
git clone https://github.com/sldgr/daqmx-python-UI-example
-
Update pip and other installation dependencies:
py -m pip install --upgrade pip setuptools virtualenv
-
Navigate to your repo:
cd <repo>
-
Create a virtual environment:
py -m venv env
-
Activate the virtual environment:
.\env\Scripts\activate
-
Install necessary packages from requirements.txt:
py -m pip install -r requirements.txt
-
(Optional for simulated hardware):
- Open NI MAX (Measurement & Automation Explorer)
- Right-click > 'My System > Devices and Interfaces' and select 'Create New...'
- Select 'Simulated NI-DAQmx Device or Modular Instrument'
- Select 'Finish'
- Select any device that supports analog input. (e.g. PXIe-6368)
- Select a desired PXI chassis and slot # (or use defaults)
- 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.
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.
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!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Cole Harding - [email protected]
Project Link: https://github.com/sldgr/daqmx-python-UI-example