esp8266驅動ULN2003帶28byj四相五線步進電機時,arduino IDE中遇到的問題
驅動示例如下,注意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.
- 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,分享一下: