我正在使用以下免费软件代码成功驱动步进电机:
/*
* Simple demo, should work with any driver board
*
* Connect STEP, DIR as indicated
*
* Copyright (C)2015-2017 Laurentiu Badea
*
* This file may be redistributed under the terms of the MIT license.
* A copy of this license has been included with this distribution in the file LICENSE.
*/
#include <Arduino.h>
#include "BasicStepperDriver.h"
// Motor steps per revolution. Most steppers are 200 steps or 1.8 degrees/step
#define MOTOR_STEPS 200
#define RPM 120
// Since microstepping is set externally, make sure this matches the selected mode
// If it doesn't, the motor will move at a different RPM than chosen
// 1=full step, 2=half step etc.
#define MICROSTEPS 1
// All the wires needed for full functionality
#define DIR 4
#define STEP 3
//Uncomment line to use enable/disable functionality
//#define SLEEP 13
// 2-wire basic config, microstepping is hardwired on the driver
BasicStepperDriver stepper(MOTOR_STEPS, DIR, STEP);
//Uncomment line to use enable/disable functionality
//BasicStepperDriver stepper(MOTOR_STEPS, DIR, STEP, SLEEP);
void setup() {
stepper.begin(RPM, MICROSTEPS);
// if using enable/disable on ENABLE pin (active LOW) instead of SLEEP uncomment next line
// stepper.setEnableActiveState(LOW);
}
void loop() {
// energize coils - the motor will hold position
// stepper.enable();
/*
* Moving motor one full revolution using the degree notation
*/
stepper.rotate(360);
/*
* Moving motor to original position using steps
*/
stepper.move(-MOTOR_STEPS*MICROSTEPS);
// pause and allow the motor to be moved by hand
// stepper.disable();
delay(5000);
}
但是,我想使用相同的 Arduino-Uno 一次驱动两个电机并稍微更改代码。我能做些什么?我对编码非常陌生,所以轻松一点。我知道有一种叫做函数的东西,它接收值。但是,我需要它使用多个控制引脚:每个电机两个 - “step”(每次将电机移动一步)和“dir”(每个电机的旋转方向)。我也明白这个功能:
BasicStepperDriver stepper(MOTOR_STEPS, DIR, STEP);
一次不能接受 4 个值(DIR1、DIR2、STEP1 和 STEP2)。我希望可以使用上面的代码(稍作改动),以便使用 4 个不同的 I/O 引脚(2 个用于第一个电机驱动器(我的 arduino 连接到一个电机驱动器)一次控制 2 个电机我有 2 个并想用另一个来驱动另一个电机)“step”和“dir”引脚,2 个用于第二个电机驱动器的“step”和“dir”引脚)。
谢谢