ESP8266 EP-01 controlling a stepper motor

Hello everyone, I'm working on a project where I'm trying to control a stepper motor with an Easy Driver and an ESP8266 EP-01. I have a feeling I have everything wired correctly and the problem is a caveat. I have the following programming on the ESP

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>

#ifndef STASSID
#define STASSID "MySpectrumWiFiEB-2G"
#define STAPSK  "pw"
#endif

const char* ssid = STASSID;
const char* password = STAPSK;

ESP8266WebServer server(80);

const int led = 13;
int dirPin  = 2;
int stepPin = 5;
int enPin   = 3;
String str;
String str1;
String forwardX;
int iforwardX;
String backwardX;
int ibackwardX;

String getValue(String data, char separator, int index)
{
    int found = 0;
    int strIndex[] = { 0, -1 };
    int maxIndex = data.length() - 1;

    for (int i = 0; i <= maxIndex && found <= index; i++) {
        if (data.charAt(i) == separator || i == maxIndex) {
            found++;
            strIndex[0] = strIndex[1] + 1;
            strIndex[1] = (i == maxIndex) ? i+1 : i;
        }
    }
    return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}

void handleRoot() {
  digitalWrite(led, 1);
  server.send(200, "text/plain", "hello from esp8266!\r\n");
  digitalWrite(led, 0);
}

void setup(void) {
  pinMode(led, OUTPUT);
  digitalWrite(led, 0);
  //Serial.begin(9600);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  pinMode(enPin, OUTPUT);
  digitalWrite(enPin, LOW);
  digitalWrite(stepPin, LOW);
  digitalWrite(dirPin, HIGH);
  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }

  if (MDNS.begin("esp8266")) {
    //Serial.println("MDNS responder started");
  }

  server.on("/", handleRoot);

  server.on("/godoor", []() {
    str1 = server.arg("todo");
      str= str1.substring(0,str1.length());
      if(str.indexOf("move")>=0) {
        forwardX =getValue(str,',',1);
        iforwardX = forwardX.toInt();
        backwardX =getValue(str,',',2);
        ibackwardX = backwardX.toInt();
  digitalWrite(enPin, LOW);
  for (int i = 0; i < iforwardX; i++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(100);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(1000);
  }
  digitalWrite(dirPin,LOW);
  for (int i = 0; i < ibackwardX; i++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(100);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(1000);
  }
  digitalWrite(dirPin,HIGH);
  digitalWrite(enPin, HIGH);
  //Serial.println("loop");   // read it and send it out Serial (USB)
}
    server.send(200, "text/plain", "Motor should have moved "+forwardX);
  });
 
  server.addHook([](const String & method, const String & url, WiFiClient * client, ESP8266WebServer::ContentTypeFunction contentType) {
    (void)method;      // GET, PUT, ...
    (void)url;         // example: /root/myfile.html
    (void)client;      // the webserver tcp client connection
    (void)contentType; // contentType(".html") => "text/html"
    /*Serial.printf("A useless web hook has passed\n");
    Serial.printf("(this hook is in 0x%08x area (401x=IRAM 402x=FLASH))\n", esp_get_program_counter());*/
    return ESP8266WebServer::CLIENT_REQUEST_CAN_CONTINUE;
  });
  server.begin();
  //Serial.println("HTTP server started");
}

void loop(void) {
  server.handleClient();
  MDNS.update();
}

When I navigate to 192.168.2.5/godoor?todo=move,900,8 the motor jumps and barely moves. It makes me think that it's not honoring the delayMicroseconds function. When I wire it to a Leonardo, it works perfectly. Does anybody have any ideas why this won't work?

Thanks in advanced for any insight!

Check this out:
https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966/2

Please edit your post with formatted code in tags.

Just for fun can we see how it's wired?

Have you configured the Easy Driver for 3.3v logic.

The EasyDriver is a simple to use stepper motor driver, compatible with anything that can output a digital 0 to 5V pulse (or 0 to 3.3V pulse if you solder SJ2 closed on the EasyDriver).

That is something I was wondering. So I have a jumper going from a Leonardo's 3.3v (powered via USB) to a breadboard's positive rail. Then from that positive rail I have two jumpers going to the ESP's VCC and EN pins.
I then run a jumper from the Leonardo's ground to the negative rail of the breadboard. From that rail, I have two jumpers going to the ESP's gnd and the other going to the Easy Driver's gnd pin beside the STEP pin. I am planning on powering the ESP via the power output pin on the Easy Driver, I just need to get my brother to plop some solder so that it outputs 2.3v. I have a physical disability and can't do that myself.
Then from the Easy Driver's DIR, STEP and ENABLE pins go to the pins in the ESP as indicated in the code.
And last but not least, I have a power supply from the wall to the power in on the Easy Driver.
Since I'm not powering the ESP from the Easy Driver, yet, do I need to close the S2J to get my current setup working?

You will have to read the Easy Driver documentation but it sounds like you are giving STEP, DIR, and ENABLE pins 3.3v as a HIGH level. If the Easy Driver is configured to see 5v as a HIGH level, then 3.3v likely won't trigger a step.

Okay I'll get my brother over here to do that. I was thinking that only applied to the power output. Thanks for the advice! I'll let you know what happens.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.