驱动示例如***意Stepper stepper(STEPS, 8, 9, 10, 11),改为Stepper stepper(STEPS, 8, 10, 9, 11)即可,该程序在arduino UNO板上运行后,电机正反转没有问题,但在esp8266运行时只能“单向旋转”,旋转方向或正或反。
测试后发现,将 stepper.step(2048)中的参数改为255以下,即可实现两句代码顺序执行,连续正反转。另外应用该官方Stepper容易导致esp8266 stack dumped导致重启,标志是串口出现类似如下:
/*
- MotorKnob
- A stepper motor follows the turns of a potentiometer
- (or other sensor) on analog input 0.
- http://www.arduino.cc/en/Reference/Stepper
- This example code is in the public domain.
*/
#include <Stepper.h>
// change this to the number of steps on your motor
#define STEPS 100
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it’s
// attached to
Stepper stepper(STEPS, 8, 9, 10, 11);
// the previous reading from the analog input
int previous = 0;
void setup() {
// set the speed of the motor to 30 RPMs
stepper.setSpeed(30);
}
void loop() {
stepper.step(-2048);
delay(500);
stepper.step(2048);
delay(500);
}
后确定是该库文件问题。这个库文件在当初学UNO的时候一直使用没什么问题,但是在esp8266下出现上述问题,后来在github上download了个库文件步进电机运行正常了,再也没有stack dumped,分享一下:https://download.csdn.net/download/u012893428/10686229