Soft wdt Reset-使用步进电机的ESP8266 / NodeMCU

问题描述

我正在运行一个非常基本的代码,并且我的ESP8266在步进电机功能期间超时。我在myStepper.step函数调用中得到了大约1600ms的“ Soft wdt Reset”。该程序适用于38的MyStepper.setSpeed,但不适用于37。这种情况发生在我尝试过的两块板上。有办法解决这个问题吗?我正在使用Arduino编程软件,代码如下。

#include <Stepper.h>

const int stepsPerRevolution = 200;  
unsigned long startT;

// initialize the stepper library:
Stepper myStepper(stepsPerRevolution,14,12,13,15); //D5,D6,D7 & D8

void setup() {
  // set the speed at in rpm:
  myStepper.setSpeed(37); //38 good (~1571 ms),37 bad (~1614 ms)
  
  // initialize the serial port:
  Serial.begin(9600);
  Serial.println("Started stepper_oneRevolution_mk-------------------------");
}

void loop() {
  startT=millis();
  // step one revolution  in one direction:
  Serial.print("clockwise took: ");
  myStepper.step(stepsPerRevolution);
  Serial.println(millis()-startT);
  delay(1000);
  
}

解决方法

看门狗定时器抱怨您将前任拖了太久。

myStepper.step()处于阻塞状态,因此在电机完成运动之前,其他进程无法使用处理器。

在此期间,WiFi通信和管理TCP / IP堆栈之类的过程也将无法运行,在这种情况下,看门狗定时器可用于重置ESP8266。

您可以通过使步进电机每个循环仅移动几步来避免这种情况,并在必要时添加yield();或提高速度,使其在看门狗生气之前完全旋转。

您可以尝试执行20步,然后再执行简短的delay()yield()并以自己的for循环执行10次,以尝试快速而肮脏的方法。您将不得不做一些实验,以达到不触发看门狗的目的,并补偿您所做的时间测量。

或者使用具有专用于WiFi的额外内核的Arduino或ESP,或找到​​不阻塞的步进器库。

,

我就是这样解决这个问题的。

  • 我可以在看门狗允许的时间段内步进电机一次
  • 所以不要告诉电机步进 30 次
    • override func tableView(_ tableView: UITableView,didSelectRowAt indexPath: IndexPath) { tableView.deselectRow(at: indexPath,animated: true) let chatId = startChat(user1: User.currentUser!,user2: user!) if indexPath.section == 1 { if BlockLabel.text == "Block User" { let chatId = startChat(user1: User.currentUser!,user2: user!) let privateChatView = ChatViewController(chatId: chatId,recipientId: user!.id,recipientName: user!.username) privateChatView.hidesBottomBarWhenPushed = true navigationController?.pushViewController(privateChatView,animated: true) } else { ProgressHUD.showFailed("You Blocked This user") } } // start from here is the code if indexPath.section == 2 { if BlockLabel.text == "Block User" { FirebaseIsBlocked.shared.saveTypingCounter(blocked: true,chatRoomId: chatId) BlockLabel.text = "Unblock User" } else if BlockLabel.text == "Unblock User" { FirebaseIsBlocked.shared.saveTypingCounter(blocked: false,chatRoomId: chatId) BlockLabel.text = "Block User" } } }
  • 我告诉它转 1 圈,30 次。 :)
    • 这里的关键是在每次旋转之间调用 myStepper.step(stepsPerRevolution * 30);

过度简化

yield()

Yielding for ESP8266(火花)

更完整的例子。这缺少所有 wifi 和 mqtt 位,但应该给你要点。

int steps = 30;
while(stepsTaken < steps){
    yield(); // Let other things run
    myStepper.step(-stepsPerRevolution * 1);
    stepsTaken++;
}