步进电机的优点在于它能够被精确定位,正向或反向一次性转动“一步”,并且也能够连续转动。本次实验,我们选用的舵机驱动芯片是ULN2003A,ULN2003 是高耐压、大电流复合晶体管阵列,由七个硅NPN 复合晶体管组成。为了方便起见,我们用了ULN2003A模块,电路连接方式如下图:
#!/usr/bin/env python
#########################################################
# File name: stepMotor.py
# Author: Jason Dai
# Date: 2015/01/26
#########################################################
import RPi.GPIO as GPIO
import time
IN1 = 11 # pin11
IN2 = 12
IN3 = 13
IN4 = 15
def setStep(w1, w2, w3, w4):
GPIO.output(IN1, w1)
GPIO.output(IN2, w2)
GPIO.output(IN3, w3)
GPIO.output(IN4, w4)
def stop():
setStep(0, 0, 0, 0)
def forward(delay, steps):
for