Hello,
I have a problem using nidaqmx digital output to control a stepper motor in Python. I have read through the Python documentation (http://nidaqmx-python.readthedocs.io/en/latest/index.html ) and this example (https://github.com/ni/nidaqmx-python/blob/master/nidaqmx_examples/do_sw_timed.py) already, but I am running into issues getting the stepper motor to rotate. So far it seems like the digital output is being sent to the motor, but the motor is only vibrating and not rotating.
System:
Windows 7, Python 3.7, NI USB-6009
The code:
import nidaqmx import time from nidaqmx.constants import ( LineGrouping) with nidaqmx.Task() as task: task.do_channels.add_do_chan('Dev1/port1/line0:3') task.start() while True: task.write([8,0,0,0]) time.sleep(.002) task.write([0,8,0,0]) time.sleep(.002) task.write([0,0,8,0]) time.sleep(.002) task.write([0,0,0,8]) time.sleep(.002)
When I run the code, the stepper motor will vibrate but it will not rotate like I want it to. Any suggestions to fix this problem? I have already tried changing the length of the pause from .002 to .02 to .2 (and values in between). I have also tried writing different values of bits such as [8,0,8,0] and [0,8,0,8]. Changing the length of the pause will change how frequently it vibrates, but I cannot get the motor to actually rotate. I assume it is an issue with what bits I am writing to the task, because the digital output works.
For reference, here is a version of the code in matlab that works like it is supposed to on the same computer/system:
clear all close all clc pt=2/100; s=daq.createSession('ni') %% addDigitalChannel(s,'Dev1','Port1/Line0','OutputOnly'); addDigitalChannel(s,'Dev1','Port1/Line1','OutputOnly'); addDigitalChannel(s,'Dev1','Port1/Line2','OutputOnly'); addDigitalChannel(s,'Dev1','Port1/Line3','OutputOnly'); n=0 while(n<100) outputSingleScan(s,[1 0 0 0]); pause(pt) outputSingleScan(s,[0 1 0 0]); pause(pt) outputSingleScan(s,[0 0 1 0]); pause(pt) outputSingleScan(s,[0 0 0 1]); pause(pt) n=n+1 str='loop' end clear all close all
Thanks in advance, any advice is appreciated.