Hi,
following scenario:
stepper motor
Driver A4988
ESP8266
contolled by webinterface ( using wifi)
The motor works pretty well. It's moving smoothly forward and reverse and everything is fine. Despite of one thing
If I let do the motor too many steps at once to move a sled all over my testing area (maybe 40cm), the esp crashes and reboots.
on the seral interface it looks like this:
Connecting to fritzboxdampf
...........
WiFi connected
Server started
Use this URL to connect: http://192.168.178.98/
new client
GET /Command=backward HTTP/1.1
Client disonnected
new client
GET /favicon.ico HTTP/1.1
Client disonnected
new client
GET /Command=forward HTTP/1.1
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
Soft WDT reset
>>>stack>>>
ctx: cont
sp: 3ffffd90 end: 3fffffc0 offset: 01a0
3fffff30: 3fffdad0 00000000 00000000 40100f20
3fffff40: 40100260 3ffee72c 000004e2 40100290
3fffff50: 3fffdad0 000004e2 3ffee72c 402012c0
3fffff60: 40206518 00000000 00001388 00010d51
3fffff70: 00000000 00000000 3fff0104 00000000
3fffff80: 3ffef6dc 001d001f 8a00616d 40100164
3fffff90: 3fffdad0 00000000 3ffee7a4 3ffee7b8
3fffffa0: 3fffdad0 00000000 3ffee7a4 4020371c
3fffffb0: feefeffe feefeffe 3ffe85f0 40100c01
<<<stack<<<
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 3460, room 16
tail 4
chksum 0xcc
load 0x3fff20b8, len 40, room 4
tail 4
chksum 0xc9
csum 0xc9
v00044d30
~ld
Connecting to fritzboxdampf
.......
WiFi connected
Server started
Use this URL to connect: http://192.168.178.98/
It never happens if i let him move only have the way.
I do not have any clue why this happens.
Here is my code. Maybe you have an idea.
#include <ESP8266WiFi.h>
const char* ssid = "fritzboxdampf";
const char* password = "mypassword";
const int switch1 = 14;
const int switch2 = 12;
int switchval1 = 1;
int switchval2 = 1;
int pinRelais = 5;
int stepPin = 0; //GPIO0---D3 of Nodemcu--Step of stepper motor driver
int dirPin = 2; //GPIO2---D4 of Nodemcu--Direction of stepper motor driver
// Motor steps per rotation
const int STEPS_PER_REV = 200;
WiFiServer server(80);
void setup() {
Serial.begin(115200);
delay(10);
pinMode(pinRelais , OUTPUT);
pinMode(switch1, INPUT);
pinMode(switch2, INPUT);
pinMode(stepPin, OUTPUT); //Step pin as output
pinMode(dirPin, OUTPUT); //Direcction pin as output
digitalWrite(stepPin, LOW); // Currently no stepper motor movement
digitalWrite(dirPin, LOW);
//relais aus
digitalWrite(pinRelais , LOW);
delay(1000);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address on serial monitor
Serial.print("Use this URL to connect: ");
Serial.print("http://"); //URL IP to be typed in mobile/desktop browser
Serial.print(WiFi.localIP());
Serial.println("/");
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
Serial.println("new client");
while (!client.available()) {
delay(1);
}
// Read the first line of the request
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
// Match the request
int i = 0;
int value = LOW;
if (request.indexOf("/Command=forward") != -1) {
//relais an
digitalWrite(pinRelais , HIGH);
delay(100);
// Set motor direction clockwise
digitalWrite(dirPin, HIGH);
// Spin motor one rotation slowly
for (int x = 0; x < STEPS_PER_REV * 17 && switchval1 == 1; x++) {
switchval1 = digitalRead(switch1);
digitalWrite(stepPin, HIGH);
delayMicroseconds(700); //maximum 500, das ist das schnellste bei dem PM42S. 700 hรถrt sich gesund an
digitalWrite(stepPin, LOW);
delayMicroseconds(700);
switchval2 = 1;
}
digitalWrite(pinRelais , LOW);
}
if (request.indexOf("/Command=backward") != -1) { // Set motor direction counterclockwise
//relais an
digitalWrite(pinRelais , HIGH);
delay(100);
digitalWrite(dirPin, LOW);
// Spin motor two rotations quickly
for (int x = 0; x < STEPS_PER_REV * 17 && switchval2 == 1 ; x++) {
switchval2 = digitalRead(switch2);
digitalWrite(stepPin, HIGH);
delayMicroseconds(700);
digitalWrite(stepPin, LOW);
delayMicroseconds(700);
switchval1 = 1;
}
digitalWrite(pinRelais , LOW);
}
// Return the response
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println(""); // do not forget this one
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println("<h1 align=center>Stepper motor controlled over WiFi</h1><br><br>");
client.print("Stepper motor moving= ");
if (value == HIGH) {
client.print("Forward");
} else {
client.print("Backward");
}
client.println("<br><br>");
client.println("<a href=\"/Command=forward\"\"><button>Forward </button></a>");
client.println("<a href=\"/Command=backward\"\"><button>Backward </button></a><br />");
client.println("</html>");
delay(1);
Serial.println("Client disonnected");
Serial.println("");
}