Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Verlique
#63682 Hi guys, I have a huge problem and i don't know WHY.
I control 2 step motors with my android, but always after a "comand" the Esp give me a WDT error and reset :(

My code:
Code: Select all#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <AccelStepper.h> // Responsavel pelas funções dos motores
#include <MultiStepper.h> // Controle de multiplos motores

#define interface 8
half stepper
#define motorPinD1  5     // IN1 ULN2003 driver 1
#define motorPinD2  4     // IN2 ULN2003 driver 1
#define motorPinD3  0     // IN3 ULN2003 driver 1
#define motorPinD4  2     // IN4 ULN2003 driver 1
#define motorPinD5  14     // IN1 ULN2003 driver 2
#define motorPinD6  12     // IN2 ULN2003 driver 2
#define motorPinD7  13    // IN3 LN2003 driver 2
#define motorPinD8  15    // IN4 ULN2003 driver 2

AccelStepper motor1(interface, motorPinD1, motorPinD3, motorPinD2, motorPinD4);
AccelStepper motor2(interface, motorPinD5, motorPinD7, motorPinD6, motorPinD8);
MultiStepper motores;

int motorVel = 1000;
int command = 001;
int cmdPassado;
long posicao[2];
long posicaoA[2];

const char *ssid = "MotoG";
const char *password = "tetando123";

ESP8266WebServer server(80);

/* Just a little test message.  Go to http://192.168.4.1 in a web browser
   connected to this access point to see it.
*/
void handleRoot() {
  //server.send(200, "text/html", "<h1>You are connected</h1>");
  String cmd;
  cmd += "<!DOCTYPE HTML>\r\n";
  cmd += "<html>\r\n";
  //cmd += "<header><title>ESP8266 Webserver</title><h1>\"ESP8266 Web Server Control\"</h1></header>";
  cmd += "<head>";
  cmd += "<meta http-equiv='refresh' content='5'/>";
  cmd += "</head>";

  switch (command) {
    case 010:
      cmd += ("<br/>Device FRONT");
      break;
    case 011:
      cmd += ("<br/>Device BACK");
      break;
    case 110:
      cmd += ("<br/>Device LEFT");
      break;
    case 111:
      cmd += ("<br/>Device RIGHT");
      break;
    default:
      cmd += ("<br/>Device STOP");
      break;
  }
  cmd += "<html>\r\n";
  server.send(200, "text/html", cmd);
}

void handleNotFound() {
  //digitalWrite(led, 1);
  String message = "File Not Found\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET) ? "GET" : "POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";
  for (uint8_t i = 0; i < server.args(); i++) {
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  }
  server.send(404, "text/plain", message);
  //digitalWrite(led, 0);
}

void setup() {
wdt_disable();
  // Motores
  motor1.setMaxSpeed(1000);
  motor1.setSpeed(motorVel);
  motor2.setMaxSpeed(1000);
  motor2.setSpeed(motorVel);
  motores.addStepper(motor1);
  motores.addStepper(motor2);

  Serial.begin(9600);
  //WiFi.softAP(ssid, password);

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");

  }
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  server.on("/", handleRoot);


  server.on("/status001", []() {
    server.send(200, "text/plain", "Device Stop");
    command = 001;
  });

  server.on("/status010", []() {
    server.send(200, "text/plain", "Device Frente");
    command = 010;
  });

  server.on("/status011", []() {
    server.send(200, "text/plain", "Device Tras");
    command = 011;
  });

  server.on("/status110", []() {
    server.send(200, "text/plain", "Device ESQ");
    command = 110;
  });

  server.on("/status111", []() {
    server.send(200, "text/plain", "Device DIR");
    command = 111;
  });

  server.onNotFound(handleNotFound);
  server.begin();
  Serial.println("Servidor Iniciado!");
}

void loop() {
  server.handleClient();
  switch (command) {
    case 010:
      posicao[0] = 100 +  posicaoA[0];
      posicao[1] = 100 +  posicaoA[1];
      motores.moveTo(posicao);
      motores.runSpeedToPosition(); // Blocks until all are in position
      break;
    case 011:
      posicao[0] = -100;
      posicao[1] = -100;
      motores.moveTo(posicao);
      motores.runSpeedToPosition(); // Blocks until all are in position
      break;
    case 110:
      posicao[0] = 100;
      posicao[1] = 100;
      motores.moveTo(posicao);
      motores.runSpeedToPosition(); // Blocks until all are in position
      break;
    case 111:
      posicao[0] = 100;
      posicao[1] = 100;
      motores.moveTo(posicao);
      motores.runSpeedToPosition(); // Blocks until all are in position
      break;
    case 001:
      motor1.stop();
      motor2.stop();
      break;
     
  }
    posicaoA[0]+=posicao[0];
    posicaoA[1]+=posicao[1];
}
User avatar
By Verlique
#63697
martinayotte wrote:We need to look at the library, there are maybe not ESP aware and using it's own delay() instead of the delay() provide by ESP SDK.


I'm using this link to get this lib:
http://arduino.esp8266.com/package_esp8 ... index.json

(attachment as well)
You do not have the required permissions to view the files attached to this post.
User avatar
By martinayotte
#63702 I'm not talking about ESP libraries, but those :
Code: Select all#include <AccelStepper.h> // Responsavel pelas funções dos motores
#include <MultiStepper.h> // Controle de multiplos motores

They probably have some code inside them that is not ESP friendly, such custom delays.