a)驱动板可以同时接2个步进电机,单极和双极都适用。
b)连接电机
上图中左为双极驱动Bipolar stepper motors(4线),右为单极驱动Unipolar Stepper Motor(6线)
- 单极驱动Unipolar Stepper Motor(6线): 首先需要知道哪根线是中心线,然后将中心线都接到接线柱的GND(右图白色和黄色),剩下的两组端线(黑和绿,红和蓝)分别接到M1、M2或M3、M4。
- 双极驱动Bipolar stepper motors(4线): 跟单极驱动类似,GND留空不接就可以。
C)步进电机(Stepper motor)控制示例详解
#include <Wire.h> #include <Adafruit_MotorShield.h> #include "utility/Adafruit_MS_PWMServoDriver.h" // Create the motor shield object with the default I2C address Adafruit_MotorShield AFMS = Adafruit_MotorShield(); ; // Connect a stepper motor with 200 steps per revolution (1.8 degree) // to motor port #2 (M3 and M4) Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2); void setup() { AFMS.begin(); // create with the default frequency 1.6KHz myMotor->setSpeed(10); // 10 rpm } void loop() { //Single coil steps myMotor->step(100, FORWARD, SINGLE); myMotor->step(100, BACKWARD, SINGLE); //Double coil steps myMotor->step(100, FORWARD, DOUBLE); myMotor->step(100, BACKWARD, DOUBLE); //Interleave coil steps myMotor->step(100, FORWARD, INTERLEAVE); myMotor->step(100, BACKWARD, INTERLEAVE); //Microstep steps myMotor->step(50, FORWARD, MICROSTEP); myMotor->step(50, BACKWARD, MICROSTEP); }
创建一个MotorShield对象:
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
从MotorShield创建StepperMotor对象:
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);
getStepper(steps, stepper#)
steps: 每转步数,建议35~200之间
stepper#: 1~2, M1、M2为1,M3、M4 为2
设置旋转速度:
setSpeed(rpm): 每分钟旋转速度
运转电机:
step(#steps, direction, steptype)
#steps:步数
direction:FORWARD or BACKWARD
steptype:SINGLE, DOUBLE, INTERLEAVE or MICROSTEP
*关于步进电机工作特性请参考网上资料。